tailwind-variants 3.2.2 → 3.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tailwind-variants",
3
- "version": "3.2.2",
3
+ "version": "3.3.0",
4
4
  "description": "🦄 Tailwindcss first-class variant API",
5
5
  "keywords": [
6
6
  "tailwindcss",
@@ -25,19 +25,34 @@
25
25
  "types": "./dist/index.d.ts",
26
26
  "exports": {
27
27
  ".": {
28
- "types": "./dist/index.d.ts",
29
- "import": "./dist/index.js",
30
- "require": "./dist/index.cjs"
28
+ "import": {
29
+ "types": "./dist/index.d.ts",
30
+ "default": "./dist/index.js"
31
+ },
32
+ "require": {
33
+ "types": "./dist/index.d.cts",
34
+ "default": "./dist/index.cjs"
35
+ }
31
36
  },
32
37
  "./lite": {
33
- "types": "./dist/lite.d.ts",
34
- "import": "./dist/lite.js",
35
- "require": "./dist/lite.cjs"
38
+ "import": {
39
+ "types": "./dist/lite.d.ts",
40
+ "default": "./dist/lite.js"
41
+ },
42
+ "require": {
43
+ "types": "./dist/lite.d.cts",
44
+ "default": "./dist/lite.cjs"
45
+ }
36
46
  },
37
47
  "./utils": {
38
- "types": "./dist/utils.d.ts",
39
- "import": "./dist/utils.js",
40
- "require": "./dist/utils.cjs"
48
+ "import": {
49
+ "types": "./dist/utils.d.ts",
50
+ "default": "./dist/utils.js"
51
+ },
52
+ "require": {
53
+ "types": "./dist/utils.d.cts",
54
+ "default": "./dist/utils.cjs"
55
+ }
41
56
  },
42
57
  "./dist/*": "./dist/*",
43
58
  "./package.json": "./package.json"
@@ -51,60 +66,22 @@
51
66
  "publishConfig": {
52
67
  "access": "public"
53
68
  },
54
- "scripts": {
55
- "dev": "tsup --watch",
56
- "build": "tsup && node copy-types.cjs",
57
- "typecheck": "tsc --noEmit",
58
- "prepack": "clean-package",
59
- "benchmark": "node benchmark.js",
60
- "postpack": "clean-package restore",
61
- "lint": "eslint . src/**/*.{js,ts}",
62
- "lint:fix": "eslint --fix . src/**/*.{js,ts}",
63
- "test": "jest --verbose",
64
- "test:watch": "jest --watch --no-verbose",
65
- "changelog": "conventional-changelog -p angular -i CHANGELOG.md -s --commit-path .",
66
- "release": "bumpp --execute='pnpm run changelog' --all",
67
- "prepublishOnly": "pnpm run build",
68
- "release:check": "pnpm run lint && pnpm run typecheck && pnpm run test && pnpm run build"
69
- },
70
69
  "devDependencies": {
71
- "@commitlint/cli": "19.5.0",
72
- "@commitlint/config-conventional": "19.5.0",
73
- "@jest/globals": "29.7.0",
74
- "@swc-node/jest": "1.8.12",
75
- "@swc/cli": "0.5.0",
76
- "@swc/core": "1.9.2",
77
- "@swc/helpers": "0.5.15",
78
- "@swc/jest": "0.2.37",
79
- "@types/jest": "29.5.14",
80
- "@types/node": "22.9.0",
81
- "@typescript-eslint/eslint-plugin": "8.14.0",
82
- "@typescript-eslint/parser": "8.14.0",
83
- "benchmark": "2.1.4",
84
- "bumpp": "10.2.0",
85
- "changelogithub": "13.16.0",
86
- "class-variance-authority": "0.7.0",
87
- "clean-package": "2.2.0",
88
- "conventional-changelog-cli": "5.0.0",
89
- "eslint": "8.57.0",
90
- "eslint-config-prettier": "9.1.0",
91
- "eslint-config-ts-lambdas": "1.2.3",
92
- "eslint-import-resolver-typescript": "3.6.3",
93
- "eslint-plugin-import": "2.31.0",
94
- "eslint-plugin-jest": "28.9.0",
95
- "eslint-plugin-node": "11.1.0",
96
- "eslint-plugin-prettier": "5.2.1",
97
- "eslint-plugin-promise": "7.1.0",
98
- "expect": "29.7.0",
99
- "jest": "29.7.0",
100
- "postcss": "8.5.6",
101
- "prettier": "3.3.3",
102
- "prettier-eslint": "16.3.0",
103
- "prettier-eslint-cli": "8.0.1",
104
- "tailwindcss": "4.1.11",
105
- "ts-node": "10.9.2",
106
- "tsup": "8.5.0",
107
- "typescript": "5.6.3"
70
+ "@biomejs/biome": "2.5.5",
71
+ "@commitlint/cli": "21.2.1",
72
+ "@commitlint/config-conventional": "21.2.0",
73
+ "@commitlint/types": "21.2.0",
74
+ "@types/node": "26.1.1",
75
+ "bumpp": "11.1.0",
76
+ "changelogithub": "14.0.0",
77
+ "conventional-changelog": "8.1.0",
78
+ "conventional-changelog-angular": "9.2.1",
79
+ "esbuild": "0.28.1",
80
+ "tailwind-merge": "3.6.0",
81
+ "tinybench": "6.1.2",
82
+ "tsup": "8.5.1",
83
+ "typescript": "5.6.3",
84
+ "vitest": "4.1.10"
108
85
  },
109
86
  "peerDependencies": {
110
87
  "tailwind-merge": ">=3.0.0",
@@ -113,10 +90,29 @@
113
90
  "peerDependenciesMeta": {
114
91
  "tailwind-merge": {
115
92
  "optional": true
93
+ },
94
+ "tailwindcss": {
95
+ "optional": true
116
96
  }
117
97
  },
118
98
  "engines": {
119
- "node": ">=16.x",
120
- "pnpm": ">=7.x"
99
+ "pnpm": ">=7.x",
100
+ "node": ">=16.9.x"
101
+ },
102
+ "scripts": {
103
+ "dev": "tsup --config .config/tsup.config.ts --watch",
104
+ "build": "tsup --config .config/tsup.config.ts",
105
+ "typecheck": "tsc --noEmit && pnpm typecheck:types",
106
+ "typecheck:types": "tsc -p .config/tsconfig.type-tests.json",
107
+ "benchmark": "pnpm build && node benchmark/run.mjs",
108
+ "lint": "biome check .",
109
+ "lint:fix": "biome check --write .",
110
+ "test": "vitest run --config .config/vitest.config.ts",
111
+ "test:watch": "vitest --config .config/vitest.config.ts",
112
+ "changelog": "conventional-changelog -p angular -i CHANGELOG.md -s --commit-path .",
113
+ "release": "bumpp --execute='pnpm run changelog' --all",
114
+ "release:check": "pnpm run lint && pnpm run typecheck && pnpm run test && pnpm run build",
115
+ "clean": "pnpm clean:cache && pnpm i",
116
+ "clean:cache": "find . \\( -name 'dist' -o -name 'node_modules' -o -name 'pnpm-lock.yaml' \\) -prune -exec rm -rf '{}' +"
121
117
  }
122
- }
118
+ }
@@ -1,124 +0,0 @@
1
- 'use strict';
2
-
3
- // src/utils.js
4
- var SPACE_REGEX = /\s+/g;
5
- var removeExtraSpaces = (str) => {
6
- if (typeof str !== "string" || !str) return str;
7
- return str.replace(SPACE_REGEX, " ").trim();
8
- };
9
- var cx = (...classnames) => {
10
- const classList = [];
11
- const buildClassString = (input) => {
12
- if (!input && input !== 0 && input !== 0n) return;
13
- if (Array.isArray(input)) {
14
- for (let i = 0, len = input.length; i < len; i++) buildClassString(input[i]);
15
- return;
16
- }
17
- const type = typeof input;
18
- if (type === "string" || type === "number" || type === "bigint") {
19
- if (type === "number" && input !== input) return;
20
- classList.push(String(input));
21
- } else if (type === "object") {
22
- const keys = Object.keys(input);
23
- for (let i = 0, len = keys.length; i < len; i++) {
24
- const key = keys[i];
25
- if (input[key]) classList.push(key);
26
- }
27
- }
28
- };
29
- for (let i = 0, len = classnames.length; i < len; i++) {
30
- const c = classnames[i];
31
- if (c !== null && c !== void 0) buildClassString(c);
32
- }
33
- return classList.length > 0 ? removeExtraSpaces(classList.join(" ")) : void 0;
34
- };
35
- var falsyToString = (value) => value === false ? "false" : value === true ? "true" : value === 0 ? "0" : value;
36
- var isEmptyObject = (obj) => {
37
- if (!obj || typeof obj !== "object") return true;
38
- for (const _ in obj) return false;
39
- return true;
40
- };
41
- var isEqual = (obj1, obj2) => {
42
- if (obj1 === obj2) return true;
43
- if (!obj1 || !obj2) return false;
44
- const keys1 = Object.keys(obj1);
45
- const keys2 = Object.keys(obj2);
46
- if (keys1.length !== keys2.length) return false;
47
- for (let i = 0; i < keys1.length; i++) {
48
- const key = keys1[i];
49
- if (!keys2.includes(key)) return false;
50
- if (obj1[key] !== obj2[key]) return false;
51
- }
52
- return true;
53
- };
54
- var isBoolean = (value) => value === true || value === false;
55
- var joinObjects = (obj1, obj2) => {
56
- for (const key in obj2) {
57
- if (Object.prototype.hasOwnProperty.call(obj2, key)) {
58
- const val2 = obj2[key];
59
- if (key in obj1) {
60
- obj1[key] = cx(obj1[key], val2);
61
- } else {
62
- obj1[key] = val2;
63
- }
64
- }
65
- }
66
- return obj1;
67
- };
68
- var flat = (arr, target) => {
69
- for (let i = 0; i < arr.length; i++) {
70
- const el = arr[i];
71
- if (Array.isArray(el)) flat(el, target);
72
- else if (el) target.push(el);
73
- }
74
- };
75
- function flatArray(arr) {
76
- const flattened = [];
77
- flat(arr, flattened);
78
- return flattened;
79
- }
80
- var flatMergeArrays = (...arrays) => {
81
- const result = [];
82
- flat(arrays, result);
83
- const filtered = [];
84
- for (let i = 0; i < result.length; i++) {
85
- if (result[i]) filtered.push(result[i]);
86
- }
87
- return filtered;
88
- };
89
- var mergeObjects = (obj1, obj2) => {
90
- const result = {};
91
- for (const key in obj1) {
92
- const val1 = obj1[key];
93
- if (key in obj2) {
94
- const val2 = obj2[key];
95
- if (Array.isArray(val1) || Array.isArray(val2)) {
96
- result[key] = flatMergeArrays(val2, val1);
97
- } else if (typeof val1 === "object" && typeof val2 === "object" && val1 && val2) {
98
- result[key] = mergeObjects(val1, val2);
99
- } else {
100
- result[key] = val2 + " " + val1;
101
- }
102
- } else {
103
- result[key] = val1;
104
- }
105
- }
106
- for (const key in obj2) {
107
- if (!(key in obj1)) {
108
- result[key] = obj2[key];
109
- }
110
- }
111
- return result;
112
- };
113
-
114
- exports.cx = cx;
115
- exports.falsyToString = falsyToString;
116
- exports.flat = flat;
117
- exports.flatArray = flatArray;
118
- exports.flatMergeArrays = flatMergeArrays;
119
- exports.isBoolean = isBoolean;
120
- exports.isEmptyObject = isEmptyObject;
121
- exports.isEqual = isEqual;
122
- exports.joinObjects = joinObjects;
123
- exports.mergeObjects = mergeObjects;
124
- exports.removeExtraSpaces = removeExtraSpaces;
@@ -1,273 +0,0 @@
1
- 'use strict';
2
-
3
- var chunk2JY7EID6_cjs = require('./chunk-2JY7EID6.cjs');
4
-
5
- // src/config.js
6
- var defaultConfig = {
7
- twMerge: true,
8
- twMergeConfig: {}
9
- };
10
-
11
- // src/state.js
12
- function createState() {
13
- let cachedTwMerge = null;
14
- let cachedTwMergeConfig = {};
15
- let didTwMergeConfigChange = false;
16
- return {
17
- get cachedTwMerge() {
18
- return cachedTwMerge;
19
- },
20
- set cachedTwMerge(value) {
21
- cachedTwMerge = value;
22
- },
23
- get cachedTwMergeConfig() {
24
- return cachedTwMergeConfig;
25
- },
26
- set cachedTwMergeConfig(value) {
27
- cachedTwMergeConfig = value;
28
- },
29
- get didTwMergeConfigChange() {
30
- return didTwMergeConfigChange;
31
- },
32
- set didTwMergeConfigChange(value) {
33
- didTwMergeConfigChange = value;
34
- },
35
- reset() {
36
- cachedTwMerge = null;
37
- cachedTwMergeConfig = {};
38
- didTwMergeConfigChange = false;
39
- }
40
- };
41
- }
42
- var state = createState();
43
-
44
- // src/core.js
45
- var getTailwindVariants = (cn) => {
46
- const tv = (options, configProp) => {
47
- const {
48
- extend = null,
49
- slots: slotProps = {},
50
- variants: variantsProps = {},
51
- compoundVariants: compoundVariantsProps = [],
52
- compoundSlots = [],
53
- defaultVariants: defaultVariantsProps = {}
54
- } = options;
55
- const config = { ...defaultConfig, ...configProp };
56
- const base = extend?.base ? chunk2JY7EID6_cjs.cx(extend.base, options?.base) : options?.base;
57
- const variants = extend?.variants && !chunk2JY7EID6_cjs.isEmptyObject(extend.variants) ? chunk2JY7EID6_cjs.mergeObjects(variantsProps, extend.variants) : variantsProps;
58
- const defaultVariants = extend?.defaultVariants && !chunk2JY7EID6_cjs.isEmptyObject(extend.defaultVariants) ? { ...extend.defaultVariants, ...defaultVariantsProps } : defaultVariantsProps;
59
- if (!chunk2JY7EID6_cjs.isEmptyObject(config.twMergeConfig) && !chunk2JY7EID6_cjs.isEqual(config.twMergeConfig, state.cachedTwMergeConfig)) {
60
- state.didTwMergeConfigChange = true;
61
- state.cachedTwMergeConfig = config.twMergeConfig;
62
- }
63
- const isExtendedSlotsEmpty = chunk2JY7EID6_cjs.isEmptyObject(extend?.slots);
64
- const componentSlots = !chunk2JY7EID6_cjs.isEmptyObject(slotProps) ? {
65
- // add "base" to the slots object
66
- base: chunk2JY7EID6_cjs.cx(options?.base, isExtendedSlotsEmpty && extend?.base),
67
- ...slotProps
68
- } : {};
69
- const slots = isExtendedSlotsEmpty ? componentSlots : chunk2JY7EID6_cjs.joinObjects(
70
- { ...extend?.slots },
71
- chunk2JY7EID6_cjs.isEmptyObject(componentSlots) ? { base: options?.base } : componentSlots
72
- );
73
- const compoundVariants = chunk2JY7EID6_cjs.isEmptyObject(extend?.compoundVariants) ? compoundVariantsProps : chunk2JY7EID6_cjs.flatMergeArrays(extend?.compoundVariants, compoundVariantsProps);
74
- const component = (props) => {
75
- if (chunk2JY7EID6_cjs.isEmptyObject(variants) && chunk2JY7EID6_cjs.isEmptyObject(slotProps) && isExtendedSlotsEmpty) {
76
- return cn(base, props?.class, props?.className)(config);
77
- }
78
- if (compoundVariants && !Array.isArray(compoundVariants)) {
79
- throw new TypeError(
80
- `The "compoundVariants" prop must be an array. Received: ${typeof compoundVariants}`
81
- );
82
- }
83
- if (compoundSlots && !Array.isArray(compoundSlots)) {
84
- throw new TypeError(
85
- `The "compoundSlots" prop must be an array. Received: ${typeof compoundSlots}`
86
- );
87
- }
88
- const getVariantValue = (variant, vrs = variants, _slotKey = null, slotProps2 = null) => {
89
- const variantObj = vrs[variant];
90
- if (!variantObj || chunk2JY7EID6_cjs.isEmptyObject(variantObj)) {
91
- return null;
92
- }
93
- const variantProp = slotProps2?.[variant] ?? props?.[variant];
94
- if (variantProp === null) return null;
95
- const variantKey = chunk2JY7EID6_cjs.falsyToString(variantProp);
96
- if (typeof variantKey === "object") {
97
- return null;
98
- }
99
- const defaultVariantProp = defaultVariants?.[variant];
100
- const key = variantKey != null ? variantKey : chunk2JY7EID6_cjs.falsyToString(defaultVariantProp);
101
- const value = variantObj[key || "false"];
102
- return value;
103
- };
104
- const getVariantClassNames = () => {
105
- if (!variants) return null;
106
- const keys = Object.keys(variants);
107
- const result = [];
108
- for (let i = 0; i < keys.length; i++) {
109
- const value = getVariantValue(keys[i], variants);
110
- if (value) result.push(value);
111
- }
112
- return result;
113
- };
114
- const getVariantClassNamesBySlotKey = (slotKey, slotProps2) => {
115
- if (!variants || typeof variants !== "object") return null;
116
- const result = [];
117
- for (const variant in variants) {
118
- const variantValue = getVariantValue(variant, variants, slotKey, slotProps2);
119
- const value = slotKey === "base" && typeof variantValue === "string" ? variantValue : variantValue && variantValue[slotKey];
120
- if (value) result.push(value);
121
- }
122
- return result;
123
- };
124
- const propsWithoutUndefined = {};
125
- for (const prop in props) {
126
- const value = props[prop];
127
- if (value !== void 0) propsWithoutUndefined[prop] = value;
128
- }
129
- const getCompleteProps = (key, slotProps2) => {
130
- const initialProp = typeof props?.[key] === "object" ? {
131
- [key]: props[key]?.initial
132
- } : {};
133
- return {
134
- ...defaultVariants,
135
- ...propsWithoutUndefined,
136
- ...initialProp,
137
- ...slotProps2
138
- };
139
- };
140
- const getCompoundVariantsValue = (cv = [], slotProps2) => {
141
- const result = [];
142
- const cvLength = cv.length;
143
- for (let i = 0; i < cvLength; i++) {
144
- const { class: tvClass, className: tvClassName, ...compoundVariantOptions } = cv[i];
145
- let isValid = true;
146
- const completeProps = getCompleteProps(null, slotProps2);
147
- for (const key in compoundVariantOptions) {
148
- const value = compoundVariantOptions[key];
149
- const completePropsValue = completeProps[key];
150
- if (Array.isArray(value)) {
151
- if (!value.includes(completePropsValue)) {
152
- isValid = false;
153
- break;
154
- }
155
- } else {
156
- if ((value == null || value === false) && (completePropsValue == null || completePropsValue === false))
157
- continue;
158
- if (completePropsValue !== value) {
159
- isValid = false;
160
- break;
161
- }
162
- }
163
- }
164
- if (isValid) {
165
- if (tvClass) result.push(tvClass);
166
- if (tvClassName) result.push(tvClassName);
167
- }
168
- }
169
- return result;
170
- };
171
- const getCompoundVariantClassNamesBySlot = (slotProps2) => {
172
- const compoundClassNames = getCompoundVariantsValue(compoundVariants, slotProps2);
173
- if (!Array.isArray(compoundClassNames)) return compoundClassNames;
174
- const result = {};
175
- const cnFn = cn;
176
- for (let i = 0; i < compoundClassNames.length; i++) {
177
- const className = compoundClassNames[i];
178
- if (typeof className === "string") {
179
- result.base = cnFn(result.base, className)(config);
180
- } else if (typeof className === "object") {
181
- for (const slot in className) {
182
- result[slot] = cnFn(result[slot], className[slot])(config);
183
- }
184
- }
185
- }
186
- return result;
187
- };
188
- const getCompoundSlotClassNameBySlot = (slotProps2) => {
189
- if (compoundSlots.length < 1) return null;
190
- const result = {};
191
- const completeProps = getCompleteProps(null, slotProps2);
192
- for (let i = 0; i < compoundSlots.length; i++) {
193
- const {
194
- slots: slots2 = [],
195
- class: slotClass,
196
- className: slotClassName,
197
- ...slotVariants
198
- } = compoundSlots[i];
199
- if (!chunk2JY7EID6_cjs.isEmptyObject(slotVariants)) {
200
- let isValid = true;
201
- for (const key in slotVariants) {
202
- const completePropsValue = completeProps[key];
203
- const slotVariantValue = slotVariants[key];
204
- if (completePropsValue === void 0 || (Array.isArray(slotVariantValue) ? !slotVariantValue.includes(completePropsValue) : slotVariantValue !== completePropsValue)) {
205
- isValid = false;
206
- break;
207
- }
208
- }
209
- if (!isValid) continue;
210
- }
211
- for (let j = 0; j < slots2.length; j++) {
212
- const slotName = slots2[j];
213
- if (!result[slotName]) result[slotName] = [];
214
- result[slotName].push([slotClass, slotClassName]);
215
- }
216
- }
217
- return result;
218
- };
219
- if (!chunk2JY7EID6_cjs.isEmptyObject(slotProps) || !isExtendedSlotsEmpty) {
220
- const slotsFns = {};
221
- if (typeof slots === "object" && !chunk2JY7EID6_cjs.isEmptyObject(slots)) {
222
- const cnFn = cn;
223
- for (const slotKey in slots) {
224
- slotsFns[slotKey] = (slotProps2) => {
225
- const compoundVariantClasses = getCompoundVariantClassNamesBySlot(slotProps2);
226
- const compoundSlotClasses = getCompoundSlotClassNameBySlot(slotProps2);
227
- return cnFn(
228
- slots[slotKey],
229
- getVariantClassNamesBySlotKey(slotKey, slotProps2),
230
- compoundVariantClasses ? compoundVariantClasses[slotKey] : void 0,
231
- compoundSlotClasses ? compoundSlotClasses[slotKey] : void 0,
232
- slotProps2?.class,
233
- slotProps2?.className
234
- )(config);
235
- };
236
- }
237
- }
238
- return slotsFns;
239
- }
240
- return cn(
241
- base,
242
- getVariantClassNames(),
243
- getCompoundVariantsValue(compoundVariants),
244
- props?.class,
245
- props?.className
246
- )(config);
247
- };
248
- const getVariantKeys = () => {
249
- if (!variants || typeof variants !== "object") return;
250
- return Object.keys(variants);
251
- };
252
- component.variantKeys = getVariantKeys();
253
- component.extend = extend;
254
- component.base = base;
255
- component.slots = slots;
256
- component.variants = variants;
257
- component.defaultVariants = defaultVariants;
258
- component.compoundSlots = compoundSlots;
259
- component.compoundVariants = compoundVariants;
260
- return component;
261
- };
262
- const createTV = (configProp) => {
263
- return (options, config) => tv(options, config ? chunk2JY7EID6_cjs.mergeObjects(configProp, config) : configProp);
264
- };
265
- return {
266
- tv,
267
- createTV
268
- };
269
- };
270
-
271
- exports.defaultConfig = defaultConfig;
272
- exports.getTailwindVariants = getTailwindVariants;
273
- exports.state = state;
@@ -1,112 +0,0 @@
1
- // src/utils.js
2
- var SPACE_REGEX = /\s+/g;
3
- var removeExtraSpaces = (str) => {
4
- if (typeof str !== "string" || !str) return str;
5
- return str.replace(SPACE_REGEX, " ").trim();
6
- };
7
- var cx = (...classnames) => {
8
- const classList = [];
9
- const buildClassString = (input) => {
10
- if (!input && input !== 0 && input !== 0n) return;
11
- if (Array.isArray(input)) {
12
- for (let i = 0, len = input.length; i < len; i++) buildClassString(input[i]);
13
- return;
14
- }
15
- const type = typeof input;
16
- if (type === "string" || type === "number" || type === "bigint") {
17
- if (type === "number" && input !== input) return;
18
- classList.push(String(input));
19
- } else if (type === "object") {
20
- const keys = Object.keys(input);
21
- for (let i = 0, len = keys.length; i < len; i++) {
22
- const key = keys[i];
23
- if (input[key]) classList.push(key);
24
- }
25
- }
26
- };
27
- for (let i = 0, len = classnames.length; i < len; i++) {
28
- const c = classnames[i];
29
- if (c !== null && c !== void 0) buildClassString(c);
30
- }
31
- return classList.length > 0 ? removeExtraSpaces(classList.join(" ")) : void 0;
32
- };
33
- var falsyToString = (value) => value === false ? "false" : value === true ? "true" : value === 0 ? "0" : value;
34
- var isEmptyObject = (obj) => {
35
- if (!obj || typeof obj !== "object") return true;
36
- for (const _ in obj) return false;
37
- return true;
38
- };
39
- var isEqual = (obj1, obj2) => {
40
- if (obj1 === obj2) return true;
41
- if (!obj1 || !obj2) return false;
42
- const keys1 = Object.keys(obj1);
43
- const keys2 = Object.keys(obj2);
44
- if (keys1.length !== keys2.length) return false;
45
- for (let i = 0; i < keys1.length; i++) {
46
- const key = keys1[i];
47
- if (!keys2.includes(key)) return false;
48
- if (obj1[key] !== obj2[key]) return false;
49
- }
50
- return true;
51
- };
52
- var isBoolean = (value) => value === true || value === false;
53
- var joinObjects = (obj1, obj2) => {
54
- for (const key in obj2) {
55
- if (Object.prototype.hasOwnProperty.call(obj2, key)) {
56
- const val2 = obj2[key];
57
- if (key in obj1) {
58
- obj1[key] = cx(obj1[key], val2);
59
- } else {
60
- obj1[key] = val2;
61
- }
62
- }
63
- }
64
- return obj1;
65
- };
66
- var flat = (arr, target) => {
67
- for (let i = 0; i < arr.length; i++) {
68
- const el = arr[i];
69
- if (Array.isArray(el)) flat(el, target);
70
- else if (el) target.push(el);
71
- }
72
- };
73
- function flatArray(arr) {
74
- const flattened = [];
75
- flat(arr, flattened);
76
- return flattened;
77
- }
78
- var flatMergeArrays = (...arrays) => {
79
- const result = [];
80
- flat(arrays, result);
81
- const filtered = [];
82
- for (let i = 0; i < result.length; i++) {
83
- if (result[i]) filtered.push(result[i]);
84
- }
85
- return filtered;
86
- };
87
- var mergeObjects = (obj1, obj2) => {
88
- const result = {};
89
- for (const key in obj1) {
90
- const val1 = obj1[key];
91
- if (key in obj2) {
92
- const val2 = obj2[key];
93
- if (Array.isArray(val1) || Array.isArray(val2)) {
94
- result[key] = flatMergeArrays(val2, val1);
95
- } else if (typeof val1 === "object" && typeof val2 === "object" && val1 && val2) {
96
- result[key] = mergeObjects(val1, val2);
97
- } else {
98
- result[key] = val2 + " " + val1;
99
- }
100
- } else {
101
- result[key] = val1;
102
- }
103
- }
104
- for (const key in obj2) {
105
- if (!(key in obj1)) {
106
- result[key] = obj2[key];
107
- }
108
- }
109
- return result;
110
- };
111
-
112
- export { cx, falsyToString, flat, flatArray, flatMergeArrays, isBoolean, isEmptyObject, isEqual, joinObjects, mergeObjects, removeExtraSpaces };