@ts-utilities/core 1.0.6 → 1.0.7
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/README.md +15 -15
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +61 -1
- package/dist/index.d.ts +61 -1
- package/dist/index.js +1 -1
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
# @ts-
|
|
1
|
+
# @ts-collection/core
|
|
2
2
|
|
|
3
3
|

|
|
4
4
|

|
|
5
5
|

|
|
6
|
-

|
|
7
7
|
|
|
8
8
|
## Description
|
|
9
9
|
|
|
10
|
-
`@ts-
|
|
10
|
+
`@ts-collection/core` is a collection of core utility functions and advanced TypeScript types designed for JavaScript/TypeScript projects. It provides essential utilities for object manipulation, async operations, data transformation, and type-level programming. The library is built with TypeScript and is fully typed, ensuring a smooth and error-free development experience.
|
|
11
11
|
|
|
12
12
|
## Features
|
|
13
13
|
|
|
@@ -20,16 +20,16 @@
|
|
|
20
20
|
|
|
21
21
|
## Installation
|
|
22
22
|
|
|
23
|
-
You can install `@ts-
|
|
23
|
+
You can install `@ts-collection/core` using npm or yarn:
|
|
24
24
|
|
|
25
25
|
```bash
|
|
26
|
-
npm install @ts-
|
|
26
|
+
npm install @ts-collection/core
|
|
27
27
|
```
|
|
28
28
|
|
|
29
29
|
or
|
|
30
30
|
|
|
31
31
|
```bash
|
|
32
|
-
yarn add @ts-
|
|
32
|
+
yarn add @ts-collection/core
|
|
33
33
|
```
|
|
34
34
|
|
|
35
35
|
## Usage
|
|
@@ -39,9 +39,9 @@ yarn add @ts-utilities/core
|
|
|
39
39
|
You can import individual utilities or types as needed:
|
|
40
40
|
|
|
41
41
|
```typescript
|
|
42
|
-
import { deepmerge, poll, shield, sleep, debounce, throttle } from '@ts-
|
|
43
|
-
import { getObjectValue, extendProps, hydrate } from '@ts-
|
|
44
|
-
import type { DeepPartial, Primitive, KeysOfType } from '@ts-
|
|
42
|
+
import { deepmerge, poll, shield, sleep, debounce, throttle } from '@ts-collection/core';
|
|
43
|
+
import { getObjectValue, extendProps, hydrate } from '@ts-collection/core/functions';
|
|
44
|
+
import type { DeepPartial, Primitive, KeysOfType } from '@ts-collection/core/types';
|
|
45
45
|
```
|
|
46
46
|
|
|
47
47
|
### Examples
|
|
@@ -49,7 +49,7 @@ import type { DeepPartial, Primitive, KeysOfType } from '@ts-utilities/core/type
|
|
|
49
49
|
#### Object Utilities
|
|
50
50
|
|
|
51
51
|
```typescript
|
|
52
|
-
import { getObjectValue, extendProps } from '@ts-
|
|
52
|
+
import { getObjectValue, extendProps } from '@ts-collection/core';
|
|
53
53
|
|
|
54
54
|
const obj = { a: { b: { c: 1 } } };
|
|
55
55
|
const value = getObjectValue(obj, 'a.b.c'); // 1
|
|
@@ -60,7 +60,7 @@ const extended = extendProps({ a: 1 }, { b: 'hello' }); // { a: 1, b: 'hello' }
|
|
|
60
60
|
#### Data Transformation
|
|
61
61
|
|
|
62
62
|
```typescript
|
|
63
|
-
import { hydrate, deepmerge } from '@ts-
|
|
63
|
+
import { hydrate, deepmerge } from '@ts-collection/core';
|
|
64
64
|
|
|
65
65
|
const cleaned = hydrate({ a: null, b: { c: null } }); // { a: undefined, b: { c: undefined } }
|
|
66
66
|
|
|
@@ -95,7 +95,7 @@ const combined = deepmerge(
|
|
|
95
95
|
#### Async Operations
|
|
96
96
|
|
|
97
97
|
```typescript
|
|
98
|
-
import { poll, shield, sleep } from '@ts-
|
|
98
|
+
import { poll, shield, sleep } from '@ts-collection/core';
|
|
99
99
|
|
|
100
100
|
const result = await poll(async () => {
|
|
101
101
|
const status = await checkStatus();
|
|
@@ -108,7 +108,7 @@ const [error, data] = await shield(fetchData());
|
|
|
108
108
|
#### Debounce and Throttle
|
|
109
109
|
|
|
110
110
|
```typescript
|
|
111
|
-
import { debounce, throttle } from '@ts-
|
|
111
|
+
import { debounce, throttle } from '@ts-collection/core';
|
|
112
112
|
|
|
113
113
|
const debouncedFunction = debounce(() => console.log('Debounced!'), 300);
|
|
114
114
|
const throttledFunction = throttle(() => console.log('Throttled!'), 300);
|
|
@@ -117,7 +117,7 @@ const throttledFunction = throttle(() => console.log('Throttled!'), 300);
|
|
|
117
117
|
#### TypeScript Types
|
|
118
118
|
|
|
119
119
|
```typescript
|
|
120
|
-
import type { DeepPartial, Nullable, KeysOfType, Primitive } from '@ts-
|
|
120
|
+
import type { DeepPartial, Nullable, KeysOfType, Primitive } from '@ts-collection/core/types';
|
|
121
121
|
|
|
122
122
|
type PartialUser = DeepPartial<User>;
|
|
123
123
|
type NullableUser = Nullable<User>;
|
|
@@ -279,4 +279,4 @@ This project is licensed under the ISC License - see the [LICENSE](LICENSE) file
|
|
|
279
279
|
## Contact
|
|
280
280
|
|
|
281
281
|
- **Sohan Emon**: [sohanemon@outlook.com](mailto:sohanemon@outlook.com)
|
|
282
|
-
- **GitHub**: [
|
|
282
|
+
- **GitHub**: [ts-collection/core](https://github.com/ts-collection/core)
|
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
const e=e=>!e,t=e=>e==null,n=e=>{if(e==null)return!0;switch(typeof e){case`string`:case`number`:case`bigint`:case`boolean`:case`symbol`:return!0;default:return!1}};function
|
|
1
|
+
const e=e=>!e,t=e=>e==null,n=e=>typeof e==`boolean`,r=e=>typeof e==`string`,i=e=>typeof e==`number`,a=e=>Array.isArray(e),o=e=>typeof e==`function`,s=e=>{if(e==null)return!0;switch(typeof e){case`string`:case`number`:case`bigint`:case`boolean`:case`symbol`:return!0;default:return!1}};function c(e){if(typeof e!=`object`||!e||Object.prototype.toString.call(e)!==`[object Object]`)return!1;let t=Object.getPrototypeOf(e);return t===null||t===Object.prototype}function l(e,...t){let n,r={},i=t[t.length-1];i&&typeof i==`object`&&!Array.isArray(i)&&(i.arrayMerge!==void 0||i.clone!==void 0||i.customMerge!==void 0||i.functionMerge!==void 0||i.maxDepth!==void 0)?(r={...r,...i},n=t.slice(0,-1)):n=t;let{arrayMerge:a=`replace`,clone:o=!0,functionMerge:s=`replace`,maxDepth:l=100,customMerge:u}=r,d=new WeakMap;return f(e,n,0);function f(e,t,n){if(n>=l)return console.warn(`[deepmerge] Maximum depth ${l} exceeded. Returning target as-is.`),e;if(!c(e)&&!Array.isArray(e)){for(let n of t)if(n!==void 0){if(u){let t=u(``,e,n);if(t!==void 0)return t}return typeof e==`function`&&typeof n==`function`&&s===`compose`?(...t)=>{e(...t),n(...t)}:n}return e}let r=o?Array.isArray(e)?[...e]:{...e}:e;for(let e of t)if(e!=null&&!d.has(e))if(d.set(e,r),Array.isArray(r)&&Array.isArray(e))r=p(r,e,a);else if(c(r)&&c(e)){let t=new Set([...Object.keys(r),...Object.keys(e),...Object.getOwnPropertySymbols(r),...Object.getOwnPropertySymbols(e)]);for(let i of t){let t=r[i],o=e[i];u&&u(i,t,o)!==void 0?r[i]=u(i,t,o):typeof t==`function`&&typeof o==`function`?s===`compose`?r[i]=(...e)=>{t(...e),o(...e)}:r[i]=o:c(t)&&c(o)?r[i]=f(t,[o],n+1):Array.isArray(t)&&Array.isArray(o)?r[i]=p(t,o,a):o!==void 0&&(r[i]=o)}}else r=e;return r}function p(e,t,n){if(typeof n==`function`)return n(e,t);switch(n){case`concat`:return[...e,...t];case`merge`:let n=Math.max(e.length,t.length),r=[];for(let i=0;i<n;i++)i<e.length&&i<t.length?c(e[i])&&c(t[i])?r[i]=f(e[i],[t[i]],0):r[i]=t[i]:i<e.length?r[i]=e[i]:r[i]=t[i];return r;case`replace`:default:return[...t]}}}function u(e){return d(e)}function d(e){if(e!==null){if(typeof e!=`object`||!e)return e;if(Array.isArray(e))return e.map(d);if(c(e)){let t={};for(let n in e)t[n]=d(e[n]);return t}return e}}function f(e,t,n){if(typeof t!=`string`&&!Array.isArray(t))return n;let r=(()=>Array.isArray(t)?t:t===``?[]:String(t).split(`.`).filter(e=>e!==``))();if(!Array.isArray(r))return n;let i=e;for(let e of r){if(i==null)return n;let t=typeof e==`string`&&Array.isArray(i)&&/^\d+$/.test(e)?Number.parseInt(e,10):e;i=i[t]}return i===void 0?n:i}function p(e,t){return e==null?e:Object.assign(e,t)}function m(e){return(e.split(`.`).pop()||e).replace(/([a-z])([A-Z])/g,`$1 $2`).split(/[-_|�\s]+/).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(` `)}const h=`àáãäâèéëêìíïîòóöôùúüûñç·/_,:;`,g=`aaaaaeeeeiiiioooouuuunc------`,_=e=>{if(typeof e!=`string`)throw TypeError(`Input must be a string`);let t=e.trim().toLowerCase(),n={};for(let e=0;e<29;e++)n[h.charAt(e)]=`aaaaaeeeeiiiioooouuuunc------`.charAt(e);return t=t.replace(RegExp(`[${h}]`,`g`),e=>n[e]||e),t.replace(/[^a-z0-9 -]/g,``).replace(/\s+/g,`-`).replace(/-+/g,`-`).replace(/^-+/,``).replace(/-+$/,``)||``},v=(e=1e3,t)=>new Promise(n=>{if(t?.aborted)return n();let r=setTimeout(()=>{a(),n()},e);function i(){clearTimeout(r),a(),n()}function a(){t?.removeEventListener(`abort`,i)}t&&t.addEventListener(`abort`,i,{once:!0})});function y(e,t=100,n){if(typeof e!=`function`)throw TypeError(`Expected the first parameter to be a function, got \`${typeof e}\`.`);if(t<0)throw RangeError("`wait` must not be negative.");let r=n?.immediate??!1,i,a,o,s;function c(){return s=e.apply(o,a),a=void 0,o=void 0,s}let l=function(...e){return a=e,o=this,i===void 0&&r&&(s=c.call(this)),i!==void 0&&clearTimeout(i),i=setTimeout(c.bind(this),t),s};return Object.defineProperty(l,`isPending`,{get(){return i!==void 0}}),l}function b(e,t=100,n){if(typeof e!=`function`)throw TypeError(`Expected the first parameter to be a function, got \`${typeof e}\`.`);if(t<0)throw RangeError("`wait` must not be negative.");let r=n?.leading??!0,i=n?.trailing??!0,a,o,s,c,l;function u(){c=Date.now(),l=e.apply(s,o),o=void 0,s=void 0}function d(){a=void 0,i&&o&&u()}let f=function(...e){let n=c?Date.now()-c:1/0;return o=e,s=this,n>=t?r?u():a=setTimeout(d,t):!a&&i&&(a=setTimeout(d,t-n)),l};return Object.defineProperty(f,`isPending`,{get(){return a!==void 0}}),f}function x(e,...t){let n=t.length===1&&Array.isArray(t[0])?t[0]:t,r=0;return e.replace(/%s/g,()=>{let e=n[r++];return e===void 0?``:String(e)})}function S(e){return e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`)}function C(e,t={}){if(!e)return``;let{lowercase:n=!0,removeAccents:r=!0,removeNonAlphanumeric:i=!0}=t,a=e.normalize(`NFC`);return r&&(a=a.normalize(`NFD`).replace(/\p{M}/gu,``)),i&&(a=a.replace(/^[^\p{L}\p{N}]*|[^\p{L}\p{N}]*$/gu,``)),n&&(a=a.toLocaleLowerCase()),a}async function w(e,{interval:t=5e3,timeout:n=300*1e3,jitter:r=!0,signal:i}={}){let a=Date.now(),o=i?.aborted??!1,s=()=>{o=!0};i?.addEventListener(`abort`,s,{once:!0});try{for(let s=0;;s++){if(o)throw Error(`Polling aborted`);let s=await e();if(s)return s;if(Date.now()-a>=n)throw Error(`Polling timed out`,{cause:`Polling timed out after ${n}ms`});await v(r?t+(Math.random()-.5)*t*.2:t,i)}}catch(e){throw e}finally{i?.removeEventListener(`abort`,s)}}function T(e,t={}){let{retry:n=0,delay:r=0}=t,i=Date.now(),a=async t=>{try{await e();let t=Date.now()-i;console.log(`⚡[schedule.ts] Completed in ${t}ms`)}catch(e){if(console.log(`⚡[schedule.ts] err:`,e),t>0)console.log(`⚡[schedule.ts] Retrying in ${r}ms...`),setTimeout(()=>a(t-1),r);else{let e=Date.now()-i;console.log(`⚡[schedule.ts] Failed after ${e}ms`)}}};setTimeout(()=>a(n),0)}function E(e){if(e instanceof Promise)return e.then(e=>[null,e]).catch(e=>[e,null]);try{return[null,e()]}catch(t){return console.log(`\x1b[31m🛡 [shield]\x1b[0m ${e.name} failed →`,t),[t,null]}}exports.convertToNormalCase=m,exports.convertToSlug=_,exports.debounce=y,exports.deepmerge=l,exports.escapeRegExp=S,exports.extendProps=p,exports.getObjectValue=f,exports.hydrate=u,exports.isArray=a,exports.isBoolean=n,exports.isFalsy=e,exports.isFunction=o,exports.isNullish=t,exports.isNumber=i,exports.isPlainObject=c,exports.isPrimitive=s,exports.isString=r,exports.normalizeText=C,exports.poll=w,exports.printf=x,exports.schedule=T,exports.shield=E,exports.sleep=v,exports.throttle=b;
|
package/dist/index.d.cts
CHANGED
|
@@ -1260,6 +1260,66 @@ declare const isFalsy: (val: unknown) => val is Falsy;
|
|
|
1260
1260
|
* }
|
|
1261
1261
|
*/
|
|
1262
1262
|
declare const isNullish: (val: unknown) => val is null | undefined;
|
|
1263
|
+
/**
|
|
1264
|
+
* Type guard that checks if a value is a boolean.
|
|
1265
|
+
*
|
|
1266
|
+
* @param val - The value to check
|
|
1267
|
+
* @returns True if the value is a boolean, false otherwise
|
|
1268
|
+
*
|
|
1269
|
+
* @example
|
|
1270
|
+
* if (isBoolean(value)) {
|
|
1271
|
+
* console.log('Value is a boolean');
|
|
1272
|
+
* }
|
|
1273
|
+
*/
|
|
1274
|
+
declare const isBoolean: (val: unknown) => val is boolean;
|
|
1275
|
+
/**
|
|
1276
|
+
* Type guard that checks if a value is a string.
|
|
1277
|
+
*
|
|
1278
|
+
* @param val - The value to check
|
|
1279
|
+
* @returns True if the value is a string, false otherwise
|
|
1280
|
+
*
|
|
1281
|
+
* @example
|
|
1282
|
+
* if (isString(value)) {
|
|
1283
|
+
* console.log('Value is a string');
|
|
1284
|
+
* }
|
|
1285
|
+
*/
|
|
1286
|
+
declare const isString: (val: unknown) => val is string;
|
|
1287
|
+
/**
|
|
1288
|
+
* Type guard that checks if a value is a number.
|
|
1289
|
+
*
|
|
1290
|
+
* @param val - The value to check
|
|
1291
|
+
* @returns True if the value is a number, false otherwise
|
|
1292
|
+
*
|
|
1293
|
+
* @example
|
|
1294
|
+
* if (isNumber(value)) {
|
|
1295
|
+
* console.log('Value is a number');
|
|
1296
|
+
* }
|
|
1297
|
+
*/
|
|
1298
|
+
declare const isNumber: (val: unknown) => val is number;
|
|
1299
|
+
/**
|
|
1300
|
+
* Type guard that checks if a value is an array.
|
|
1301
|
+
*
|
|
1302
|
+
* @param val - The value to check
|
|
1303
|
+
* @returns True if the value is an array, false otherwise
|
|
1304
|
+
*
|
|
1305
|
+
* @example
|
|
1306
|
+
* if (isArray(value)) {
|
|
1307
|
+
* console.log('Value is an array');
|
|
1308
|
+
* }
|
|
1309
|
+
*/
|
|
1310
|
+
declare const isArray: (val: unknown) => val is unknown[];
|
|
1311
|
+
/**
|
|
1312
|
+
* Type guard that checks if a value is a function.
|
|
1313
|
+
*
|
|
1314
|
+
* @param val - The value to check
|
|
1315
|
+
* @returns True if the value is a function, false otherwise
|
|
1316
|
+
*
|
|
1317
|
+
* @example
|
|
1318
|
+
* if (isFunction(value)) {
|
|
1319
|
+
* console.log('Value is a function');
|
|
1320
|
+
* }
|
|
1321
|
+
*/
|
|
1322
|
+
declare const isFunction: (val: unknown) => val is Function;
|
|
1263
1323
|
/**
|
|
1264
1324
|
* Type guard that checks if a value is a primitive type.
|
|
1265
1325
|
*
|
|
@@ -1285,4 +1345,4 @@ declare const isPrimitive: (val: unknown) => val is Primitive;
|
|
|
1285
1345
|
*/
|
|
1286
1346
|
declare function isPlainObject(value: unknown): value is Record<string, any>;
|
|
1287
1347
|
//#endregion
|
|
1288
|
-
export { AND, AllOrNone, BUFFER, DeepMergeOptions, DeepPartial, DeepReadonly, DeepRequired, Diff, Falsy, IMPLIES, Intersection, Keys, KeysOfType, Maybe, Merge, Mutable, NAND, NOR, NOT, NestedKeyOf, Never, Nullable, Nullish, OR, OmitByType, OneOf, Optional, Prettify, Primitive, RequiredKeys, ScheduleOpts, SelectivePartial, SelectiveRequired, Substract, Task, TwoOf, Values, Without, XNOR, XNOR_Binary, XOR, XOR_Binary, convertToNormalCase, convertToSlug, debounce, deepmerge, escapeRegExp, extendProps, getObjectValue, hydrate, isFalsy, isNullish, isPlainObject, isPrimitive, normalizeText, poll, printf, schedule, shield, sleep, throttle };
|
|
1348
|
+
export { AND, AllOrNone, BUFFER, DeepMergeOptions, DeepPartial, DeepReadonly, DeepRequired, Diff, Falsy, IMPLIES, Intersection, Keys, KeysOfType, Maybe, Merge, Mutable, NAND, NOR, NOT, NestedKeyOf, Never, Nullable, Nullish, OR, OmitByType, OneOf, Optional, Prettify, Primitive, RequiredKeys, ScheduleOpts, SelectivePartial, SelectiveRequired, Substract, Task, TwoOf, Values, Without, XNOR, XNOR_Binary, XOR, XOR_Binary, convertToNormalCase, convertToSlug, debounce, deepmerge, escapeRegExp, extendProps, getObjectValue, hydrate, isArray, isBoolean, isFalsy, isFunction, isNullish, isNumber, isPlainObject, isPrimitive, isString, normalizeText, poll, printf, schedule, shield, sleep, throttle };
|
package/dist/index.d.ts
CHANGED
|
@@ -1260,6 +1260,66 @@ declare const isFalsy: (val: unknown) => val is Falsy;
|
|
|
1260
1260
|
* }
|
|
1261
1261
|
*/
|
|
1262
1262
|
declare const isNullish: (val: unknown) => val is null | undefined;
|
|
1263
|
+
/**
|
|
1264
|
+
* Type guard that checks if a value is a boolean.
|
|
1265
|
+
*
|
|
1266
|
+
* @param val - The value to check
|
|
1267
|
+
* @returns True if the value is a boolean, false otherwise
|
|
1268
|
+
*
|
|
1269
|
+
* @example
|
|
1270
|
+
* if (isBoolean(value)) {
|
|
1271
|
+
* console.log('Value is a boolean');
|
|
1272
|
+
* }
|
|
1273
|
+
*/
|
|
1274
|
+
declare const isBoolean: (val: unknown) => val is boolean;
|
|
1275
|
+
/**
|
|
1276
|
+
* Type guard that checks if a value is a string.
|
|
1277
|
+
*
|
|
1278
|
+
* @param val - The value to check
|
|
1279
|
+
* @returns True if the value is a string, false otherwise
|
|
1280
|
+
*
|
|
1281
|
+
* @example
|
|
1282
|
+
* if (isString(value)) {
|
|
1283
|
+
* console.log('Value is a string');
|
|
1284
|
+
* }
|
|
1285
|
+
*/
|
|
1286
|
+
declare const isString: (val: unknown) => val is string;
|
|
1287
|
+
/**
|
|
1288
|
+
* Type guard that checks if a value is a number.
|
|
1289
|
+
*
|
|
1290
|
+
* @param val - The value to check
|
|
1291
|
+
* @returns True if the value is a number, false otherwise
|
|
1292
|
+
*
|
|
1293
|
+
* @example
|
|
1294
|
+
* if (isNumber(value)) {
|
|
1295
|
+
* console.log('Value is a number');
|
|
1296
|
+
* }
|
|
1297
|
+
*/
|
|
1298
|
+
declare const isNumber: (val: unknown) => val is number;
|
|
1299
|
+
/**
|
|
1300
|
+
* Type guard that checks if a value is an array.
|
|
1301
|
+
*
|
|
1302
|
+
* @param val - The value to check
|
|
1303
|
+
* @returns True if the value is an array, false otherwise
|
|
1304
|
+
*
|
|
1305
|
+
* @example
|
|
1306
|
+
* if (isArray(value)) {
|
|
1307
|
+
* console.log('Value is an array');
|
|
1308
|
+
* }
|
|
1309
|
+
*/
|
|
1310
|
+
declare const isArray: (val: unknown) => val is unknown[];
|
|
1311
|
+
/**
|
|
1312
|
+
* Type guard that checks if a value is a function.
|
|
1313
|
+
*
|
|
1314
|
+
* @param val - The value to check
|
|
1315
|
+
* @returns True if the value is a function, false otherwise
|
|
1316
|
+
*
|
|
1317
|
+
* @example
|
|
1318
|
+
* if (isFunction(value)) {
|
|
1319
|
+
* console.log('Value is a function');
|
|
1320
|
+
* }
|
|
1321
|
+
*/
|
|
1322
|
+
declare const isFunction: (val: unknown) => val is Function;
|
|
1263
1323
|
/**
|
|
1264
1324
|
* Type guard that checks if a value is a primitive type.
|
|
1265
1325
|
*
|
|
@@ -1285,4 +1345,4 @@ declare const isPrimitive: (val: unknown) => val is Primitive;
|
|
|
1285
1345
|
*/
|
|
1286
1346
|
declare function isPlainObject(value: unknown): value is Record<string, any>;
|
|
1287
1347
|
//#endregion
|
|
1288
|
-
export { AND, AllOrNone, BUFFER, DeepMergeOptions, DeepPartial, DeepReadonly, DeepRequired, Diff, Falsy, IMPLIES, Intersection, Keys, KeysOfType, Maybe, Merge, Mutable, NAND, NOR, NOT, NestedKeyOf, Never, Nullable, Nullish, OR, OmitByType, OneOf, Optional, Prettify, Primitive, RequiredKeys, ScheduleOpts, SelectivePartial, SelectiveRequired, Substract, Task, TwoOf, Values, Without, XNOR, XNOR_Binary, XOR, XOR_Binary, convertToNormalCase, convertToSlug, debounce, deepmerge, escapeRegExp, extendProps, getObjectValue, hydrate, isFalsy, isNullish, isPlainObject, isPrimitive, normalizeText, poll, printf, schedule, shield, sleep, throttle };
|
|
1348
|
+
export { AND, AllOrNone, BUFFER, DeepMergeOptions, DeepPartial, DeepReadonly, DeepRequired, Diff, Falsy, IMPLIES, Intersection, Keys, KeysOfType, Maybe, Merge, Mutable, NAND, NOR, NOT, NestedKeyOf, Never, Nullable, Nullish, OR, OmitByType, OneOf, Optional, Prettify, Primitive, RequiredKeys, ScheduleOpts, SelectivePartial, SelectiveRequired, Substract, Task, TwoOf, Values, Without, XNOR, XNOR_Binary, XOR, XOR_Binary, convertToNormalCase, convertToSlug, debounce, deepmerge, escapeRegExp, extendProps, getObjectValue, hydrate, isArray, isBoolean, isFalsy, isFunction, isNullish, isNumber, isPlainObject, isPrimitive, isString, normalizeText, poll, printf, schedule, shield, sleep, throttle };
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
const e=e=>!e,t=e=>e==null,n=e=>{if(e==null)return!0;switch(typeof e){case`string`:case`number`:case`bigint`:case`boolean`:case`symbol`:return!0;default:return!1}};function
|
|
1
|
+
const e=e=>!e,t=e=>e==null,n=e=>typeof e==`boolean`,r=e=>typeof e==`string`,i=e=>typeof e==`number`,a=e=>Array.isArray(e),o=e=>typeof e==`function`,s=e=>{if(e==null)return!0;switch(typeof e){case`string`:case`number`:case`bigint`:case`boolean`:case`symbol`:return!0;default:return!1}};function c(e){if(typeof e!=`object`||!e||Object.prototype.toString.call(e)!==`[object Object]`)return!1;let t=Object.getPrototypeOf(e);return t===null||t===Object.prototype}function l(e,...t){let n,r={},i=t[t.length-1];i&&typeof i==`object`&&!Array.isArray(i)&&(i.arrayMerge!==void 0||i.clone!==void 0||i.customMerge!==void 0||i.functionMerge!==void 0||i.maxDepth!==void 0)?(r={...r,...i},n=t.slice(0,-1)):n=t;let{arrayMerge:a=`replace`,clone:o=!0,functionMerge:s=`replace`,maxDepth:l=100,customMerge:u}=r,d=new WeakMap;return f(e,n,0);function f(e,t,n){if(n>=l)return console.warn(`[deepmerge] Maximum depth ${l} exceeded. Returning target as-is.`),e;if(!c(e)&&!Array.isArray(e)){for(let n of t)if(n!==void 0){if(u){let t=u(``,e,n);if(t!==void 0)return t}return typeof e==`function`&&typeof n==`function`&&s===`compose`?(...t)=>{e(...t),n(...t)}:n}return e}let r=o?Array.isArray(e)?[...e]:{...e}:e;for(let e of t)if(e!=null&&!d.has(e))if(d.set(e,r),Array.isArray(r)&&Array.isArray(e))r=p(r,e,a);else if(c(r)&&c(e)){let t=new Set([...Object.keys(r),...Object.keys(e),...Object.getOwnPropertySymbols(r),...Object.getOwnPropertySymbols(e)]);for(let i of t){let t=r[i],o=e[i];u&&u(i,t,o)!==void 0?r[i]=u(i,t,o):typeof t==`function`&&typeof o==`function`?s===`compose`?r[i]=(...e)=>{t(...e),o(...e)}:r[i]=o:c(t)&&c(o)?r[i]=f(t,[o],n+1):Array.isArray(t)&&Array.isArray(o)?r[i]=p(t,o,a):o!==void 0&&(r[i]=o)}}else r=e;return r}function p(e,t,n){if(typeof n==`function`)return n(e,t);switch(n){case`concat`:return[...e,...t];case`merge`:let n=Math.max(e.length,t.length),r=[];for(let i=0;i<n;i++)i<e.length&&i<t.length?c(e[i])&&c(t[i])?r[i]=f(e[i],[t[i]],0):r[i]=t[i]:i<e.length?r[i]=e[i]:r[i]=t[i];return r;case`replace`:default:return[...t]}}}function u(e){return d(e)}function d(e){if(e!==null){if(typeof e!=`object`||!e)return e;if(Array.isArray(e))return e.map(d);if(c(e)){let t={};for(let n in e)t[n]=d(e[n]);return t}return e}}function f(e,t,n){if(typeof t!=`string`&&!Array.isArray(t))return n;let r=(()=>Array.isArray(t)?t:t===``?[]:String(t).split(`.`).filter(e=>e!==``))();if(!Array.isArray(r))return n;let i=e;for(let e of r){if(i==null)return n;let t=typeof e==`string`&&Array.isArray(i)&&/^\d+$/.test(e)?Number.parseInt(e,10):e;i=i[t]}return i===void 0?n:i}function p(e,t){return e==null?e:Object.assign(e,t)}function m(e){return(e.split(`.`).pop()||e).replace(/([a-z])([A-Z])/g,`$1 $2`).split(/[-_|�\s]+/).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(` `)}const h=`àáãäâèéëêìíïîòóöôùúüûñç·/_,:;`,g=e=>{if(typeof e!=`string`)throw TypeError(`Input must be a string`);let t=e.trim().toLowerCase(),n={};for(let e=0;e<29;e++)n[h.charAt(e)]=`aaaaaeeeeiiiioooouuuunc------`.charAt(e);return t=t.replace(RegExp(`[${h}]`,`g`),e=>n[e]||e),t.replace(/[^a-z0-9 -]/g,``).replace(/\s+/g,`-`).replace(/-+/g,`-`).replace(/^-+/,``).replace(/-+$/,``)||``},_=(e=1e3,t)=>new Promise(n=>{if(t?.aborted)return n();let r=setTimeout(()=>{a(),n()},e);function i(){clearTimeout(r),a(),n()}function a(){t?.removeEventListener(`abort`,i)}t&&t.addEventListener(`abort`,i,{once:!0})});function v(e,t=100,n){if(typeof e!=`function`)throw TypeError(`Expected the first parameter to be a function, got \`${typeof e}\`.`);if(t<0)throw RangeError("`wait` must not be negative.");let r=n?.immediate??!1,i,a,o,s;function c(){return s=e.apply(o,a),a=void 0,o=void 0,s}let l=function(...e){return a=e,o=this,i===void 0&&r&&(s=c.call(this)),i!==void 0&&clearTimeout(i),i=setTimeout(c.bind(this),t),s};return Object.defineProperty(l,`isPending`,{get(){return i!==void 0}}),l}function y(e,t=100,n){if(typeof e!=`function`)throw TypeError(`Expected the first parameter to be a function, got \`${typeof e}\`.`);if(t<0)throw RangeError("`wait` must not be negative.");let r=n?.leading??!0,i=n?.trailing??!0,a,o,s,c,l;function u(){c=Date.now(),l=e.apply(s,o),o=void 0,s=void 0}function d(){a=void 0,i&&o&&u()}let f=function(...e){let n=c?Date.now()-c:1/0;return o=e,s=this,n>=t?r?u():a=setTimeout(d,t):!a&&i&&(a=setTimeout(d,t-n)),l};return Object.defineProperty(f,`isPending`,{get(){return a!==void 0}}),f}function b(e,...t){let n=t.length===1&&Array.isArray(t[0])?t[0]:t,r=0;return e.replace(/%s/g,()=>{let e=n[r++];return e===void 0?``:String(e)})}function x(e){return e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`)}function S(e,t={}){if(!e)return``;let{lowercase:n=!0,removeAccents:r=!0,removeNonAlphanumeric:i=!0}=t,a=e.normalize(`NFC`);return r&&(a=a.normalize(`NFD`).replace(/\p{M}/gu,``)),i&&(a=a.replace(/^[^\p{L}\p{N}]*|[^\p{L}\p{N}]*$/gu,``)),n&&(a=a.toLocaleLowerCase()),a}async function C(e,{interval:t=5e3,timeout:n=300*1e3,jitter:r=!0,signal:i}={}){let a=Date.now(),o=i?.aborted??!1,s=()=>{o=!0};i?.addEventListener(`abort`,s,{once:!0});try{for(let s=0;;s++){if(o)throw Error(`Polling aborted`);let s=await e();if(s)return s;if(Date.now()-a>=n)throw Error(`Polling timed out`,{cause:`Polling timed out after ${n}ms`});await _(r?t+(Math.random()-.5)*t*.2:t,i)}}catch(e){throw e}finally{i?.removeEventListener(`abort`,s)}}function w(e,t={}){let{retry:n=0,delay:r=0}=t,i=Date.now(),a=async t=>{try{await e();let t=Date.now()-i;console.log(`⚡[schedule.ts] Completed in ${t}ms`)}catch(e){if(console.log(`⚡[schedule.ts] err:`,e),t>0)console.log(`⚡[schedule.ts] Retrying in ${r}ms...`),setTimeout(()=>a(t-1),r);else{let e=Date.now()-i;console.log(`⚡[schedule.ts] Failed after ${e}ms`)}}};setTimeout(()=>a(n),0)}function T(e){if(e instanceof Promise)return e.then(e=>[null,e]).catch(e=>[e,null]);try{return[null,e()]}catch(t){return console.log(`\x1b[31m🛡 [shield]\x1b[0m ${e.name} failed →`,t),[t,null]}}export{m as convertToNormalCase,g as convertToSlug,v as debounce,l as deepmerge,x as escapeRegExp,p as extendProps,f as getObjectValue,u as hydrate,a as isArray,n as isBoolean,e as isFalsy,o as isFunction,t as isNullish,i as isNumber,c as isPlainObject,s as isPrimitive,r as isString,S as normalizeText,C as poll,b as printf,w as schedule,T as shield,_ as sleep,y as throttle};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ts-utilities/core",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.7",
|
|
4
4
|
"author": "Sohan Emon <sohanemon@outlook.com>",
|
|
5
5
|
"description": "Core utilities for JavaScript/TypeScript projects",
|
|
6
6
|
"type": "module",
|
|
@@ -50,10 +50,10 @@
|
|
|
50
50
|
"homepage": "https://sohanjs.web.app/core",
|
|
51
51
|
"repository": {
|
|
52
52
|
"type": "git",
|
|
53
|
-
"url": "git+https://github.com/
|
|
53
|
+
"url": "git+https://github.com/ts-collection/core.git"
|
|
54
54
|
},
|
|
55
55
|
"bugs": {
|
|
56
|
-
"url": "https://github.com/
|
|
56
|
+
"url": "https://github.com/ts-collection/core/issues"
|
|
57
57
|
},
|
|
58
58
|
"devDependencies": {
|
|
59
59
|
"@biomejs/biome": "2.3.8",
|