@wyw-in-js/processor-utils 1.1.0 → 2.0.0-alpha.1
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/esm/BaseProcessor.js +48 -76
- package/esm/BaseProcessor.js.map +1 -1
- package/esm/TaggedTemplateProcessor.js +32 -41
- package/esm/TaggedTemplateProcessor.js.map +1 -1
- package/esm/ast.js +72 -0
- package/esm/ast.js.map +1 -0
- package/esm/diagnostics.js +4 -4
- package/esm/diagnostics.js.map +1 -1
- package/esm/index.js +9 -8
- package/esm/index.js.map +1 -1
- package/esm/static.js +2 -0
- package/esm/static.js.map +1 -0
- package/esm/types.js +1 -1
- package/esm/types.js.map +1 -1
- package/esm/utils/buildSlug.js +2 -2
- package/esm/utils/buildSlug.js.map +1 -1
- package/esm/utils/getClassNameAndSlug.js +38 -41
- package/esm/utils/getClassNameAndSlug.js.map +1 -1
- package/esm/utils/getVariableName.js +7 -10
- package/esm/utils/getVariableName.js.map +1 -1
- package/esm/utils/stripLines.js +9 -11
- package/esm/utils/stripLines.js.map +1 -1
- package/esm/utils/templateProcessor.js +98 -118
- package/esm/utils/templateProcessor.js.map +1 -1
- package/esm/utils/throwIfInvalid.js +11 -12
- package/esm/utils/throwIfInvalid.js.map +1 -1
- package/esm/utils/toCSS.js +34 -43
- package/esm/utils/toCSS.js.map +1 -1
- package/esm/utils/toValidCSSIdentifier.js +2 -2
- package/esm/utils/toValidCSSIdentifier.js.map +1 -1
- package/esm/utils/types.js +1 -1
- package/esm/utils/types.js.map +1 -1
- package/esm/utils/units.js +79 -61
- package/esm/utils/units.js.map +1 -1
- package/esm/utils/validateParams.js +29 -39
- package/esm/utils/validateParams.js.map +1 -1
- package/package.json +15 -15
- package/types/BaseProcessor.d.ts +9 -12
- package/types/BaseProcessor.js +13 -22
- package/types/TaggedTemplateProcessor.d.ts +1 -1
- package/types/TaggedTemplateProcessor.js +9 -16
- package/types/ast.d.ts +95 -0
- package/types/ast.js +80 -0
- package/types/diagnostics.js +3 -8
- package/types/index.d.ts +4 -1
- package/types/index.js +8 -33
- package/types/static.d.ts +63 -0
- package/types/static.js +1 -0
- package/types/types.d.ts +1 -1
- package/types/types.js +1 -2
- package/types/utils/buildSlug.js +1 -4
- package/types/utils/getClassNameAndSlug.js +15 -18
- package/types/utils/getVariableName.js +1 -4
- package/types/utils/stripLines.js +1 -4
- package/types/utils/templateProcessor.d.ts +1 -1
- package/types/utils/templateProcessor.js +16 -55
- package/types/utils/throwIfInvalid.js +1 -3
- package/types/utils/toCSS.js +8 -13
- package/types/utils/toValidCSSIdentifier.js +1 -4
- package/types/utils/types.d.ts +4 -2
- package/types/utils/types.js +1 -2
- package/types/utils/units.js +2 -5
- package/types/utils/validateParams.js +2 -6
- package/lib/BaseProcessor.js +0 -87
- package/lib/BaseProcessor.js.map +0 -1
- package/lib/TaggedTemplateProcessor.js +0 -51
- package/lib/TaggedTemplateProcessor.js.map +0 -1
- package/lib/diagnostics.js +0 -12
- package/lib/diagnostics.js.map +0 -1
- package/lib/index.js +0 -89
- package/lib/index.js.map +0 -1
- package/lib/types.js +0 -2
- package/lib/types.js.map +0 -1
- package/lib/utils/buildSlug.js +0 -12
- package/lib/utils/buildSlug.js.map +0 -1
- package/lib/utils/getClassNameAndSlug.js +0 -50
- package/lib/utils/getClassNameAndSlug.js.map +0 -1
- package/lib/utils/getVariableName.js +0 -18
- package/lib/utils/getVariableName.js.map +0 -1
- package/lib/utils/stripLines.js +0 -22
- package/lib/utils/stripLines.js.map +0 -1
- package/lib/utils/templateProcessor.js +0 -129
- package/lib/utils/templateProcessor.js.map +0 -1
- package/lib/utils/throwIfInvalid.js +0 -35
- package/lib/utils/throwIfInvalid.js.map +0 -1
- package/lib/utils/toCSS.js +0 -58
- package/lib/utils/toCSS.js.map +0 -1
- package/lib/utils/toValidCSSIdentifier.js +0 -10
- package/lib/utils/toValidCSSIdentifier.js.map +0 -1
- package/lib/utils/types.js +0 -2
- package/lib/utils/types.js.map +0 -1
- package/lib/utils/units.js +0 -71
- package/lib/utils/units.js.map +0 -1
- package/lib/utils/validateParams.js +0 -54
- package/lib/utils/validateParams.js.map +0 -1
package/lib/utils/toCSS.js
DELETED
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = toCSS;
|
|
7
|
-
exports.isCSSable = void 0;
|
|
8
|
-
var _shared = require("@wyw-in-js/shared");
|
|
9
|
-
var _units = require("./units");
|
|
10
|
-
const isCSSPropertyValue = o => {
|
|
11
|
-
return (0, _shared.isBoxedPrimitive)(o) || typeof o === 'string' || typeof o === 'number' && Number.isFinite(o);
|
|
12
|
-
};
|
|
13
|
-
const isCSSable = o => {
|
|
14
|
-
if (isCSSPropertyValue(o)) {
|
|
15
|
-
return true;
|
|
16
|
-
}
|
|
17
|
-
if (Array.isArray(o)) {
|
|
18
|
-
return o.every(isCSSable);
|
|
19
|
-
}
|
|
20
|
-
if (typeof o === 'object') {
|
|
21
|
-
return o !== null && Object.values(o).every(isCSSable);
|
|
22
|
-
}
|
|
23
|
-
return false;
|
|
24
|
-
};
|
|
25
|
-
exports.isCSSable = isCSSable;
|
|
26
|
-
const hyphenate = s => {
|
|
27
|
-
if (s.startsWith('--')) {
|
|
28
|
-
// It's a custom property which is already well formatted.
|
|
29
|
-
return s;
|
|
30
|
-
}
|
|
31
|
-
return s
|
|
32
|
-
// Hyphenate CSS property names from camelCase version from JS string
|
|
33
|
-
.replace(/([A-Z])/g, (match, p1) => `-${p1.toLowerCase()}`)
|
|
34
|
-
// Special case for `-ms` because in JS it starts with `ms` unlike `Webkit`
|
|
35
|
-
.replace(/^ms-/, '-ms-');
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
// Some tools such as polished.js output JS objects
|
|
39
|
-
// To support them transparently, we convert JS objects to CSS strings
|
|
40
|
-
function toCSS(o) {
|
|
41
|
-
if (Array.isArray(o)) {
|
|
42
|
-
return o.map(toCSS).join('\n');
|
|
43
|
-
}
|
|
44
|
-
if (isCSSPropertyValue(o)) {
|
|
45
|
-
return o.valueOf().toString();
|
|
46
|
-
}
|
|
47
|
-
return Object.entries(o).filter(([, value]) =>
|
|
48
|
-
// Ignore all falsy values except numbers
|
|
49
|
-
typeof value === 'number' || value).map(([key, value]) => {
|
|
50
|
-
if (!isCSSPropertyValue(value)) {
|
|
51
|
-
return `${key} { ${toCSS(value)} }`;
|
|
52
|
-
}
|
|
53
|
-
return `${hyphenate(key)}: ${typeof value === 'number' && value !== 0 &&
|
|
54
|
-
// Strip vendor prefixes when checking if the value is unitless
|
|
55
|
-
!(key.replace(/^(Webkit|Moz|O|ms)([A-Z])(.+)$/, (match, p1, p2, p3) => `${p2.toLowerCase()}${p3}`) in _units.unitless) ? `${value}px` : value};`;
|
|
56
|
-
}).join(' ');
|
|
57
|
-
}
|
|
58
|
-
//# sourceMappingURL=toCSS.js.map
|
package/lib/utils/toCSS.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"toCSS.js","names":["_shared","require","_units","isCSSPropertyValue","o","isBoxedPrimitive","Number","isFinite","isCSSable","Array","isArray","every","Object","values","exports","hyphenate","s","startsWith","replace","match","p1","toLowerCase","toCSS","map","join","valueOf","toString","entries","filter","value","key","p2","p3","unitless"],"sources":["../../src/utils/toCSS.ts"],"sourcesContent":["import { isBoxedPrimitive } from '@wyw-in-js/shared';\n\nimport type { CSSPropertyValue, CSSable } from '../types';\n\nimport { unitless } from './units';\n\nconst isCSSPropertyValue = (o: unknown): o is CSSPropertyValue => {\n return (\n isBoxedPrimitive(o) ||\n typeof o === 'string' ||\n (typeof o === 'number' && Number.isFinite(o))\n );\n};\n\nexport const isCSSable = (o: unknown): o is CSSable => {\n if (isCSSPropertyValue(o)) {\n return true;\n }\n\n if (Array.isArray(o)) {\n return o.every(isCSSable);\n }\n\n if (typeof o === 'object') {\n return o !== null && Object.values(o).every(isCSSable);\n }\n\n return false;\n};\n\nconst hyphenate = (s: string) => {\n if (s.startsWith('--')) {\n // It's a custom property which is already well formatted.\n return s;\n }\n return (\n s\n // Hyphenate CSS property names from camelCase version from JS string\n .replace(/([A-Z])/g, (match, p1) => `-${p1.toLowerCase()}`)\n // Special case for `-ms` because in JS it starts with `ms` unlike `Webkit`\n .replace(/^ms-/, '-ms-')\n );\n};\n\n// Some tools such as polished.js output JS objects\n// To support them transparently, we convert JS objects to CSS strings\nexport default function toCSS(o: CSSable): string {\n if (Array.isArray(o)) {\n return o.map(toCSS).join('\\n');\n }\n\n if (isCSSPropertyValue(o)) {\n return o.valueOf().toString();\n }\n\n return Object.entries(o)\n .filter(\n ([, value]) =>\n // Ignore all falsy values except numbers\n typeof value === 'number' || value\n )\n .map(([key, value]) => {\n if (!isCSSPropertyValue(value)) {\n return `${key} { ${toCSS(value)} }`;\n }\n\n return `${hyphenate(key)}: ${\n typeof value === 'number' &&\n value !== 0 &&\n // Strip vendor prefixes when checking if the value is unitless\n !(\n key.replace(\n /^(Webkit|Moz|O|ms)([A-Z])(.+)$/,\n (match, p1, p2, p3) => `${p2.toLowerCase()}${p3}`\n ) in unitless\n )\n ? `${value}px`\n : value\n };`;\n })\n .join(' ');\n}\n"],"mappings":";;;;;;;AAAA,IAAAA,OAAA,GAAAC,OAAA;AAIA,IAAAC,MAAA,GAAAD,OAAA;AAEA,MAAME,kBAAkB,GAAIC,CAAU,IAA4B;EAChE,OACE,IAAAC,wBAAgB,EAACD,CAAC,CAAC,IACnB,OAAOA,CAAC,KAAK,QAAQ,IACpB,OAAOA,CAAC,KAAK,QAAQ,IAAIE,MAAM,CAACC,QAAQ,CAACH,CAAC,CAAE;AAEjD,CAAC;AAEM,MAAMI,SAAS,GAAIJ,CAAU,IAAmB;EACrD,IAAID,kBAAkB,CAACC,CAAC,CAAC,EAAE;IACzB,OAAO,IAAI;EACb;EAEA,IAAIK,KAAK,CAACC,OAAO,CAACN,C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AAK,CAACO,KAAK,CAAC,IAAI;IACrC;IAEA,OAAO,GAAGd,SAAS,CAACe,GAAG,CAAC,KACtB,OAAOD,KAAK,KAAK,QAAQ,IACzBA,KAAK,KAAK,CAAC;IACX;IACA,EACEC,GAAG,CAACZ,OAAO,CACT,gCAAgC,EAChC,CAACC,KAAK,EAAEC,EAAE,EAAEW,EAAE,EAAEC,EAAE,KAAK,GAAGD,EAAE,CAACV,WAAW,CAAC,CAAC,GAAGW,EAAE,EACjD,CAAC,IAAIC,eAAQ,CACd,GACG,GAAGJ,KAAK,IAAI,GACZA,KAAK,GACR;EACL,CAAC,CAAC,CACDL,IAAI,CAAC,GAAG,CAAC;AACd","ignoreList":[]}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.toValidCSSIdentifier = toValidCSSIdentifier;
|
|
7
|
-
function toValidCSSIdentifier(s) {
|
|
8
|
-
return s.replace(/[^-_a-z0-9\u00A0-\uFFFF]/gi, '_').replace(/^\d/, '_');
|
|
9
|
-
}
|
|
10
|
-
//# sourceMappingURL=toValidCSSIdentifier.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"toValidCSSIdentifier.js","names":["toValidCSSIdentifier","s","replace"],"sources":["../../src/utils/toValidCSSIdentifier.ts"],"sourcesContent":["export function toValidCSSIdentifier(s: string) {\n return s.replace(/[^-_a-z0-9\\u00A0-\\uFFFF]/gi, '_').replace(/^\\d/, '_');\n}\n"],"mappings":";;;;;;AAAO,SAASA,oBAAoBA,CAACC,CAAS,EAAE;EAC9C,OAAOA,CAAC,CAACC,OAAO,CAAC,4BAA4B,EAAE,GAAG,CAAC,CAACA,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC;AACzE","ignoreList":[]}
|
package/lib/utils/types.js
DELETED
package/lib/utils/types.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","names":[],"sources":["../../src/utils/types.ts"],"sourcesContent":["import type { TransformOptions } from '@babel/core';\n\nimport type { ClassNameFn, VariableNameFn } from '@wyw-in-js/shared';\n\nexport interface IOptions {\n classNameSlug?: string | ClassNameFn;\n displayName: boolean;\n extensions?: string[];\n variableNameConfig?: 'var' | 'dashes' | 'raw';\n variableNameSlug?: string | VariableNameFn;\n}\n\nexport type IFileContext = Pick<TransformOptions, 'root' | 'filename'>;\n"],"mappings":"","ignoreList":[]}
|
package/lib/utils/units.js
DELETED
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.units = exports.unitless = void 0;
|
|
7
|
-
// https://www.w3.org/TR/css-values-4/
|
|
8
|
-
const units = exports.units = [
|
|
9
|
-
// font relative lengths
|
|
10
|
-
'em', 'ex', 'cap', 'ch', 'ic', 'rem', 'lh', 'rlh',
|
|
11
|
-
// viewport percentage lengths
|
|
12
|
-
'vw', 'vh', 'vi', 'vb', 'vmin', 'vmax',
|
|
13
|
-
// absolute lengths
|
|
14
|
-
'cm', 'mm', 'Q', 'in', 'pc', 'pt', 'px',
|
|
15
|
-
// angle units
|
|
16
|
-
'deg', 'grad', 'rad', 'turn',
|
|
17
|
-
// duration units
|
|
18
|
-
's', 'ms',
|
|
19
|
-
// frequency units
|
|
20
|
-
'Hz', 'kHz',
|
|
21
|
-
// resolution units
|
|
22
|
-
'dpi', 'dpcm', 'dppx', 'x',
|
|
23
|
-
// https://www.w3.org/TR/css-grid-1/#fr-unit
|
|
24
|
-
'fr',
|
|
25
|
-
// percentages
|
|
26
|
-
'%'];
|
|
27
|
-
const unitless = exports.unitless = {
|
|
28
|
-
animationIterationCount: true,
|
|
29
|
-
borderImageOutset: true,
|
|
30
|
-
borderImageSlice: true,
|
|
31
|
-
borderImageWidth: true,
|
|
32
|
-
boxFlex: true,
|
|
33
|
-
boxFlexGroup: true,
|
|
34
|
-
boxOrdinalGroup: true,
|
|
35
|
-
columnCount: true,
|
|
36
|
-
columns: true,
|
|
37
|
-
flex: true,
|
|
38
|
-
flexGrow: true,
|
|
39
|
-
flexPositive: true,
|
|
40
|
-
flexShrink: true,
|
|
41
|
-
flexNegative: true,
|
|
42
|
-
flexOrder: true,
|
|
43
|
-
gridRow: true,
|
|
44
|
-
gridRowEnd: true,
|
|
45
|
-
gridRowSpan: true,
|
|
46
|
-
gridRowStart: true,
|
|
47
|
-
gridColumn: true,
|
|
48
|
-
gridColumnEnd: true,
|
|
49
|
-
gridColumnSpan: true,
|
|
50
|
-
gridColumnStart: true,
|
|
51
|
-
fontWeight: true,
|
|
52
|
-
lineClamp: true,
|
|
53
|
-
lineHeight: true,
|
|
54
|
-
opacity: true,
|
|
55
|
-
order: true,
|
|
56
|
-
orphans: true,
|
|
57
|
-
tabSize: true,
|
|
58
|
-
widows: true,
|
|
59
|
-
zIndex: true,
|
|
60
|
-
zoom: true,
|
|
61
|
-
// SVG-related properties
|
|
62
|
-
fillOpacity: true,
|
|
63
|
-
floodOpacity: true,
|
|
64
|
-
stopOpacity: true,
|
|
65
|
-
strokeDasharray: true,
|
|
66
|
-
strokeDashoffset: true,
|
|
67
|
-
strokeMiterlimit: true,
|
|
68
|
-
strokeOpacity: true,
|
|
69
|
-
strokeWidth: true
|
|
70
|
-
};
|
|
71
|
-
//# sourceMappingURL=units.js.map
|
package/lib/utils/units.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"units.js","names":["units","exports","unitless","animationIterationCount","borderImageOutset","borderImageSlice","borderImageWidth","boxFlex","boxFlexGroup","boxOrdinalGroup","columnCount","columns","flex","flexGrow","flexPositive","flexShrink","flexNegative","flexOrder","gridRow","gridRowEnd","gridRowSpan","gridRowStart","gridColumn","gridColumnEnd","gridColumnSpan","gridColumnStart","fontWeight","lineClamp","lineHeight","opacity","order","orphans","tabSize","widows","zIndex","zoom","fillOpacity","floodOpacity","stopOpacity","strokeDasharray","strokeDashoffset","strokeMiterlimit","strokeOpacity","strokeWidth"],"sources":["../../src/utils/units.ts"],"sourcesContent":["// https://www.w3.org/TR/css-values-4/\nexport const units = [\n // font relative lengths\n 'em',\n 'ex',\n 'cap',\n 'ch',\n 'ic',\n 'rem',\n 'lh',\n 'rlh',\n\n // viewport percentage lengths\n 'vw',\n 'vh',\n 'vi',\n 'vb',\n 'vmin',\n 'vmax',\n\n // absolute lengths\n 'cm',\n 'mm',\n 'Q',\n 'in',\n 'pc',\n 'pt',\n 'px',\n\n // angle units\n 'deg',\n 'grad',\n 'rad',\n 'turn',\n\n // duration units\n 's',\n 'ms',\n\n // frequency units\n 'Hz',\n 'kHz',\n\n // resolution units\n 'dpi',\n 'dpcm',\n 'dppx',\n 'x',\n\n // https://www.w3.org/TR/css-grid-1/#fr-unit\n 'fr',\n\n // percentages\n '%',\n];\n\nexport const unitless = {\n animationIterationCount: true,\n borderImageOutset: true,\n borderImageSlice: true,\n borderImageWidth: true,\n boxFlex: true,\n boxFlexGroup: true,\n boxOrdinalGroup: true,\n columnCount: true,\n columns: true,\n flex: true,\n flexGrow: true,\n flexPositive: true,\n flexShrink: true,\n flexNegative: true,\n flexOrder: true,\n gridRow: true,\n gridRowEnd: true,\n gridRowSpan: true,\n gridRowStart: true,\n gridColumn: true,\n gridColumnEnd: true,\n gridColumnSpan: true,\n gridColumnStart: true,\n fontWeight: true,\n lineClamp: true,\n lineHeight: true,\n opacity: true,\n order: true,\n orphans: true,\n tabSize: true,\n widows: true,\n zIndex: true,\n zoom: true,\n\n // SVG-related properties\n fillOpacity: true,\n floodOpacity: true,\n stopOpacity: true,\n strokeDasharray: true,\n strokeDashoffset: true,\n strokeMiterlimit: true,\n strokeOpacity: true,\n strokeWidth: true,\n};\n"],"mappings":";;;;;;AAAA;AACO,MAAMA,KAAK,GAAAC,OAAA,CAAAD,KAAA,GA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OAAO,EAAE,IAAI;EACbC,OAAO,EAAE,IAAI;EACbC,MAAM,EAAE,IAAI;EACZC,MAAM,EAAE,IAAI;EACZC,IAAI,EAAE,IAAI;EAEV;EACAC,WAAW,EAAE,IAAI;EACjBC,YAAY,EAAE,IAAI;EAClBC,WAAW,EAAE,IAAI;EACjBC,eAAe,EAAE,IAAI;EACrBC,gBAAgB,EAAE,IAAI;EACtBC,gBAAgB,EAAE,IAAI;EACtBC,aAAa,EAAE,IAAI;EACnBC,WAAW,EAAE;AACf,CAAC","ignoreList":[]}
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.isValidParams = isValidParams;
|
|
7
|
-
exports.validateParams = validateParams;
|
|
8
|
-
// ParamMapping maps each ParamName to its corresponding Param type.
|
|
9
|
-
|
|
10
|
-
// GetParamByName returns the Param type based on the input type T.
|
|
11
|
-
|
|
12
|
-
// If T is none of the above, return never.
|
|
13
|
-
|
|
14
|
-
// MapParams iteratively maps the input ParamConstraints to their corresponding Param types.
|
|
15
|
-
|
|
16
|
-
// If TNames is an empty tuple, return the result tuple.
|
|
17
|
-
|
|
18
|
-
function isValidParams(params, constraints) {
|
|
19
|
-
const length = Math.max(params.length, constraints.length);
|
|
20
|
-
for (let i = 0; i < length; i++) {
|
|
21
|
-
var _params$i2;
|
|
22
|
-
if (params[i] === undefined || constraints[i] === undefined) {
|
|
23
|
-
return false;
|
|
24
|
-
}
|
|
25
|
-
const constraint = constraints[i];
|
|
26
|
-
if (constraint === '...') {
|
|
27
|
-
return true;
|
|
28
|
-
}
|
|
29
|
-
if (constraint === '*') {
|
|
30
|
-
if (params[i] === undefined) {
|
|
31
|
-
return false;
|
|
32
|
-
}
|
|
33
|
-
} else if (Array.isArray(constraint)) {
|
|
34
|
-
if (constraint.every(c => {
|
|
35
|
-
var _params$i;
|
|
36
|
-
return c !== ((_params$i = params[i]) === null || _params$i === void 0 ? void 0 : _params$i[0]);
|
|
37
|
-
})) {
|
|
38
|
-
return false;
|
|
39
|
-
}
|
|
40
|
-
} else if (constraint !== ((_params$i2 = params[i]) === null || _params$i2 === void 0 ? void 0 : _params$i2[0])) {
|
|
41
|
-
return false;
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
return true;
|
|
45
|
-
}
|
|
46
|
-
function validateParams(params, constraints, messageOrError) {
|
|
47
|
-
if (!isValidParams(params, constraints)) {
|
|
48
|
-
if (typeof messageOrError === 'string') {
|
|
49
|
-
throw new Error(messageOrError);
|
|
50
|
-
}
|
|
51
|
-
throw messageOrError;
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
//# sourceMappingURL=validateParams.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"validateParams.js","names":["isValidParams","params","constraints","length","Math","max","i","_params$i2","undefined","constraint","Array","isArray","every","c","_params$i","validateParams","messageOrError","Error"],"sources":["../../src/utils/validateParams.ts"],"sourcesContent":["import type { Param, Params } from '../types';\n\ntype ParamName = Param[0];\ntype ParamConstraint = ParamName | [...ParamName[]] | '*';\n\nexport type ParamConstraints =\n | [...ParamConstraint[]]\n | [...ParamConstraint[], '...'];\n\n// ParamMapping maps each ParamName to its corresponding Param type.\ntype ParamMapping = {\n [K in ParamName]: Extract<Param, readonly [K, ...unknown[]]>; // For each ParamName K, extract the corresponding Param type.\n};\n\n// GetParamByName returns the Param type based on the input type T.\ntype GetParamByName<T> = T extends '*'\n ? Param // If T is '*', return Param type.\n : T extends keyof ParamMapping // If T is a key in ParamMapping (i.e., a ParamName).\n ? ParamMapping[T] // Return the corresponding Param type from ParamMapping.\n : T extends Array<infer TNames> // If T is an array of names.\n ? TNames extends ParamName // If TNames is a ParamName.\n ? Extract<Param, readonly [TNames, ...unknown[]]> // Return the corresponding Param type.\n : never // If TNames is not a ParamName, return never.\n : never; // If T is none of the above, return never.\n\n// MapParams iteratively maps the input ParamConstraints to their corresponding Param types.\nexport type MapParams<\n TNames extends ParamConstraints,\n TRes extends Param[] = [],\n> = TNames extends [infer THead, ...infer TTail] // If TNames is a non-empty tuple.\n ? THead extends '...' // If the first element in the tuple is '...'.\n ? [...TRes, ...Params] // Append all Params to the result tuple.\n : MapParams<\n Extract<TTail, ParamConstraints>, // Extract the remaining ParamConstraints.\n [...TRes, GetParamByName<Extract<THead, ParamName | '*' | ParamName[]>>] // Append the mapped Param to the result tuple and recurse.\n >\n : TRes; // If TNames is an empty tuple, return the result tuple.\n\nexport function isValidParams<T extends ParamConstraints>(\n params: Params,\n constraints: T\n): params is MapParams<T> {\n const length = Math.max(params.length, constraints.length);\n for (let i = 0; i < length; i++) {\n if (params[i] === undefined || constraints[i] === undefined) {\n return false;\n }\n\n const constraint = constraints[i];\n if (constraint === '...') {\n return true;\n }\n\n if (constraint === '*') {\n if (params[i] === undefined) {\n return false;\n }\n } else if (Array.isArray(constraint)) {\n if (constraint.every((c) => c !== params[i]?.[0])) {\n return false;\n }\n } else if (constraint !== params[i]?.[0]) {\n return false;\n }\n }\n\n return true;\n}\n\nexport function validateParams<T extends ParamConstraints>(\n params: Params,\n constraints: T,\n messageOrError: unknown\n): asserts params is MapParams<T> {\n if (!isValidParams(params, constraints)) {\n if (typeof messageOrError === 'string') {\n throw new Error(messageOrError);\n }\n\n throw messageOrError;\n }\n}\n"],"mappings":";;;;;;;AASA;;AAKA;;AASW;;AAEX;;AAWU;;AAEH,SAASA,aAAaA,CAC3BC,MAAc,EACdC,WAAc,EACU;EACxB,MAAMC,MAAM,GAAGC,IAAI,CAACC,GAAG,CAACJ,MAAM,CAACE,MAAM,EAAED,WAAW,CAACC,MAAM,CAAC;EAC1D,KAAK,IAAIG,CAAC,GAAG,CAAC,EAAEA,CAAC,GAAGH,MAAM,EAAEG,CAAC,EAAE,EAAE;IAAA,IAAAC,UAAA;IAC/B,IAAIN,MAAM,CAACK,CAAC,CAAC,KAAKE,SAAS,I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