1
- import { isUnitlessProperty } from 'css-in-js-utils' ;
2
- import { isPlainObject } from 'uinix-fp' ;
3
-
4
- import { createCssVariable } from './utils/create-css-variable.js' ;
5
-
6
1
/**
7
2
* @typedef {import('./types.js').Theme } Theme
8
3
*/
9
4
10
- /**
11
- * Returns a flattened object with property path as keys
12
- * @param {Object.<string, any> } object
13
- * @param {string } path
14
- * @returns {Object }
15
- */
16
- const flatten = ( object , path = '' ) => {
17
- /** @type {Record<string, any> } */
18
- const result = { } ;
19
- return Object . keys ( object ) . reduce ( ( acc , k ) => {
20
- const prepath = path . length > 0 ? path + '.' : '' ;
21
- if ( isPlainObject ( object [ k ] ) ) {
22
- Object . assign ( acc , flatten ( object [ k ] , prepath + k ) ) ;
23
- } else {
24
- acc [ prepath + k ] = object [ k ] ;
25
- }
5
+ import { isUnitlessProperty } from 'css-in-js-utils' ;
6
+ import { isPlainObject } from 'uinix-fp' ;
26
7
27
- return acc ;
28
- } , result ) ;
29
- } ;
8
+ import { createCssVariable } from './utils/create-css-variable.js' ;
30
9
31
10
/**
32
11
* Transforms the provided nested theme into a flat object of CSS variables
@@ -52,4 +31,25 @@ export const createCssVariables = (theme = {}, options = defaultOptions) => {
52
31
) ;
53
32
} ;
54
33
34
+ /**
35
+ * Returns a flattened object with property path as keys
36
+ * @param {Object.<string, any> } object
37
+ * @param {string } path
38
+ * @returns {Object }
39
+ */
40
+ const flatten = ( object , path = '' ) => {
41
+ /** @type {Record<string, any> } */
42
+ const result = { } ;
43
+ return Object . keys ( object ) . reduce ( ( acc , k ) => {
44
+ const prepath = path . length > 0 ? path + '.' : '' ;
45
+ if ( isPlainObject ( object [ k ] ) ) {
46
+ Object . assign ( acc , flatten ( object [ k ] , prepath + k ) ) ;
47
+ } else {
48
+ acc [ prepath + k ] = object [ k ] ;
49
+ }
50
+
51
+ return acc ;
52
+ } , result ) ;
53
+ } ;
54
+
55
55
const defaultOptions = { namespace : '' } ;
0 commit comments