@estjs/shared 0.0.10-beta.21

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/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023-Present jiangxd <jiangxd2016@gmail.com>
4
+ Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ of this software and associated documentation files (the "Software"), to deal
6
+ in the Software without restriction, including without limitation the rights
7
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ copies of the Software, and to permit persons to whom the Software is
9
+ furnished to do so, subject to the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be included in all
12
+ copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ SOFTWARE.
package/README.md ADDED
File without changes
@@ -0,0 +1,194 @@
1
+ /**
2
+ * @estjs/shared v0.0.10-beta.20
3
+ * (c) 2023-Present jiangxd <jiangxd2016@gmail.com>
4
+ * @license MIT
5
+ **/
6
+ "use strict";
7
+ var __defProp = Object.defineProperty;
8
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
9
+ var __getOwnPropNames = Object.getOwnPropertyNames;
10
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
11
+ var __export = (target, all) => {
12
+ for (var name in all)
13
+ __defProp(target, name, { get: all[name], enumerable: true });
14
+ };
15
+ var __copyProps = (to, from, except, desc) => {
16
+ if (from && typeof from === "object" || typeof from === "function") {
17
+ for (let key of __getOwnPropNames(from))
18
+ if (!__hasOwnProp.call(to, key) && key !== except)
19
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
20
+ }
21
+ return to;
22
+ };
23
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
24
+
25
+ // src/index.ts
26
+ var src_exports = {};
27
+ __export(src_exports, {
28
+ _toString: () => _toString,
29
+ camelCase: () => camelCase,
30
+ capitalizeFirstLetter: () => capitalizeFirstLetter,
31
+ coerceArray: () => coerceArray,
32
+ error: () => error,
33
+ escape: () => escape,
34
+ extend: () => extend,
35
+ hasChanged: () => hasChanged,
36
+ hasOwn: () => hasOwn,
37
+ info: () => info,
38
+ isArray: () => isArray,
39
+ isExclude: () => isExclude,
40
+ isFalsy: () => isFalsy,
41
+ isFunction: () => isFunction,
42
+ isHTMLElement: () => isHTMLElement,
43
+ isMap: () => isMap,
44
+ isNil: () => isNil,
45
+ isObject: () => isObject,
46
+ isPrimitive: () => isPrimitive,
47
+ isPromise: () => isPromise,
48
+ isSet: () => isSet,
49
+ isString: () => isString,
50
+ isSymbol: () => isSymbol,
51
+ isWeakMap: () => isWeakMap,
52
+ isWeakSet: () => isWeakSet,
53
+ kebabCase: () => kebabCase,
54
+ noop: () => noop,
55
+ startsWith: () => startsWith,
56
+ warn: () => warn
57
+ });
58
+ module.exports = __toCommonJS(src_exports);
59
+
60
+ // src/is.ts
61
+ var isObject = (val) => val !== null && typeof val === "object";
62
+ function isPromise(val) {
63
+ return _toString.call(val) === "[object Promise]";
64
+ }
65
+ var isArray = Array.isArray;
66
+ function isString(val) {
67
+ return typeof val === "string";
68
+ }
69
+ function isNull(val) {
70
+ return val === null;
71
+ }
72
+ function isSymbol(val) {
73
+ return typeof val === "symbol";
74
+ }
75
+ function isSet(val) {
76
+ return _toString.call(val) === "[object Set]";
77
+ }
78
+ function isWeakMap(val) {
79
+ return _toString.call(val) === "[object WeakMap]";
80
+ }
81
+ function isWeakSet(val) {
82
+ return _toString.call(val) === "[object WeakSet]";
83
+ }
84
+ function isMap(val) {
85
+ return _toString.call(val) === "[object Map]";
86
+ }
87
+ function isNil(x) {
88
+ return x === null || x === void 0;
89
+ }
90
+ var isFunction = (val) => typeof val === "function";
91
+ function isFalsy(x) {
92
+ return x === false || x === null || x === void 0;
93
+ }
94
+ var isPrimitive = (val) => ["string", "number", "boolean", "symbol", "undefined"].includes(typeof val) || isNull(val);
95
+ function isHTMLElement(obj) {
96
+ if (!obj) return false;
97
+ return obj && typeof obj === "object" && obj.nodeType === 1 && typeof obj.nodeName === "string";
98
+ }
99
+
100
+ // src/comm.ts
101
+ var _toString = Object.prototype.toString;
102
+ var extend = Object.assign;
103
+ var hasOwnProperty = Object.prototype.hasOwnProperty;
104
+ var hasOwn = (val, key) => hasOwnProperty.call(val, key);
105
+ function coerceArray(data) {
106
+ return Array.isArray(data) ? data.flat() : [data];
107
+ }
108
+ var hasChanged = (value, oldValue) => value !== oldValue && (value === value || oldValue === oldValue);
109
+ var noop = Function.prototype;
110
+ function startsWith(str, searchString) {
111
+ if (!isString(str)) {
112
+ return false;
113
+ }
114
+ return str.indexOf(searchString) === 0;
115
+ }
116
+ function escape(str) {
117
+ return str.replaceAll(/["&'<>]/g, (char) => {
118
+ switch (char) {
119
+ case "&":
120
+ return "&amp;";
121
+ case "<":
122
+ return "&lt;";
123
+ case ">":
124
+ return "&gt;";
125
+ case '"':
126
+ return "&quot;";
127
+ case "'":
128
+ return "&#039;";
129
+ default:
130
+ return char;
131
+ }
132
+ });
133
+ }
134
+ function isExclude(key, exclude) {
135
+ return Array.isArray(exclude) ? exclude.includes(key) : isFunction(exclude) ? exclude(key) : false;
136
+ }
137
+
138
+ // src/name.ts
139
+ var kebabCase = (string) => {
140
+ return string.replaceAll(/[A-Z]+/g, (match, offset) => {
141
+ return `${offset > 0 ? "-" : ""}${match.toLocaleLowerCase()}`;
142
+ });
143
+ };
144
+ var camelCase = (str) => {
145
+ const s = str.replaceAll(/[\s_-]+(.)?/g, (_, c) => c ? c.toUpperCase() : "");
146
+ return s[0].toLowerCase() + s.slice(1);
147
+ };
148
+ var capitalizeFirstLetter = (inputString) => {
149
+ return inputString.charAt(0).toUpperCase() + inputString.slice(1);
150
+ };
151
+
152
+ // src/console.ts
153
+ function warn(msg, ...args) {
154
+ console.warn.apply(console, [`[Essor warn]: ${msg}`].concat(args));
155
+ }
156
+ function info(msg, ...args) {
157
+ console.info.apply(console, [`[Essor info]: ${msg}`].concat(args));
158
+ }
159
+ function error(msg, ...args) {
160
+ console.error.apply(console, [`[Essor error]: ${msg}`].concat(args));
161
+ }
162
+ // Annotate the CommonJS export names for ESM import in node:
163
+ 0 && (module.exports = {
164
+ _toString,
165
+ camelCase,
166
+ capitalizeFirstLetter,
167
+ coerceArray,
168
+ error,
169
+ escape,
170
+ extend,
171
+ hasChanged,
172
+ hasOwn,
173
+ info,
174
+ isArray,
175
+ isExclude,
176
+ isFalsy,
177
+ isFunction,
178
+ isHTMLElement,
179
+ isMap,
180
+ isNil,
181
+ isObject,
182
+ isPrimitive,
183
+ isPromise,
184
+ isSet,
185
+ isString,
186
+ isSymbol,
187
+ isWeakMap,
188
+ isWeakSet,
189
+ kebabCase,
190
+ noop,
191
+ startsWith,
192
+ warn
193
+ });
194
+ //# sourceMappingURL=essor-shared.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts","../src/is.ts","../src/comm.ts","../src/name.ts","../src/console.ts"],"sourcesContent":["export {\n noop,\n _toString,\n extend,\n hasChanged,\n coerceArray,\n hasOwn,\n startsWith,\n escape,\n isExclude,\n ExcludeType,\n} from './comm';\nexport {\n isString,\n isObject,\n isArray,\n isMap,\n isSet,\n isWeakMap,\n isWeakSet,\n isFunction,\n isNil,\n isPromise,\n isSymbol,\n isFalsy,\n isPrimitive,\n isHTMLElement,\n} from './is';\nexport { camelCase, kebabCase, capitalizeFirstLetter } from './name';\nexport { warn, info, error } from './console';\n","import { _toString } from './comm';\n\nexport const isObject = (val: unknown): val is Record<any, any> =>\n val !== null && typeof val === 'object';\nexport function isPromise(val: any): boolean {\n return _toString.call(val) === '[object Promise]';\n}\n\nexport const isArray = Array.isArray;\n\nexport function isString(val: unknown): val is string {\n return typeof val === 'string';\n}\nexport function isNull(val: any): val is null {\n return val === null;\n}\nexport function isSymbol(val: unknown): val is symbol {\n return typeof val === 'symbol';\n}\n\nexport function isSet(val: any): val is Set<any> {\n return _toString.call(val) === '[object Set]';\n}\nexport function isWeakMap(val: any): val is WeakMap<any, any> {\n return _toString.call(val) === '[object WeakMap]';\n}\nexport function isWeakSet(val: any): val is WeakSet<any> {\n return _toString.call(val) === '[object WeakSet]';\n}\n\nexport function isMap(val: unknown): val is Map<any, any> {\n return _toString.call(val) === '[object Map]';\n}\nexport function isNil(x: any): x is null | undefined {\n return x === null || x === undefined;\n}\n\nexport const isFunction = (val: unknown): val is Function => typeof val === 'function';\n\nexport function isFalsy(x: any): x is false | null | undefined {\n return x === false || x === null || x === undefined;\n}\n\nexport const isPrimitive = (\n val: unknown,\n): val is string | number | boolean | symbol | null | undefined =>\n ['string', 'number', 'boolean', 'symbol', 'undefined'].includes(typeof val) || isNull(val);\n\nexport function isHTMLElement(obj) {\n if (!obj) return false;\n return obj && typeof obj === 'object' && obj.nodeType === 1 && typeof obj.nodeName === 'string';\n}\n","import { isFunction, isString } from './is';\n\nexport const _toString = Object.prototype.toString;\nexport const extend = Object.assign;\nconst hasOwnProperty = Object.prototype.hasOwnProperty;\nexport const hasOwn = (val: object, key: string | symbol): key is keyof typeof val =>\n hasOwnProperty.call(val, key);\n\nexport function coerceArray<T>(data: T | T[]): T[] {\n return Array.isArray(data) ? (data.flat() as T[]) : [data];\n}\nexport const hasChanged = (value, oldValue) =>\n value !== oldValue && (value === value || oldValue === oldValue);\nexport const noop = Function.prototype as () => void;\n\n/**\n * A function that checks if a string starts with a specific substring.\n * indexOf faster under normal circumstances\n * @see https://www.measurethat.net/Benchmarks/Show/12350/0/startswith-vs-test-vs-match-vs-indexof#latest_results_block\n\n * @param {string} str - The input string to check.\n * @param {string} searchString - The substring to check for at the beginning of the input string.\n * @return {boolean} Returns true if the input string starts with the specified substring, otherwise false.\n */\nexport function startsWith(str, searchString) {\n if (!isString(str)) {\n return false;\n }\n return str.indexOf(searchString) === 0;\n}\n\n/**\n * Escapes special HTML characters in a string.\n * @param str - The string to escape.\n * @returns The escaped string.\n */\nexport function escape(str: string): string {\n return str.replaceAll(/[\"&'<>]/g, char => {\n switch (char) {\n case '&':\n return '&amp;';\n case '<':\n return '&lt;';\n case '>':\n return '&gt;';\n case '\"':\n return '&quot;';\n case \"'\":\n return '&#039;';\n default:\n return char;\n }\n });\n}\n\nexport type ExcludeType = ((key: string | symbol) => boolean) | (string | symbol)[];\n\n/**\n * Checks if a key should be excluded based on the provided exclude criteria.\n * @param key - The key to check.\n * @param exclude - The exclusion criteria.\n * @returns True if the key should be excluded, otherwise false.\n */\nexport function isExclude(key: string | symbol, exclude?: ExcludeType): boolean {\n return Array.isArray(exclude)\n ? exclude.includes(key)\n : isFunction(exclude)\n ? exclude(key)\n : false;\n}\n","export const kebabCase = (string: string): string => {\n return string.replaceAll(/[A-Z]+/g, (match, offset) => {\n return `${offset > 0 ? '-' : ''}${match.toLocaleLowerCase()}`;\n });\n};\n\nexport const camelCase = (str: string): string => {\n const s = str.replaceAll(/[\\s_-]+(.)?/g, (_, c) => (c ? c.toUpperCase() : ''));\n return s[0].toLowerCase() + s.slice(1);\n};\n/**\n * Capitalizes the first letter of a string.\n *\n * @param {string} inputString - The input string to capitalize the first letter.\n * @return {string} The string with the first letter capitalized.\n */\nexport const capitalizeFirstLetter = (inputString: string): string => {\n return inputString.charAt(0).toUpperCase() + inputString.slice(1);\n};\n","export function warn(msg: string, ..._args: any[]): void;\nexport function warn(msg: string, ...args): void {\n // eslint-disable-next-line prefer-spread\n console.warn.apply(console, [`[Essor warn]: ${msg}`].concat(args) as [string, ...any[]]);\n}\n\nexport function info(msg: string, ..._args: any[]): void;\nexport function info(msg: string, ...args): void {\n // eslint-disable-next-line prefer-spread, no-console\n console.info.apply(console, [`[Essor info]: ${msg}`].concat(args) as [string, ...any[]]);\n}\n\nexport function error(msg: string, ..._args: any[]): void;\nexport function error(msg: string, ...args): void {\n // eslint-disable-next-line prefer-spread\n console.error.apply(console, [`[Essor error]: ${msg}`].concat(args) as [string, ...any[]]);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACEO,IAAM,WAAW,CAAC,QACvB,QAAQ,QAAQ,OAAO,QAAQ;AAC1B,SAAS,UAAU,KAAmB;AAC3C,SAAO,UAAU,KAAK,GAAG,MAAM;AACjC;AAEO,IAAM,UAAU,MAAM;AAEtB,SAAS,SAAS,KAA6B;AACpD,SAAO,OAAO,QAAQ;AACxB;AACO,SAAS,OAAO,KAAuB;AAC5C,SAAO,QAAQ;AACjB;AACO,SAAS,SAAS,KAA6B;AACpD,SAAO,OAAO,QAAQ;AACxB;AAEO,SAAS,MAAM,KAA2B;AAC/C,SAAO,UAAU,KAAK,GAAG,MAAM;AACjC;AACO,SAAS,UAAU,KAAoC;AAC5D,SAAO,UAAU,KAAK,GAAG,MAAM;AACjC;AACO,SAAS,UAAU,KAA+B;AACvD,SAAO,UAAU,KAAK,GAAG,MAAM;AACjC;AAEO,SAAS,MAAM,KAAoC;AACxD,SAAO,UAAU,KAAK,GAAG,MAAM;AACjC;AACO,SAAS,MAAM,GAA+B;AACnD,SAAO,MAAM,QAAQ,MAAM;AAC7B;AAEO,IAAM,aAAa,CAAC,QA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ACrEO,IAAM,YAAY,CAAC,WAA2B;AACnD,SAAO,OAAO,WAAW,WAAW,CAAC,OAAO,WAAW;AACrD,WAAO,GAAG,SAAS,IAAI,MAAM,EAAE,GAAG,MAAM,kBAAkB,CAAC;AAAA,EAC7D,CAAC;AACH;AAEO,IAAM,YAAY,CAAC,QAAwB;AAChD,QAAM,IAAI,IAAI,WAAW,gBAAgB,CAAC,GAAG,MAAO,IAAI,EAAE,YAAY,IAAI,EAAG;AAC7E,SAAO,EAAE,CAAC,EAAE,YAAY,IAAI,EAAE,MAAM,CAAC;AACvC;AAOO,IAAM,wBAAwB,CAAC,gBAAgC;AACpE,SAAO,YAAY,OAAO,CAAC,EAAE,YAAY,IAAI,YAAY,MAAM,CAAC;AAClE;;;ACjBO,SAAS,KAAK,QAAgB,MAAY;AAE/C,UAAQ,KAAK,MAAM,SAAS,CAAC,iBAAiB,GAAG,EAAE,EAAE,OAAO,IAAI,CAAuB;AACzF;AAGO,SAAS,KAAK,QAAgB,MAAY;AAE/C,UAAQ,KAAK,MAAM,SAAS,CAAC,iBAAiB,GAAG,EAAE,EAAE,OAAO,IAAI,CAAuB;AACzF;AAGO,SAAS,MAAM,QAAgB,MAAY;AAEhD,UAAQ,MAAM,MAAM,SAAS,CAAC,kBAAkB,GAAG,EAAE,EAAE,OAAO,IAAI,CAAuB;AAC3F;","names":[]}
@@ -0,0 +1,66 @@
1
+ declare const _toString: () => string;
2
+ declare const extend: {
3
+ <T extends {}, U>(target: T, source: U): T & U;
4
+ <T extends {}, U, V>(target: T, source1: U, source2: V): T & U & V;
5
+ <T extends {}, U, V, W>(target: T, source1: U, source2: V, source3: W): T & U & V & W;
6
+ (target: object, ...sources: any[]): any;
7
+ };
8
+ declare const hasOwn: (val: object, key: string | symbol) => key is keyof typeof val;
9
+ declare function coerceArray<T>(data: T | T[]): T[];
10
+ declare const hasChanged: (value: any, oldValue: any) => boolean;
11
+ declare const noop: () => void;
12
+ /**
13
+ * A function that checks if a string starts with a specific substring.
14
+ * indexOf faster under normal circumstances
15
+ * @see https://www.measurethat.net/Benchmarks/Show/12350/0/startswith-vs-test-vs-match-vs-indexof#latest_results_block
16
+
17
+ * @param {string} str - The input string to check.
18
+ * @param {string} searchString - The substring to check for at the beginning of the input string.
19
+ * @return {boolean} Returns true if the input string starts with the specified substring, otherwise false.
20
+ */
21
+ declare function startsWith(str: any, searchString: any): boolean;
22
+ /**
23
+ * Escapes special HTML characters in a string.
24
+ * @param str - The string to escape.
25
+ * @returns The escaped string.
26
+ */
27
+ declare function escape(str: string): string;
28
+ type ExcludeType = ((key: string | symbol) => boolean) | (string | symbol)[];
29
+ /**
30
+ * Checks if a key should be excluded based on the provided exclude criteria.
31
+ * @param key - The key to check.
32
+ * @param exclude - The exclusion criteria.
33
+ * @returns True if the key should be excluded, otherwise false.
34
+ */
35
+ declare function isExclude(key: string | symbol, exclude?: ExcludeType): boolean;
36
+
37
+ declare const isObject: (val: unknown) => val is Record<any, any>;
38
+ declare function isPromise(val: any): boolean;
39
+ declare const isArray: (arg: any) => arg is any[];
40
+ declare function isString(val: unknown): val is string;
41
+ declare function isSymbol(val: unknown): val is symbol;
42
+ declare function isSet(val: any): val is Set<any>;
43
+ declare function isWeakMap(val: any): val is WeakMap<any, any>;
44
+ declare function isWeakSet(val: any): val is WeakSet<any>;
45
+ declare function isMap(val: unknown): val is Map<any, any>;
46
+ declare function isNil(x: any): x is null | undefined;
47
+ declare const isFunction: (val: unknown) => val is Function;
48
+ declare function isFalsy(x: any): x is false | null | undefined;
49
+ declare const isPrimitive: (val: unknown) => val is string | number | boolean | symbol | null | undefined;
50
+ declare function isHTMLElement(obj: any): any;
51
+
52
+ declare const kebabCase: (string: string) => string;
53
+ declare const camelCase: (str: string) => string;
54
+ /**
55
+ * Capitalizes the first letter of a string.
56
+ *
57
+ * @param {string} inputString - The input string to capitalize the first letter.
58
+ * @return {string} The string with the first letter capitalized.
59
+ */
60
+ declare const capitalizeFirstLetter: (inputString: string) => string;
61
+
62
+ declare function warn(msg: string, ..._args: any[]): void;
63
+ declare function info(msg: string, ..._args: any[]): void;
64
+ declare function error(msg: string, ..._args: any[]): void;
65
+
66
+ export { type ExcludeType, _toString, camelCase, capitalizeFirstLetter, coerceArray, error, escape, extend, hasChanged, hasOwn, info, isArray, isExclude, isFalsy, isFunction, isHTMLElement, isMap, isNil, isObject, isPrimitive, isPromise, isSet, isString, isSymbol, isWeakMap, isWeakSet, kebabCase, noop, startsWith, warn };
@@ -0,0 +1,66 @@
1
+ declare const _toString: () => string;
2
+ declare const extend: {
3
+ <T extends {}, U>(target: T, source: U): T & U;
4
+ <T extends {}, U, V>(target: T, source1: U, source2: V): T & U & V;
5
+ <T extends {}, U, V, W>(target: T, source1: U, source2: V, source3: W): T & U & V & W;
6
+ (target: object, ...sources: any[]): any;
7
+ };
8
+ declare const hasOwn: (val: object, key: string | symbol) => key is keyof typeof val;
9
+ declare function coerceArray<T>(data: T | T[]): T[];
10
+ declare const hasChanged: (value: any, oldValue: any) => boolean;
11
+ declare const noop: () => void;
12
+ /**
13
+ * A function that checks if a string starts with a specific substring.
14
+ * indexOf faster under normal circumstances
15
+ * @see https://www.measurethat.net/Benchmarks/Show/12350/0/startswith-vs-test-vs-match-vs-indexof#latest_results_block
16
+
17
+ * @param {string} str - The input string to check.
18
+ * @param {string} searchString - The substring to check for at the beginning of the input string.
19
+ * @return {boolean} Returns true if the input string starts with the specified substring, otherwise false.
20
+ */
21
+ declare function startsWith(str: any, searchString: any): boolean;
22
+ /**
23
+ * Escapes special HTML characters in a string.
24
+ * @param str - The string to escape.
25
+ * @returns The escaped string.
26
+ */
27
+ declare function escape(str: string): string;
28
+ type ExcludeType = ((key: string | symbol) => boolean) | (string | symbol)[];
29
+ /**
30
+ * Checks if a key should be excluded based on the provided exclude criteria.
31
+ * @param key - The key to check.
32
+ * @param exclude - The exclusion criteria.
33
+ * @returns True if the key should be excluded, otherwise false.
34
+ */
35
+ declare function isExclude(key: string | symbol, exclude?: ExcludeType): boolean;
36
+
37
+ declare const isObject: (val: unknown) => val is Record<any, any>;
38
+ declare function isPromise(val: any): boolean;
39
+ declare const isArray: (arg: any) => arg is any[];
40
+ declare function isString(val: unknown): val is string;
41
+ declare function isSymbol(val: unknown): val is symbol;
42
+ declare function isSet(val: any): val is Set<any>;
43
+ declare function isWeakMap(val: any): val is WeakMap<any, any>;
44
+ declare function isWeakSet(val: any): val is WeakSet<any>;
45
+ declare function isMap(val: unknown): val is Map<any, any>;
46
+ declare function isNil(x: any): x is null | undefined;
47
+ declare const isFunction: (val: unknown) => val is Function;
48
+ declare function isFalsy(x: any): x is false | null | undefined;
49
+ declare const isPrimitive: (val: unknown) => val is string | number | boolean | symbol | null | undefined;
50
+ declare function isHTMLElement(obj: any): any;
51
+
52
+ declare const kebabCase: (string: string) => string;
53
+ declare const camelCase: (str: string) => string;
54
+ /**
55
+ * Capitalizes the first letter of a string.
56
+ *
57
+ * @param {string} inputString - The input string to capitalize the first letter.
58
+ * @return {string} The string with the first letter capitalized.
59
+ */
60
+ declare const capitalizeFirstLetter: (inputString: string) => string;
61
+
62
+ declare function warn(msg: string, ..._args: any[]): void;
63
+ declare function info(msg: string, ..._args: any[]): void;
64
+ declare function error(msg: string, ..._args: any[]): void;
65
+
66
+ export { type ExcludeType, _toString, camelCase, capitalizeFirstLetter, coerceArray, error, escape, extend, hasChanged, hasOwn, info, isArray, isExclude, isFalsy, isFunction, isHTMLElement, isMap, isNil, isObject, isPrimitive, isPromise, isSet, isString, isSymbol, isWeakMap, isWeakSet, kebabCase, noop, startsWith, warn };
@@ -0,0 +1,140 @@
1
+ /**
2
+ * @estjs/shared v0.0.10-beta.20
3
+ * (c) 2023-Present jiangxd <jiangxd2016@gmail.com>
4
+ * @license MIT
5
+ **/
6
+
7
+ // src/is.ts
8
+ var isObject = (val) => val !== null && typeof val === "object";
9
+ function isPromise(val) {
10
+ return _toString.call(val) === "[object Promise]";
11
+ }
12
+ var isArray = Array.isArray;
13
+ function isString(val) {
14
+ return typeof val === "string";
15
+ }
16
+ function isNull(val) {
17
+ return val === null;
18
+ }
19
+ function isSymbol(val) {
20
+ return typeof val === "symbol";
21
+ }
22
+ function isSet(val) {
23
+ return _toString.call(val) === "[object Set]";
24
+ }
25
+ function isWeakMap(val) {
26
+ return _toString.call(val) === "[object WeakMap]";
27
+ }
28
+ function isWeakSet(val) {
29
+ return _toString.call(val) === "[object WeakSet]";
30
+ }
31
+ function isMap(val) {
32
+ return _toString.call(val) === "[object Map]";
33
+ }
34
+ function isNil(x) {
35
+ return x === null || x === void 0;
36
+ }
37
+ var isFunction = (val) => typeof val === "function";
38
+ function isFalsy(x) {
39
+ return x === false || x === null || x === void 0;
40
+ }
41
+ var isPrimitive = (val) => ["string", "number", "boolean", "symbol", "undefined"].includes(typeof val) || isNull(val);
42
+ function isHTMLElement(obj) {
43
+ if (!obj) return false;
44
+ return obj && typeof obj === "object" && obj.nodeType === 1 && typeof obj.nodeName === "string";
45
+ }
46
+
47
+ // src/comm.ts
48
+ var _toString = Object.prototype.toString;
49
+ var extend = Object.assign;
50
+ var hasOwnProperty = Object.prototype.hasOwnProperty;
51
+ var hasOwn = (val, key) => hasOwnProperty.call(val, key);
52
+ function coerceArray(data) {
53
+ return Array.isArray(data) ? data.flat() : [data];
54
+ }
55
+ var hasChanged = (value, oldValue) => value !== oldValue && (value === value || oldValue === oldValue);
56
+ var noop = Function.prototype;
57
+ function startsWith(str, searchString) {
58
+ if (!isString(str)) {
59
+ return false;
60
+ }
61
+ return str.indexOf(searchString) === 0;
62
+ }
63
+ function escape(str) {
64
+ return str.replaceAll(/["&'<>]/g, (char) => {
65
+ switch (char) {
66
+ case "&":
67
+ return "&amp;";
68
+ case "<":
69
+ return "&lt;";
70
+ case ">":
71
+ return "&gt;";
72
+ case '"':
73
+ return "&quot;";
74
+ case "'":
75
+ return "&#039;";
76
+ default:
77
+ return char;
78
+ }
79
+ });
80
+ }
81
+ function isExclude(key, exclude) {
82
+ return Array.isArray(exclude) ? exclude.includes(key) : isFunction(exclude) ? exclude(key) : false;
83
+ }
84
+
85
+ // src/name.ts
86
+ var kebabCase = (string) => {
87
+ return string.replaceAll(/[A-Z]+/g, (match, offset) => {
88
+ return `${offset > 0 ? "-" : ""}${match.toLocaleLowerCase()}`;
89
+ });
90
+ };
91
+ var camelCase = (str) => {
92
+ const s = str.replaceAll(/[\s_-]+(.)?/g, (_, c) => c ? c.toUpperCase() : "");
93
+ return s[0].toLowerCase() + s.slice(1);
94
+ };
95
+ var capitalizeFirstLetter = (inputString) => {
96
+ return inputString.charAt(0).toUpperCase() + inputString.slice(1);
97
+ };
98
+
99
+ // src/console.ts
100
+ function warn(msg, ...args) {
101
+ console.warn.apply(console, [`[Essor warn]: ${msg}`].concat(args));
102
+ }
103
+ function info(msg, ...args) {
104
+ console.info.apply(console, [`[Essor info]: ${msg}`].concat(args));
105
+ }
106
+ function error(msg, ...args) {
107
+ console.error.apply(console, [`[Essor error]: ${msg}`].concat(args));
108
+ }
109
+ export {
110
+ _toString,
111
+ camelCase,
112
+ capitalizeFirstLetter,
113
+ coerceArray,
114
+ error,
115
+ escape,
116
+ extend,
117
+ hasChanged,
118
+ hasOwn,
119
+ info,
120
+ isArray,
121
+ isExclude,
122
+ isFalsy,
123
+ isFunction,
124
+ isHTMLElement,
125
+ isMap,
126
+ isNil,
127
+ isObject,
128
+ isPrimitive,
129
+ isPromise,
130
+ isSet,
131
+ isString,
132
+ isSymbol,
133
+ isWeakMap,
134
+ isWeakSet,
135
+ kebabCase,
136
+ noop,
137
+ startsWith,
138
+ warn
139
+ };
140
+ //# sourceMappingURL=essor-shared.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/is.ts","../src/comm.ts","../src/name.ts","../src/console.ts"],"sourcesContent":["import { _toString } from './comm';\n\nexport const isObject = (val: unknown): val is Record<any, any> =>\n val !== null && typeof val === 'object';\nexport function isPromise(val: any): boolean {\n return _toString.call(val) === '[object Promise]';\n}\n\nexport const isArray = Array.isArray;\n\nexport function isString(val: unknown): val is string {\n return typeof val === 'string';\n}\nexport function isNull(val: any): val is null {\n return val === null;\n}\nexport function isSymbol(val: unknown): val is symbol {\n return typeof val === 'symbol';\n}\n\nexport function isSet(val: any): val is Set<any> {\n return _toString.call(val) === '[object Set]';\n}\nexport function isWeakMap(val: any): val is WeakMap<any, any> {\n return _toString.call(val) === '[object WeakMap]';\n}\nexport function isWeakSet(val: any): val is WeakSet<any> {\n return _toString.call(val) === '[object WeakSet]';\n}\n\nexport function isMap(val: unknown): val is Map<any, any> {\n return _toString.call(val) === '[object Map]';\n}\nexport function isNil(x: any): x is null | undefined {\n return x === null || x === undefined;\n}\n\nexport const isFunction = (val: unknown): val is Function => typeof val === 'function';\n\nexport function isFalsy(x: any): x is false | null | undefined {\n return x === false || x === null || x === undefined;\n}\n\nexport const isPrimitive = (\n val: unknown,\n): val is string | number | boolean | symbol | null | undefined =>\n ['string', 'number', 'boolean', 'symbol', 'undefined'].includes(typeof val) || isNull(val);\n\nexport function isHTMLElement(obj) {\n if (!obj) return false;\n return obj && typeof obj === 'object' && obj.nodeType === 1 && typeof obj.nodeName === 'string';\n}\n","import { isFunction, isString } from './is';\n\nexport const _toString = Object.prototype.toString;\nexport const extend = Object.assign;\nconst hasOwnProperty = Object.prototype.hasOwnProperty;\nexport const hasOwn = (val: object, key: string | symbol): key is keyof typeof val =>\n hasOwnProperty.call(val, key);\n\nexport function coerceArray<T>(data: T | T[]): T[] {\n return Array.isArray(data) ? (data.flat() as T[]) : [data];\n}\nexport const hasChanged = (value, oldValue) =>\n value !== oldValue && (value === value || oldValue === oldValue);\nexport const noop = Function.prototype as () => void;\n\n/**\n * A function that checks if a string starts with a specific substring.\n * indexOf faster under normal circumstances\n * @see https://www.measurethat.net/Benchmarks/Show/12350/0/startswith-vs-test-vs-match-vs-indexof#latest_results_block\n\n * @param {string} str - The input string to check.\n * @param {string} searchString - The substring to check for at the beginning of the input string.\n * @return {boolean} Returns true if the input string starts with the specified substring, otherwise false.\n */\nexport function startsWith(str, searchString) {\n if (!isString(str)) {\n return false;\n }\n return str.indexOf(searchString) === 0;\n}\n\n/**\n * Escapes special HTML characters in a string.\n * @param str - The string to escape.\n * @returns The escaped string.\n */\nexport function escape(str: string): string {\n return str.replaceAll(/[\"&'<>]/g, char => {\n switch (char) {\n case '&':\n return '&amp;';\n case '<':\n return '&lt;';\n case '>':\n return '&gt;';\n case '\"':\n return '&quot;';\n case \"'\":\n return '&#039;';\n default:\n return char;\n }\n });\n}\n\nexport type ExcludeType = ((key: string | symbol) => boolean) | (string | symbol)[];\n\n/**\n * Checks if a key should be excluded based on the provided exclude criteria.\n * @param key - The key to check.\n * @param exclude - The exclusion criteria.\n * @returns True if the key should be excluded, otherwise false.\n */\nexport function isExclude(key: string | symbol, exclude?: ExcludeType): boolean {\n return Array.isArray(exclude)\n ? exclude.includes(key)\n : isFunction(exclude)\n ? exclude(key)\n : false;\n}\n","export const kebabCase = (string: string): string => {\n return string.replaceAll(/[A-Z]+/g, (match, offset) => {\n return `${offset > 0 ? '-' : ''}${match.toLocaleLowerCase()}`;\n });\n};\n\nexport const camelCase = (str: string): string => {\n const s = str.replaceAll(/[\\s_-]+(.)?/g, (_, c) => (c ? c.toUpperCase() : ''));\n return s[0].toLowerCase() + s.slice(1);\n};\n/**\n * Capitalizes the first letter of a string.\n *\n * @param {string} inputString - The input string to capitalize the first letter.\n * @return {string} The string with the first letter capitalized.\n */\nexport const capitalizeFirstLetter = (inputString: string): string => {\n return inputString.charAt(0).toUpperCase() + inputString.slice(1);\n};\n","export function warn(msg: string, ..._args: any[]): void;\nexport function warn(msg: string, ...args): void {\n // eslint-disable-next-line prefer-spread\n console.warn.apply(console, [`[Essor warn]: ${msg}`].concat(args) as [string, ...any[]]);\n}\n\nexport function info(msg: string, ..._args: any[]): void;\nexport function info(msg: string, ...args): void {\n // eslint-disable-next-line prefer-spread, no-console\n console.info.apply(console, [`[Essor info]: ${msg}`].concat(args) as [string, ...any[]]);\n}\n\nexport function error(msg: string, ..._args: any[]): void;\nexport function error(msg: string, ...args): void {\n // eslint-disable-next-line prefer-spread\n console.error.apply(console, [`[Essor error]: ${msg}`].concat(args) as [string, ...any[]]);\n}\n"],"mappings":";;;;;;;AAEO,IAAM,WAAW,CAAC,QACvB,QAAQ,QAAQ,OAAO,QAAQ;AAC1B,SAAS,UAAU,KAAmB;AAC3C,SAAO,UAAU,KAAK,GAAG,MAAM;AACjC;AAEO,IAAM,UAAU,MAAM;AAEtB,SAAS,SAAS,KAA6B;AACpD,SAAO,OAAO,QAAQ;AACxB;AACO,SAAS,OAAO,KAAuB;AAC5C,SAAO,QAAQ;AACjB;AACO,SAAS,SAAS,KAA6B;AACpD,SAAO,OAAO,QAAQ;AACxB;AAEO,SAAS,MAAM,KAA2B;AAC/C,SAAO,UAAU,KAAK,GAAG,MAAM;AACjC;AACO,SAAS,UAAU,KAAoC;AAC5D,SAAO,UAAU,KAAK,GAAG,MAAM;AACjC;AACO,SAAS,UAAU,KAA+B;AACvD,SAAO,UAAU,KAAK,GAAG,MAAM;AACjC;AAEO,SAAS,MAAM,KAAoC;AACxD,SAAO,UAAU,KAAK,GAAG,MAAM;AACjC;AACO,SAAS,MAAM,GAA+B;AACnD,SAAO,MAAM,QAAQ,MAAM;AAC7B;AAEO,IAAM,aAAa,CAAC,QAAkC,OAAO,QAAQ;AAErE,SAAS,QAAQ,GAAuC;AAC7D,SAAO,MAAM,SAAS,MAAM,QAAQ,MAAM;AAC5C;AAEO,IAAM,cAAc,CACzB,QAEA,CAAC,UAAU,UAAU,WAAW,UAAU,WAAW,EAAE,SAAS,OAAO,GAAG,KAAK,OAAO,GAAG;AAEpF,SAAS,cAAc,KAAK;AACjC,MAAI,CAAC,IAAK,QAAO;AACjB,SAAO,OAAO,OAAO,QAAQ,YAAY,IAAI,aAAa,KAAK,OAAO,IAAI,aAAa;AACzF;;;ACjDO,IAAM,YAAY,OAAO,UAAU;AACnC,IAAM,SAAS,OAAO;AAC7B,IAAM,iBAAiB,OAAO,UAAU;AACjC,IA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,YAAY,MAAM,CAAC;AAClE;;;ACjBO,SAAS,KAAK,QAAgB,MAAY;AAE/C,UAAQ,KAAK,MAAM,SAAS,CAAC,iBAAiB,GAAG,EAAE,EAAE,OAAO,IAAI,CAAuB;AACzF;AAGO,SAAS,KAAK,QAAgB,MAAY;AAE/C,UAAQ,KAAK,MAAM,SAAS,CAAC,iBAAiB,GAAG,EAAE,EAAE,OAAO,IAAI,CAAuB;AACzF;AAGO,SAAS,MAAM,QAAgB,MAAY;AAEhD,UAAQ,MAAM,MAAM,SAAS,CAAC,kBAAkB,GAAG,EAAE,EAAE,OAAO,IAAI,CAAuB;AAC3F;","names":[]}
package/package.json ADDED
@@ -0,0 +1,41 @@
1
+ {
2
+ "name": "@estjs/shared",
3
+ "version": "0.0.10-beta.21",
4
+ "description": "",
5
+ "type": "module",
6
+ "keywords": [],
7
+ "license": "MIT",
8
+ "homepage": "https://github.com/estjs/essor#readme",
9
+ "bugs": "https://github.com/estjs/essor/issues",
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "git+https://github.com/estjs/essor.git"
13
+ },
14
+ "author": "jiangxd <jiangxd2016@gmail.com>",
15
+ "funding": "https://github.com/sponsors/estjs",
16
+ "files": [
17
+ "dist"
18
+ ],
19
+ "main": "./dist/essor-shared.js",
20
+ "module": "./dist/essor-shared.js",
21
+ "types": "./dist/essor-shared.d.ts",
22
+ "exports": {
23
+ ".": {
24
+ "types": "./dist/essor-shared.d.ts",
25
+ "require": "./dist/essor-shared.cjs",
26
+ "import": "./dist/essor-shared.js"
27
+ }
28
+ },
29
+ "typesVersions": {
30
+ "*": {
31
+ "*": [
32
+ "./dist/essor-shared.d.ts"
33
+ ]
34
+ }
35
+ },
36
+ "sideEffects": false,
37
+ "scripts": {
38
+ "build": "tsup",
39
+ "dev": "tsup --watch"
40
+ }
41
+ }