main
Last change
on this file since d565449 was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago |
Update repo after prototype presentation
|
-
Property mode
set to
100644
|
File size:
1.1 KB
|
Line | |
---|
1 | import {IMPORT, LAYER, COMMENT, RULESET, DECLARATION, KEYFRAMES} from './Enum.js'
|
---|
2 | import {strlen} from './Utility.js'
|
---|
3 |
|
---|
4 | /**
|
---|
5 | * @param {object[]} children
|
---|
6 | * @param {function} callback
|
---|
7 | * @return {string}
|
---|
8 | */
|
---|
9 | export function serialize (children, callback) {
|
---|
10 | var output = ''
|
---|
11 |
|
---|
12 | for (var i = 0; i < children.length; i++)
|
---|
13 | output += callback(children[i], i, children, callback) || ''
|
---|
14 |
|
---|
15 | return output
|
---|
16 | }
|
---|
17 |
|
---|
18 | /**
|
---|
19 | * @param {object} element
|
---|
20 | * @param {number} index
|
---|
21 | * @param {object[]} children
|
---|
22 | * @param {function} callback
|
---|
23 | * @return {string}
|
---|
24 | */
|
---|
25 | export function stringify (element, index, children, callback) {
|
---|
26 | switch (element.type) {
|
---|
27 | case LAYER: if (element.children.length) break
|
---|
28 | case IMPORT: case DECLARATION: return element.return = element.return || element.value
|
---|
29 | case COMMENT: return ''
|
---|
30 | case KEYFRAMES: return element.return = element.value + '{' + serialize(element.children, callback) + '}'
|
---|
31 | case RULESET: if (!strlen(element.value = element.props.join(','))) return ''
|
---|
32 | }
|
---|
33 |
|
---|
34 | return strlen(children = serialize(element.children, callback)) ? element.return = element.value + '{' + children + '}' : ''
|
---|
35 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.