@linaria/utils
Advanced tools
Comparing version 3.0.0-beta.15 to 3.0.0-beta.18
@@ -6,2 +6,13 @@ # Change Log | ||
# [3.0.0-beta.18](https://github.com/callstack/linaria/compare/v3.0.0-beta.17...v3.0.0-beta.18) (2022-04-01) | ||
### Features | ||
* **atomic:** string serialization of atoms ([#934](https://github.com/callstack/linaria/issues/934)) ([ef19ccb](https://github.com/callstack/linaria/commit/ef19ccb384cb7dbee561e789f637b0289d4d224c)) | ||
# [3.0.0-beta.15](https://github.com/callstack/linaria/compare/v3.0.0-beta.14...v3.0.0-beta.15) (2021-11-29) | ||
@@ -8,0 +19,0 @@ |
@@ -7,6 +7,6 @@ /** | ||
* ``` | ||
* If arguments provided are objects, these objects are merged together, and the values are taken as class names: | ||
* If space separated atomic styles are provided, they are deduplicated according to the first hashed valued: | ||
* | ||
* ```js | ||
* cx({ color: 'class1', textDecoration: 'class2'}, { color: 'class3' }) // returns `class3 class2` | ||
* cx('atm_a_class1 atm_b_class2', 'atm_a_class3') // returns `atm_a_class3 atm_b_class2` | ||
* ``` | ||
@@ -17,11 +17,21 @@ * | ||
const cx = function cx() { | ||
const presentClassNames = Array.prototype.slice.call(arguments).filter(Boolean); // In the basic case, `cx` is passed all strings, and we simply need to join them together with space separators | ||
const presentClassNames = Array.prototype.slice.call(arguments).filter(Boolean); | ||
const atomicClasses = {}; | ||
const nonAtomicClasses = []; | ||
const classNamesResult = presentClassNames.filter(arg => typeof arg !== 'object'); // There might also be objects (eg. from the atomic API) such as cx('foo', { | ||
// key1: 'bar', key2: 'fizz'}, { key1: 'buzz' }) the desired behavior is to | ||
// deduplicate the values based on their properties. The object's values are | ||
// the class names | ||
for (const className of presentClassNames) { | ||
// className could be the output of a previous cx call, so split by ' ' first | ||
const individualClassNames = className.split(' '); | ||
const styleCollectionResult = Object.values(Object.assign({}, ...presentClassNames.filter(arg => typeof arg === 'object'))); | ||
return [...styleCollectionResult, ...classNamesResult].join(' '); | ||
for (const className of individualClassNames) { | ||
if (className.startsWith('atm_')) { | ||
const [, keyHash] = className.split('_'); | ||
atomicClasses[keyHash] = className; | ||
} else { | ||
nonAtomicClasses.push(className); | ||
} | ||
} | ||
} | ||
return [...Object.values(atomicClasses), ...nonAtomicClasses].join(' '); | ||
}; | ||
@@ -28,0 +38,0 @@ |
@@ -14,6 +14,6 @@ "use strict"; | ||
* ``` | ||
* If arguments provided are objects, these objects are merged together, and the values are taken as class names: | ||
* If space separated atomic styles are provided, they are deduplicated according to the first hashed valued: | ||
* | ||
* ```js | ||
* cx({ color: 'class1', textDecoration: 'class2'}, { color: 'class3' }) // returns `class3 class2` | ||
* cx('atm_a_class1 atm_b_class2', 'atm_a_class3') // returns `atm_a_class3 atm_b_class2` | ||
* ``` | ||
@@ -24,11 +24,21 @@ * | ||
const cx = function cx() { | ||
const presentClassNames = Array.prototype.slice.call(arguments).filter(Boolean); // In the basic case, `cx` is passed all strings, and we simply need to join them together with space separators | ||
const presentClassNames = Array.prototype.slice.call(arguments).filter(Boolean); | ||
const atomicClasses = {}; | ||
const nonAtomicClasses = []; | ||
const classNamesResult = presentClassNames.filter(arg => typeof arg !== 'object'); // There might also be objects (eg. from the atomic API) such as cx('foo', { | ||
// key1: 'bar', key2: 'fizz'}, { key1: 'buzz' }) the desired behavior is to | ||
// deduplicate the values based on their properties. The object's values are | ||
// the class names | ||
for (const className of presentClassNames) { | ||
// className could be the output of a previous cx call, so split by ' ' first | ||
const individualClassNames = className.split(' '); | ||
const styleCollectionResult = Object.values(Object.assign({}, ...presentClassNames.filter(arg => typeof arg === 'object'))); | ||
return [...styleCollectionResult, ...classNamesResult].join(' '); | ||
for (const className of individualClassNames) { | ||
if (className.startsWith('atm_')) { | ||
const [, keyHash] = className.split('_'); | ||
atomicClasses[keyHash] = className; | ||
} else { | ||
nonAtomicClasses.push(className); | ||
} | ||
} | ||
} | ||
return [...Object.values(atomicClasses), ...nonAtomicClasses].join(' '); | ||
}; | ||
@@ -35,0 +45,0 @@ |
{ | ||
"name": "@linaria/utils", | ||
"version": "3.0.0-beta.15", | ||
"version": "3.0.0-beta.18", | ||
"publishConfig": { | ||
@@ -40,3 +40,3 @@ "access": "public" | ||
}, | ||
"gitHead": "a8ada3794c6e13231f70711d92b516d57677a5b1" | ||
"gitHead": "c3f093a3a7fb4e7c82d23e44adb19a94438da68c" | ||
} |
@@ -5,8 +5,4 @@ export declare type LinariaClassName = string & { | ||
export declare type ClassName<T = string> = T | false | void | null | 0 | ''; | ||
interface StyleCollectionObject { | ||
[key: string]: string; | ||
} | ||
interface ICX { | ||
(...classNames: ClassName<LinariaClassName>[]): LinariaClassName; | ||
(...classNames: (ClassName | ClassName<StyleCollectionObject>)[]): string; | ||
(...classNames: (ClassName | ClassName<LinariaClassName>)[]): string; | ||
} | ||
@@ -19,6 +15,6 @@ /** | ||
* ``` | ||
* If arguments provided are objects, these objects are merged together, and the values are taken as class names: | ||
* If space separated atomic styles are provided, they are deduplicated according to the first hashed valued: | ||
* | ||
* ```js | ||
* cx({ color: 'class1', textDecoration: 'class2'}, { color: 'class3' }) // returns `class3 class2` | ||
* cx('atm_a_class1 atm_b_class2', 'atm_a_class3') // returns `atm_a_class3 atm_b_class2` | ||
* ``` | ||
@@ -25,0 +21,0 @@ * |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
252
26517