@avstantso/js 1.1.0 → 1.2.2
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/CHANGELOG.md +14 -0
- package/dist/_global/_register.d.ts +35 -0
- package/dist/_global/index.d.ts +4 -0
- package/dist/_global/is.d.ts +60 -0
- package/dist/_global/switch.d.ts +50 -0
- package/dist/_global/type-info.d.ts +33 -0
- package/dist/export.d.ts +2 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +94 -0
- package/dist/index.js.map +1 -0
- package/package.json +4 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
|
|
4
|
+
## [1.2.2] - 2026-01-31
|
|
5
|
+
|
|
6
|
+
### Changed
|
|
7
|
+
|
|
8
|
+
- Updated `@avstantso/ts` dependency (Updated @avstantso/ts dependency (fix String, Filter))
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
## [1.2.1] - 2026-01-18
|
|
12
|
+
|
|
13
|
+
### Changed
|
|
14
|
+
|
|
15
|
+
- Fix publishing
|
|
16
|
+
|
|
3
17
|
All notable changes to this project will be documented in this file.
|
|
4
18
|
|
|
5
19
|
## [1.1.0] - 2026-01-18
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
declare namespace AVStantso {
|
|
2
|
+
/**
|
|
3
|
+
* @summary JavaScript helpers
|
|
4
|
+
*/
|
|
5
|
+
namespace JS {
|
|
6
|
+
/**
|
|
7
|
+
* @summary JS types (available resault of `typeof`)
|
|
8
|
+
*/
|
|
9
|
+
type Type = keyof AVStantso.TS.Literal.Builtins;
|
|
10
|
+
}
|
|
11
|
+
namespace Code {
|
|
12
|
+
namespace JS {
|
|
13
|
+
/**
|
|
14
|
+
* @summary Map of JS types (available resault of `typeof`).
|
|
15
|
+
*/
|
|
16
|
+
type Types = Readonly<AVStantso.TS.Key2Key<AVStantso.JS.Type>>;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* @summary JavaScript helpers utility
|
|
20
|
+
*/
|
|
21
|
+
interface JS extends JS.Types {
|
|
22
|
+
/**
|
|
23
|
+
* @summary Map of JS types (available resault of `typeof`).
|
|
24
|
+
*/
|
|
25
|
+
Types: JS.Types;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
interface Code {
|
|
29
|
+
/**
|
|
30
|
+
* @summary JavaScript helpers utility
|
|
31
|
+
*/
|
|
32
|
+
JS: Code.JS;
|
|
33
|
+
}
|
|
34
|
+
const JS: Code.JS;
|
|
35
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
declare namespace AVStantso {
|
|
2
|
+
namespace Code {
|
|
3
|
+
namespace JS {
|
|
4
|
+
namespace Is {
|
|
5
|
+
export type Func<B> = <T extends B = B>(candidate: unknown) => candidate is T;
|
|
6
|
+
export type TypeFunc = <T>(type: AVStantso.JS.Type, candidate: unknown) => candidate is T;
|
|
7
|
+
export type ClassFunc<B extends object = object> = <T extends B = B>(objClass: AVStantso.TS.Class<T>, candidate: unknown) => candidate is T;
|
|
8
|
+
export type ByTypes = {
|
|
9
|
+
[K in AVStantso.JS.Type]: Func<AVStantso.TS.Literal.Builtins[K]>;
|
|
10
|
+
};
|
|
11
|
+
export type ByClasses = {
|
|
12
|
+
class: ClassFunc;
|
|
13
|
+
error: ClassFunc<Error>;
|
|
14
|
+
};
|
|
15
|
+
export type ByCombination = {
|
|
16
|
+
/**
|
|
17
|
+
* @summary Wrapper on `typeof XXX === 'object' || typeof XXX === 'function'`\
|
|
18
|
+
* — type that posible use with `Object.defineProperty`.
|
|
19
|
+
*/
|
|
20
|
+
structure: Func<object | Function>;
|
|
21
|
+
};
|
|
22
|
+
namespace OneOf {
|
|
23
|
+
type Set<T> = [set?: ReadonlyArray<T> | ReadonlySet<T>] | [...set: T[]];
|
|
24
|
+
export type Func<B> = <T extends B = B>(candidate: unknown, ...set: Set<T>) => candidate is T;
|
|
25
|
+
export type TypeFunc = <T>(type: AVStantso.JS.Type, candidate: unknown, ...set: Set<T>) => candidate is T;
|
|
26
|
+
export type ClassFunc<B extends object = object> = <T extends B = B>(objClass: AVStantso.TS.Class<T>, candidate: unknown, ...set: Set<AVStantso.TS.Class<T>>) => candidate is T;
|
|
27
|
+
export type ByTypes = {
|
|
28
|
+
[K in AVStantso.JS.Type]: Func<AVStantso.TS.Literal.Builtins[K]>;
|
|
29
|
+
};
|
|
30
|
+
export type ByClasses = {
|
|
31
|
+
class: ClassFunc;
|
|
32
|
+
error: ClassFunc<Error>;
|
|
33
|
+
};
|
|
34
|
+
export type ByCombination = {
|
|
35
|
+
/**
|
|
36
|
+
* @summary Wrapper on `typeof XXX === 'object' || typeof XXX === 'function'`\
|
|
37
|
+
* — type that posible use with `Object.defineProperty`.\
|
|
38
|
+
* _Short ~synonym of `TS.Structure.is`_
|
|
39
|
+
* @see TS.Structure.is
|
|
40
|
+
*/
|
|
41
|
+
structure: Func<'object' | 'function'>;
|
|
42
|
+
};
|
|
43
|
+
export {};
|
|
44
|
+
}
|
|
45
|
+
export type OneOf = OneOf.TypeFunc & OneOf.ByTypes & OneOf.ByClasses & OneOf.ByCombination;
|
|
46
|
+
export {};
|
|
47
|
+
}
|
|
48
|
+
export type Is = Is.TypeFunc & Is.ByTypes & Is.ByClasses & Is.ByCombination & {
|
|
49
|
+
oneOf: Is.OneOf;
|
|
50
|
+
};
|
|
51
|
+
export {};
|
|
52
|
+
}
|
|
53
|
+
interface JS {
|
|
54
|
+
/**
|
|
55
|
+
* @summary Wrapper on `typeof XXX === YYY` and `instanceof`
|
|
56
|
+
*/
|
|
57
|
+
is: JS.Is;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
declare namespace AVStantso {
|
|
2
|
+
namespace JS.Switch {
|
|
3
|
+
/**
|
|
4
|
+
* @summary Cases key for switch value by `typeof`
|
|
5
|
+
*/
|
|
6
|
+
type Key = Type | 'null' | 'default';
|
|
7
|
+
/**
|
|
8
|
+
* @summary Case for switch value by `typeof`
|
|
9
|
+
*/
|
|
10
|
+
type Case<R, K extends Key> = TS.Func.Is<R, never, R> | (K extends 'default' ? (<P>(arg: P, ...params: TS.Arr) => R) : K extends 'undefined' | 'null' ? (...params: TS.Arr) => R : <P extends TS.Literal.Builtins[Extract<K, Type>]>(arg: P, ...params: TS.Arr) => R);
|
|
11
|
+
/**
|
|
12
|
+
* @summary Cases for switch value by `typeof` key + `null` + `default` case
|
|
13
|
+
*/
|
|
14
|
+
type Cases<R> = {
|
|
15
|
+
[K in Key]?: Case<R, K>;
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
namespace Code {
|
|
19
|
+
interface JS {
|
|
20
|
+
/**
|
|
21
|
+
* @summary Switch value by `typeof` key function or default key
|
|
22
|
+
* @template R Case result type
|
|
23
|
+
* @template T Argument data type
|
|
24
|
+
* @template Cases Infer type of cases
|
|
25
|
+
* @param data Data for get `typeof` and switch
|
|
26
|
+
* @param cases Cases of switch
|
|
27
|
+
* @example
|
|
28
|
+
* const uk = JS.switch(15, { string: 46, number: 98 });
|
|
29
|
+
* expect(uk).toBe(98);
|
|
30
|
+
*
|
|
31
|
+
* const s: string = JS.switch(uk, { default: 'xyz' });
|
|
32
|
+
* expect(s).toBe('xyz');
|
|
33
|
+
*
|
|
34
|
+
* const o = JS.switch<number>({}, { object: 14, default: 86, string: 42 });
|
|
35
|
+
* expect(o).toBe(14);
|
|
36
|
+
*
|
|
37
|
+
* const nl = JS.switch(null, { default: 1, object: 2, null: 3, undefined: 4, string: 5 });
|
|
38
|
+
* expect(nl).toBe(3);
|
|
39
|
+
*
|
|
40
|
+
* const calc: string = JS.switch({ name: 'Jon' } as unknown, {
|
|
41
|
+
* string: (v) => v.repeat(2),
|
|
42
|
+
* object: (v: { name?: string }) => v.name,
|
|
43
|
+
* number: '!!!'
|
|
44
|
+
* });
|
|
45
|
+
* expect(calc).toBe('Jon');
|
|
46
|
+
*/
|
|
47
|
+
switch<R, T = unknown, Cases extends AVStantso.JS.Switch.Cases<R> = AVStantso.JS.Switch.Cases<R>>(data: T, cases: Cases): R;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
declare namespace AVStantso {
|
|
2
|
+
namespace JS {
|
|
3
|
+
namespace TypeInfo {
|
|
4
|
+
/**
|
|
5
|
+
* @summary Runtime type information provider for objects
|
|
6
|
+
*/
|
|
7
|
+
type Provider = {
|
|
8
|
+
/**
|
|
9
|
+
* @summary Runtime type information for objects
|
|
10
|
+
*/
|
|
11
|
+
typeInfo: TypeInfo;
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* @summary Runtime type information for objects
|
|
16
|
+
* @description For example, I use this mechanism when dynamically rendering React components.\
|
|
17
|
+
* If an attribute has no value, but is declared as `boolean` in `typeInfo`, the value is interpreted as `true`.
|
|
18
|
+
*/
|
|
19
|
+
type TypeInfo = NodeJS.ReadOnlyDict<TS.Literal>;
|
|
20
|
+
}
|
|
21
|
+
namespace Code {
|
|
22
|
+
interface JS {
|
|
23
|
+
/**
|
|
24
|
+
* @summary Check exists `typeInfo` in `object` or `Function`
|
|
25
|
+
*/
|
|
26
|
+
hasTypeInfo(candidate: unknown): candidate is AVStantso.JS.TypeInfo.Provider;
|
|
27
|
+
/**
|
|
28
|
+
* @summary Try get `typeInfo` from `object` or `Function` if it exists
|
|
29
|
+
*/
|
|
30
|
+
tryTypeInfo(candidate: unknown): AVStantso.JS.TypeInfo;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
package/dist/export.d.ts
ADDED
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
require('@avstantso/ts');
|
|
4
|
+
|
|
5
|
+
var AVStantso$2;
|
|
6
|
+
(function (AVStantso) {
|
|
7
|
+
AVStantso.JS = avstantso._reg.JS(({ TS }) => {
|
|
8
|
+
const Types = Object.freeze(Object.fromEntries(TS.Literal.Builtins.map((t) => [t, t])));
|
|
9
|
+
return { ...Types, Types };
|
|
10
|
+
});
|
|
11
|
+
})(AVStantso$2 || (AVStantso$2 = {}));
|
|
12
|
+
|
|
13
|
+
(function (AVStantso) {
|
|
14
|
+
avstantso._reg.JS.is(({ TS }) => {
|
|
15
|
+
function checkInSet(candidate, params) {
|
|
16
|
+
if (params.length) {
|
|
17
|
+
if ('object' === typeof params[0]) {
|
|
18
|
+
if (params[0] instanceof Set)
|
|
19
|
+
return params[0].has(candidate);
|
|
20
|
+
if (Array.isArray(params[0]))
|
|
21
|
+
return params[0].includes(candidate);
|
|
22
|
+
}
|
|
23
|
+
return params.includes(candidate);
|
|
24
|
+
}
|
|
25
|
+
return true;
|
|
26
|
+
}
|
|
27
|
+
function is(type, candidate, ...params) {
|
|
28
|
+
return (type === typeof candidate) && (!params.length || checkInSet(candidate, params));
|
|
29
|
+
}
|
|
30
|
+
function isClass(objClass, candidate, ...params) {
|
|
31
|
+
try {
|
|
32
|
+
return (candidate
|
|
33
|
+
&& 'object' === typeof candidate
|
|
34
|
+
&& candidate instanceof objClass
|
|
35
|
+
&& (!params.length || checkInSet(candidate, params)));
|
|
36
|
+
}
|
|
37
|
+
catch (e) {
|
|
38
|
+
e.candidate = candidate;
|
|
39
|
+
throw e;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
function isStructure(candidate, ...params) {
|
|
43
|
+
return TS.Structure.is(candidate)
|
|
44
|
+
&& (!params.length || checkInSet(candidate, params));
|
|
45
|
+
}
|
|
46
|
+
is.class = isClass;
|
|
47
|
+
is.error = isClass;
|
|
48
|
+
is.structure = isStructure;
|
|
49
|
+
for (const type of TS.Literal.Builtins)
|
|
50
|
+
Object.defineProperty(is, type, {
|
|
51
|
+
value: is.bind(null, type),
|
|
52
|
+
writable: false
|
|
53
|
+
});
|
|
54
|
+
Object.defineProperties(is, { oneOf: { get: () => is } });
|
|
55
|
+
return is;
|
|
56
|
+
});
|
|
57
|
+
})();
|
|
58
|
+
|
|
59
|
+
(function (AVStantso) {
|
|
60
|
+
avstantso._reg.JS.hasTypeInfo(() => function hasTypeInfo(candidate) {
|
|
61
|
+
const { typeInfo } = (candidate || {});
|
|
62
|
+
return !!typeInfo && 'object' === typeof typeInfo;
|
|
63
|
+
});
|
|
64
|
+
avstantso._reg.JS.tryTypeInfo(() => function tryTypeInfo(candidate) {
|
|
65
|
+
const { typeInfo } = (candidate || {});
|
|
66
|
+
return 'object' === typeof typeInfo && typeInfo;
|
|
67
|
+
});
|
|
68
|
+
})();
|
|
69
|
+
|
|
70
|
+
var AVStantso$1;
|
|
71
|
+
(function (AVStantso) {
|
|
72
|
+
(function (Code) {
|
|
73
|
+
avstantso._reg.JS.switch(() => {
|
|
74
|
+
function _switch(data, cases) {
|
|
75
|
+
function resolve(value) {
|
|
76
|
+
return 'function' === typeof value ? value(data) : value;
|
|
77
|
+
}
|
|
78
|
+
if (null === data && 'null' in cases)
|
|
79
|
+
return resolve(cases.null);
|
|
80
|
+
const t = typeof data;
|
|
81
|
+
if (t in cases)
|
|
82
|
+
return resolve(cases[t]);
|
|
83
|
+
if ('default' in cases)
|
|
84
|
+
return resolve(cases.default);
|
|
85
|
+
}
|
|
86
|
+
return _switch;
|
|
87
|
+
});
|
|
88
|
+
})(AVStantso.Code || (AVStantso.Code = {}));
|
|
89
|
+
})(AVStantso$1 || (AVStantso$1 = {}));
|
|
90
|
+
|
|
91
|
+
var JS = AVStantso.JS;
|
|
92
|
+
|
|
93
|
+
exports.JS = JS;
|
|
94
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../src/_global/_register.ts","../src/_global/is.ts","../src/_global/type-info.ts","../src/_global/switch.ts","../src/export.ts"],"sourcesContent":["namespace AVStantso {\n /**\n * @summary JavaScript helpers\n */\n export namespace JS {\n /**\n * @summary JS types (available resault of `typeof`)\n */\n export type Type = keyof AVStantso.TS.Literal.Builtins;\n }\n\n export namespace Code {\n export namespace JS {\n /**\n * @summary Map of JS types (available resault of `typeof`).\n */\n export type Types = Readonly<AVStantso.TS.Key2Key<AVStantso.JS.Type>>;\n }\n\n /**\n * @summary JavaScript helpers utility\n */\n export interface JS extends JS.Types {\n /**\n * @summary Map of JS types (available resault of `typeof`).\n */\n Types: JS.Types;\n }\n }\n\n export interface Code {\n /**\n * @summary JavaScript helpers utility\n */\n JS: Code.JS;\n }\n\n export const JS: Code.JS = avstantso._reg.JS(({ TS }) => {\n const Types = Object.freeze(\n Object.fromEntries(\n TS.Literal.Builtins.map((t) => [t, t])\n ) as Code.JS.Types\n );\n\n return { ...Types, Types };\n });\n}\n","namespace AVStantso {\n export namespace Code {\n export namespace JS {\n namespace Is {\n export type Func<B> = <T extends B = B>(\n candidate: unknown\n ) => candidate is T;\n\n export type TypeFunc = <T>(\n type: AVStantso.JS.Type,\n candidate: unknown\n ) => candidate is T;\n\n export type ClassFunc<B extends object = object> = <T extends B = B>(\n objClass: AVStantso.TS.Class<T>,\n candidate: unknown\n ) => candidate is T;\n\n export type ByTypes = {\n [K in AVStantso.JS.Type]: Func<AVStantso.TS.Literal.Builtins[K]>;\n };\n\n export type ByClasses = {\n class: ClassFunc;\n error: ClassFunc<Error>;\n };\n\n export type ByCombination = {\n /**\n * @summary Wrapper on `typeof XXX === 'object' || typeof XXX === 'function'`\\\n * — type that posible use with `Object.defineProperty`.\n */\n // eslint-disable-next-line @typescript-eslint/no-unsafe-function-type\n structure: Func<object | Function>;\n };\n\n namespace OneOf {\n type Set<T> = [set?: ReadonlyArray<T> | ReadonlySet<T>] | [...set: T[]];\n\n export type Func<B> = <T extends B = B>(\n candidate: unknown,\n ...set: Set<T>\n ) => candidate is T;\n\n export type TypeFunc = <T>(\n type: AVStantso.JS.Type,\n candidate: unknown,\n ...set: Set<T>\n ) => candidate is T;\n\n export type ClassFunc<B extends object = object> = <T extends B = B>(\n objClass: AVStantso.TS.Class<T>,\n candidate: unknown,\n ...set: Set<AVStantso.TS.Class<T>>\n ) => candidate is T;\n\n export type ByTypes = {\n [K in AVStantso.JS.Type]: Func<AVStantso.TS.Literal.Builtins[K]>;\n };\n\n export type ByClasses = {\n class: ClassFunc;\n error: ClassFunc<Error>;\n };\n\n export type ByCombination = {\n /**\n * @summary Wrapper on `typeof XXX === 'object' || typeof XXX === 'function'`\\\n * — type that posible use with `Object.defineProperty`.\\\n * _Short ~synonym of `TS.Structure.is`_\n * @see TS.Structure.is\n */\n structure: Func<'object' | 'function'>;\n };\n }\n\n export type OneOf = OneOf.TypeFunc & OneOf.ByTypes & OneOf.ByClasses & OneOf.ByCombination;\n }\n\n export type Is = Is.TypeFunc & Is.ByTypes & Is.ByClasses & Is.ByCombination & {\n oneOf: Is.OneOf;\n };\n }\n\n export interface JS {\n /**\n * @summary Wrapper on `typeof XXX === YYY` and `instanceof`\n */\n is: JS.Is;\n }\n }\n\n avstantso._reg.JS.is(({ TS }) => {\n function checkInSet(candidate: unknown, params: TS.Arr) {\n if (params.length) {\n if ('object' === typeof params[0]) {\n if (params[0] instanceof Set)\n return params[0].has(candidate);\n\n if (Array.isArray(params[0]))\n return params[0].includes(candidate);\n }\n\n return params.includes(candidate);\n }\n\n return true;\n }\n\n\n function is(type: string, candidate: unknown, ...params: TS.Arr) {\n return (type === typeof candidate) && (!params.length || checkInSet(candidate, params));\n }\n\n function isClass(objClass: TS.Class, candidate: unknown, ...params: TS.Arr) {\n try {\n return (\n candidate\n && 'object' === typeof candidate\n && candidate instanceof objClass\n && (!params.length || checkInSet(candidate, params))\n );\n } catch (e) {\n e.candidate = candidate;\n throw e;\n }\n }\n\n function isStructure(candidate: unknown, ...params: TS.Arr) {\n return TS.Structure.is(candidate)\n && (!params.length || checkInSet(candidate, params));\n }\n\n is.class = isClass;\n is.error = isClass;\n is.structure = isStructure;\n\n for (const type of TS.Literal.Builtins)\n Object.defineProperty(is, type, {\n value: is.bind(null, type),\n writable: false\n });\n\n Object.defineProperties(is, { oneOf: { get: () => is } });\n\n return is as Code.JS.Is;\n });\n}\n","namespace AVStantso {\n export namespace JS {\n export namespace TypeInfo {\n /**\n * @summary Runtime type information provider for objects\n */\n export type Provider = {\n /**\n * @summary Runtime type information for objects\n */\n typeInfo: TypeInfo;\n };\n }\n\n /**\n * @summary Runtime type information for objects\n * @description For example, I use this mechanism when dynamically rendering React components.\\\n * If an attribute has no value, but is declared as `boolean` in `typeInfo`, the value is interpreted as `true`.\n */\n export type TypeInfo = NodeJS.ReadOnlyDict<TS.Literal>;\n }\n\n export namespace Code {\n export interface JS {\n /**\n * @summary Check exists `typeInfo` in `object` or `Function`\n */\n hasTypeInfo(\n candidate: unknown\n ): candidate is AVStantso.JS.TypeInfo.Provider;\n\n /**\n * @summary Try get `typeInfo` from `object` or `Function` if it exists\n */\n tryTypeInfo(candidate: unknown): AVStantso.JS.TypeInfo;\n }\n }\n\n avstantso._reg.JS.hasTypeInfo(\n () =>\n function hasTypeInfo(candidate: unknown): candidate is JS.TypeInfo.Provider {\n const { typeInfo } = (candidate || {}) as JS.TypeInfo.Provider;\n return !!typeInfo && 'object' === typeof typeInfo;\n }\n );\n\n avstantso._reg.JS.tryTypeInfo(\n () =>\n function tryTypeInfo(candidate: unknown){\n const { typeInfo } = (candidate || {}) as JS.TypeInfo.Provider;\n return 'object' === typeof typeInfo && typeInfo;\n }\n );\n}\n","namespace AVStantso {\n export namespace JS.Switch {\n /**\n * @summary Cases key for switch value by `typeof`\n */\n export type Key = Type | 'null' | 'default';\n\n /**\n * @summary Case for switch value by `typeof`\n */\n export type Case<R, K extends Key> = TS.Func.Is<R, never, R>\n | (K extends 'default'\n ? (<P>(arg: P, ...params: TS.Arr) => R)\n : K extends 'undefined' | 'null'\n ? (...params: TS.Arr) => R\n : <P extends TS.Literal.Builtins[Extract<K, Type>]>(\n arg: P, ...params: TS.Arr\n ) => R\n );\n\n /**\n * @summary Cases for switch value by `typeof` key + `null` + `default` case\n */\n export type Cases<R> = {\n [K in Key]?: Case<R, K>;\n };\n }\n\n export namespace Code {\n export interface JS {\n /**\n * @summary Switch value by `typeof` key function or default key\n * @template R Case result type\n * @template T Argument data type\n * @template Cases Infer type of cases\n * @param data Data for get `typeof` and switch\n * @param cases Cases of switch\n * @EXAMPLE(@JS.Switch)\n */\n switch<\n R,\n T = unknown,\n Cases extends AVStantso.JS.Switch.Cases<R> = AVStantso.JS.Switch.Cases<R>\n >(data: T, cases: Cases): R;\n }\n\n avstantso._reg.JS.switch(() => {\n function _switch(data: unknown, cases: NodeJS.Dict<unknown>) {\n function resolve(value: unknown) {\n return 'function' === typeof value ? value(data) : value;\n }\n\n if (null === data && 'null' in cases)\n return resolve(cases.null);\n\n const t = typeof data;\n if (t in cases)\n return resolve(cases[t]);\n\n if ('default' in cases)\n return resolve(cases.default);\n }\n\n return _switch;\n });\n }\n}\n","import JS = AVStantso.JS;\nexport { JS };\n"],"names":["AVStantso"],"mappings":";;;;AAAA,IAAUA,WAAS;AAAnB,CAAA,UAAU,SAAS,EAAA;AAqCJ,IAAA,SAAA,CAAA,EAAE,GAAY,SAAS,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,EAAE,KAAI;AACtD,QAAA,MAAM,KAAK,GAAG,MAAM,CAAC,MAAM,CACzB,MAAM,CAAC,WAAW,CAChB,EAAE,CAAC,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CACtB,CACnB;AAED,QAAA,OAAO,EAAE,GAAG,KAAK,EAAE,KAAK,EAAE;AAC5B,IAAA,CAAC,CAAC;AACJ,CAAC,EA9CSA,WAAS,KAATA,WAAS,GAAA,EAAA,CAAA,CAAA;;ACAnB,CAAA,UAAU,SAAS,EAAA;AA4FjB,IAAA,SAAS,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,CAAC,C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A,UAAU,SAAS,EAAA;AA4BjB,IAAA,CAAA,UAAiB,IAAI,EAAA;QAkBnB,SAAS,CAAC,IAAI,CAAC,EAAE,CAAC,MAAM,CAAC,MAAK;AAC5B,YAAA,SAAS,OAAO,CAAC,IAAa,EAAE,KAA2B,EAAA;gBACzD,SAAS,OAAO,CAAC,KAAc,EAAA;AAC7B,oBAAA,OAAO,UAAU,KAAK,OAAO,KAAK,GAAG,KAAK,CAAC,IAAI,CAAC,GAAG,KAAK;gBAC1D;AAEA,gBAAA,IAAI,IAAI,KAAK,IAAI,IAAI,MAAM,IAAI,KAAK;AAClC,oBAAA,OAAO,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC;AAE5B,gBAAA,MAAM,CAAC,GAAG,OAAO,IAAI;gBACrB,IAAI,CAAC,IAAI,KAAK;AACZ,oBAAA,OAAO,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;gBAE1B,IAAI,SAAS,IAAI,KAAK;AACpB,oBAAA,OAAO,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC;YACjC;AAEA,YAAA,OAAO,OAAO;AAChB,QAAA,CAAC,CAAC;AACJ,IAAA,CAAC,EArCgB,SAAA,CAAA,IAAI,KAAJ,cAAI,GAAA,EAAA,CAAA,CAAA;AAsCvB,CAAC,EAlESA,WAAS,KAATA,WAAS,GAAA,EAAA,CAAA,CAAA;;ACAnB,IAAO,EAAE,GAAG,SAAS,CAAC;;;;"}
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@avstantso/js",
|
|
3
3
|
"license": "MIT",
|
|
4
4
|
"author": "avstantso",
|
|
5
|
-
"version": "1.
|
|
5
|
+
"version": "1.2.2",
|
|
6
6
|
"description": "JavaScript helpers",
|
|
7
7
|
"keywords": [
|
|
8
8
|
"JavaScript"
|
|
@@ -23,9 +23,9 @@
|
|
|
23
23
|
"test": "NODE_ENV=test jest --coverage"
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@avstantso/core": "1.1
|
|
27
|
-
"@avstantso/std-ext": "1.1
|
|
28
|
-
"@avstantso/ts": "1.
|
|
26
|
+
"@avstantso/core": "1.2.1",
|
|
27
|
+
"@avstantso/std-ext": "1.2.1",
|
|
28
|
+
"@avstantso/ts": "1.3.0"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
31
|
"@avstantso/dev-basic": "1.0.0"
|