@sanity/util 5.0.0-next.0-9b570ece82-202507150640 → 5.0.0-next.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/LICENSE +1 -1
- package/lib/client.js +9 -8
- package/lib/client.js.map +1 -1
- package/lib/concurrency-limiter.js +3 -3
- package/lib/concurrency-limiter.js.map +1 -1
- package/lib/content.js +11 -15
- package/lib/content.js.map +1 -1
- package/lib/{createSafeJsonParser.mjs → createSafeJsonParser.cjs} +5 -5
- package/lib/{createSafeJsonParser.mjs.map → createSafeJsonParser.cjs.map} +1 -1
- package/lib/createSafeJsonParser.js +4 -4
- package/lib/createSafeJsonParser.js.map +1 -1
- package/lib/fs.js +13 -15
- package/lib/fs.js.map +1 -1
- package/lib/index.js +1 -1
- package/lib/legacyDateFormat.js +160 -78
- package/lib/legacyDateFormat.js.map +1 -1
- package/lib/paths.js +25 -25
- package/lib/paths.js.map +1 -1
- package/package.json +18 -30
- package/lib/client.d.mts +0 -12
- package/lib/client.mjs +0 -64
- package/lib/client.mjs.map +0 -1
- package/lib/concurrency-limiter.d.mts +0 -22
- package/lib/concurrency-limiter.mjs +0 -32
- package/lib/concurrency-limiter.mjs.map +0 -1
- package/lib/content.d.mts +0 -39
- package/lib/content.mjs +0 -89
- package/lib/content.mjs.map +0 -1
- package/lib/fs.d.mts +0 -7
- package/lib/fs.mjs +0 -31
- package/lib/fs.mjs.map +0 -1
- package/lib/index.d.mts +0 -1
- package/lib/index.mjs +0 -2
- package/lib/index.mjs.map +0 -1
- package/lib/legacyDateFormat.d.mts +0 -39
- package/lib/legacyDateFormat.mjs +0 -213
- package/lib/legacyDateFormat.mjs.map +0 -1
- package/lib/paths.d.mts +0 -53
- package/lib/paths.mjs +0 -153
- package/lib/paths.mjs.map +0 -1
- /package/lib/{createSafeJsonParser.d.mts → createSafeJsonParser.d.cts} +0 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sanity/util",
|
|
3
|
-
"version": "5.0.0-next.
|
|
3
|
+
"version": "5.0.0-next.7+eaffcdec86",
|
|
4
4
|
"description": "Utilities shared across projects of Sanity",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"sanity",
|
|
@@ -22,60 +22,44 @@
|
|
|
22
22
|
"license": "MIT",
|
|
23
23
|
"author": "Sanity.io <hello@sanity.io>",
|
|
24
24
|
"sideEffects": false,
|
|
25
|
-
"type": "
|
|
25
|
+
"type": "module",
|
|
26
26
|
"exports": {
|
|
27
27
|
".": {
|
|
28
28
|
"source": "./src/_exports/index.ts",
|
|
29
|
-
"import": "./lib/index.mjs",
|
|
30
|
-
"require": "./lib/index.js",
|
|
31
29
|
"default": "./lib/index.js"
|
|
32
30
|
},
|
|
33
31
|
"./fs": {
|
|
34
32
|
"source": "./src/_exports/fs.ts",
|
|
35
|
-
"import": "./lib/fs.mjs",
|
|
36
|
-
"require": "./lib/fs.js",
|
|
37
33
|
"default": "./lib/fs.js"
|
|
38
34
|
},
|
|
39
35
|
"./client": {
|
|
40
36
|
"source": "./src/_exports/client.ts",
|
|
41
|
-
"import": "./lib/client.mjs",
|
|
42
|
-
"require": "./lib/client.js",
|
|
43
37
|
"default": "./lib/client.js"
|
|
44
38
|
},
|
|
45
39
|
"./concurrency-limiter": {
|
|
46
40
|
"source": "./src/_exports/concurrency-limiter.ts",
|
|
47
|
-
"import": "./lib/concurrency-limiter.mjs",
|
|
48
|
-
"require": "./lib/concurrency-limiter.js",
|
|
49
41
|
"default": "./lib/concurrency-limiter.js"
|
|
50
42
|
},
|
|
51
43
|
"./content": {
|
|
52
44
|
"source": "./src/_exports/content.ts",
|
|
53
|
-
"import": "./lib/content.mjs",
|
|
54
|
-
"require": "./lib/content.js",
|
|
55
45
|
"default": "./lib/content.js"
|
|
56
46
|
},
|
|
57
47
|
"./createSafeJsonParser": {
|
|
58
48
|
"source": "./src/_exports/createSafeJsonParser.ts",
|
|
59
|
-
"
|
|
60
|
-
"require": "./lib/createSafeJsonParser.js",
|
|
49
|
+
"require": "./lib/createSafeJsonParser.cjs",
|
|
61
50
|
"default": "./lib/createSafeJsonParser.js"
|
|
62
51
|
},
|
|
63
52
|
"./legacyDateFormat": {
|
|
64
53
|
"source": "./src/_exports/legacyDateFormat.ts",
|
|
65
|
-
"import": "./lib/legacyDateFormat.mjs",
|
|
66
|
-
"require": "./lib/legacyDateFormat.js",
|
|
67
54
|
"default": "./lib/legacyDateFormat.js"
|
|
68
55
|
},
|
|
69
56
|
"./paths": {
|
|
70
57
|
"source": "./src/_exports/paths.ts",
|
|
71
|
-
"import": "./lib/paths.mjs",
|
|
72
|
-
"require": "./lib/paths.js",
|
|
73
58
|
"default": "./lib/paths.js"
|
|
74
59
|
},
|
|
75
60
|
"./package.json": "./package.json"
|
|
76
61
|
},
|
|
77
62
|
"main": "./lib/index.js",
|
|
78
|
-
"module": "./lib/index.mjs",
|
|
79
63
|
"types": "./lib/index.d.ts",
|
|
80
64
|
"typesVersions": {
|
|
81
65
|
"*": {
|
|
@@ -106,27 +90,31 @@
|
|
|
106
90
|
"lib"
|
|
107
91
|
],
|
|
108
92
|
"dependencies": {
|
|
109
|
-
"@date-fns/tz": "^1.
|
|
110
|
-
"@date-fns/utc": "^2.1.
|
|
111
|
-
"@sanity/client": "^7.
|
|
93
|
+
"@date-fns/tz": "^1.4.1",
|
|
94
|
+
"@date-fns/utc": "^2.1.1",
|
|
95
|
+
"@sanity/client": "^7.13.2",
|
|
112
96
|
"date-fns": "^4.1.0",
|
|
113
|
-
"get-random-values-esm": "1.0.2",
|
|
114
97
|
"rxjs": "^7.8.2",
|
|
115
|
-
"@sanity/types": "5.0.0-next.
|
|
98
|
+
"@sanity/types": "5.0.0-next.7+eaffcdec86"
|
|
116
99
|
},
|
|
117
100
|
"devDependencies": {
|
|
101
|
+
"@sanity/pkg-utils": "^10.2.1",
|
|
102
|
+
"@types/node": "^24.3.0",
|
|
103
|
+
"@typescript/native-preview": "7.0.0-dev.20251128.1",
|
|
104
|
+
"eslint": "^9.39.1",
|
|
118
105
|
"rimraf": "^5.0.10",
|
|
119
|
-
"vitest": "^3.2.
|
|
120
|
-
"@repo/
|
|
121
|
-
"@repo/
|
|
122
|
-
"@repo/eslint-config": "5.0.0-next.
|
|
106
|
+
"vitest": "^3.2.4",
|
|
107
|
+
"@repo/package.config": "5.0.0-next.7+eaffcdec86",
|
|
108
|
+
"@repo/test-config": "5.0.0-next.7+eaffcdec86",
|
|
109
|
+
"@repo/eslint-config": "5.0.0-next.7+eaffcdec86",
|
|
110
|
+
"@repo/tsconfig": "5.0.0-next.7+eaffcdec86"
|
|
123
111
|
},
|
|
124
112
|
"engines": {
|
|
125
|
-
"node": ">=20.19"
|
|
113
|
+
"node": ">=20.19 <22 || >=22.12"
|
|
126
114
|
},
|
|
127
115
|
"scripts": {
|
|
128
116
|
"build": "pnpm clean && pkg-utils build --strict --check --clean",
|
|
129
|
-
"check:types": "(cd ../../.. &&
|
|
117
|
+
"check:types": "(cd ../../.. && tsgo --project packages/@sanity/util/tsconfig.lib.json --erasableSyntaxOnly)",
|
|
130
118
|
"clean": "rimraf client.js concurrency-limiter.js content.js createSafeJsonParser.js fs.js legacyDateFormat.js lib paths.js",
|
|
131
119
|
"lint": "eslint .",
|
|
132
120
|
"test": "vitest run",
|
package/lib/client.d.mts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import {SanityClient} from '@sanity/client'
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Decorates a sanity client to limit the concurrency of `client.fetch`
|
|
5
|
-
* requests. Keeps the concurrency limit state and returns wrapped clients with
|
|
6
|
-
* that same state if the `clone` `config` or `withConfig` methods are called.
|
|
7
|
-
*/
|
|
8
|
-
export declare function createClientConcurrencyLimiter(
|
|
9
|
-
maxConcurrency: number,
|
|
10
|
-
): (input: SanityClient) => SanityClient
|
|
11
|
-
|
|
12
|
-
export {}
|
package/lib/client.mjs
DELETED
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import { from, switchMap, finalize } from "rxjs";
|
|
2
|
-
import { ConcurrencyLimiter } from "./concurrency-limiter.mjs";
|
|
3
|
-
function createClientConcurrencyLimiter(maxConcurrency) {
|
|
4
|
-
const limiter = new ConcurrencyLimiter(maxConcurrency);
|
|
5
|
-
function wrapClient(client) {
|
|
6
|
-
return new Proxy(client, {
|
|
7
|
-
get: (target, property) => {
|
|
8
|
-
switch (property) {
|
|
9
|
-
case "fetch":
|
|
10
|
-
return async (...args) => {
|
|
11
|
-
await limiter.ready();
|
|
12
|
-
try {
|
|
13
|
-
return await target.fetch(...args);
|
|
14
|
-
} finally {
|
|
15
|
-
limiter.release();
|
|
16
|
-
}
|
|
17
|
-
};
|
|
18
|
-
case "clone":
|
|
19
|
-
return (...args) => wrapClient(target.clone(...args));
|
|
20
|
-
case "config":
|
|
21
|
-
return (...args) => {
|
|
22
|
-
const result = target.config(...args);
|
|
23
|
-
return args[0] ? wrapClient(result) : result;
|
|
24
|
-
};
|
|
25
|
-
case "withConfig":
|
|
26
|
-
return (...args) => wrapClient(target.withConfig(...args));
|
|
27
|
-
case "observable":
|
|
28
|
-
return wrapObservableClient(target.observable);
|
|
29
|
-
default:
|
|
30
|
-
return target[property];
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
|
-
function wrapObservableClient(observableSanityClient) {
|
|
36
|
-
return new Proxy(observableSanityClient, {
|
|
37
|
-
get: (target, property) => {
|
|
38
|
-
switch (property) {
|
|
39
|
-
case "fetch":
|
|
40
|
-
return (...args) => from(limiter.ready()).pipe(
|
|
41
|
-
switchMap(() => target.fetch(...args)),
|
|
42
|
-
finalize(() => limiter.release())
|
|
43
|
-
);
|
|
44
|
-
case "clone":
|
|
45
|
-
return (...args) => wrapObservableClient(target.clone(...args));
|
|
46
|
-
case "config":
|
|
47
|
-
return (...args) => {
|
|
48
|
-
const result = target.config(...args);
|
|
49
|
-
return args[0] ? wrapObservableClient(result) : result;
|
|
50
|
-
};
|
|
51
|
-
case "withConfig":
|
|
52
|
-
return (...args) => wrapObservableClient(target.withConfig(...args));
|
|
53
|
-
default:
|
|
54
|
-
return target[property];
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
return wrapClient;
|
|
60
|
-
}
|
|
61
|
-
export {
|
|
62
|
-
createClientConcurrencyLimiter
|
|
63
|
-
};
|
|
64
|
-
//# sourceMappingURL=client.mjs.map
|
package/lib/client.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"client.mjs","sources":["../src/client/concurrency-limiter/createClientConcurrencyLimiter.ts"],"sourcesContent":["import {type ObservableSanityClient, type SanityClient} from '@sanity/client'\nimport {finalize, from, switchMap} from 'rxjs'\n\nimport {ConcurrencyLimiter} from '../../concurrency-limiter'\n\n/**\n * Decorates a sanity client to limit the concurrency of `client.fetch`\n * requests. Keeps the concurrency limit state and returns wrapped clients with\n * that same state if the `clone` `config` or `withConfig` methods are called.\n */\nexport function createClientConcurrencyLimiter(\n maxConcurrency: number,\n): (input: SanityClient) => SanityClient {\n const limiter = new ConcurrencyLimiter(maxConcurrency)\n\n function wrapClient(client: SanityClient): SanityClient {\n return new Proxy(client, {\n get: (target, property) => {\n switch (property) {\n case 'fetch': {\n return async (...args: Parameters<SanityClient['fetch']>) => {\n await limiter.ready()\n try {\n // note we want to await before we return so the finally block\n // will run after the promise has been fulfilled or rejected\n return await target.fetch(...args)\n } finally {\n limiter.release()\n }\n }\n }\n case 'clone': {\n return (...args: Parameters<SanityClient['clone']>) => {\n return wrapClient(target.clone(...args))\n }\n }\n case 'config': {\n return (...args: Parameters<SanityClient['config']>) => {\n const result = target.config(...args)\n\n // if there is a config, it returns a client so we need to wrap again\n if (args[0]) return wrapClient(result)\n return result\n }\n }\n case 'withConfig': {\n return (...args: Parameters<SanityClient['withConfig']>) => {\n return wrapClient(target.withConfig(...args))\n }\n }\n case 'observable': {\n return wrapObservableClient(target.observable)\n }\n default: {\n return target[property as keyof SanityClient]\n }\n }\n },\n })\n }\n\n function wrapObservableClient(\n observableSanityClient: ObservableSanityClient,\n ): ObservableSanityClient {\n return new Proxy(observableSanityClient, {\n get: (target, property) => {\n switch (property) {\n case 'fetch': {\n return (...args: Parameters<ObservableSanityClient['fetch']>) =>\n from(limiter.ready()).pipe(\n switchMap(() => target.fetch(...args)),\n finalize(() => limiter.release()),\n )\n }\n case 'clone': {\n return (...args: Parameters<ObservableSanityClient['clone']>) => {\n return wrapObservableClient(target.clone(...args))\n }\n }\n case 'config': {\n return (...args: Parameters<ObservableSanityClient['config']>) => {\n const result = target.config(...args)\n\n // if there is a config, it returns a client so we need to wrap again\n if (args[0]) return wrapObservableClient(result)\n return result\n }\n }\n case 'withConfig': {\n return (...args: Parameters<ObservableSanityClient['withConfig']>) => {\n return wrapObservableClient(target.withConfig(...args))\n }\n }\n default: {\n return target[property as keyof ObservableSanityClient]\n }\n }\n },\n })\n }\n\n return wrapClient\n}\n"],"names":[],"mappings":";;AAUO,SAAS,+BACd,gBACuC;AACjC,QAAA,UAAU,IAAI,mBAAmB,cAAc;AAErD,WAAS,WAAW,QAAoC;AAC/C,WAAA,IAAI,MAAM,QAAQ;AAAA,MACvB,KAAK,CAAC,QAAQ,aAAa;AACzB,gBAAQ,UAAU;AAAA,UAChB,KAAK;AACH,mBAAO,UAAU,SAA4C;AAC3D,oBAAM,QAAQ,MAAM;AAChB,kBAAA;AAGF,uBAAO,MAAM,OAAO,MAAM,GAAG,IAAI;AAAA,cAAA,UACjC;AACA,wBAAQ,QAAQ;AAAA,cAAA;AAAA,YAEpB;AAAA,UAEF,KAAK;AACH,mBAAO,IAAI,SACF,WAAW,OAAO,MAAM,GAAG,IAAI,CAAC;AAAA,UAG3C,KAAK;AACH,mBAAO,IAAI,SAA6C;AACtD,oBAAM,SAAS,OAAO,OAAO,GAAG,IAAI;AAGpC,qBAAI,KAAK,CAAC,IAAU,WAAW,MAAM,IAC9B;AAAA,YACT;AAAA,UAEF,KAAK;AACH,mBAAO,IAAI,SACF,WAAW,OAAO,WAAW,GAAG,IAAI,CAAC;AAAA,UAGhD,KAAK;AACI,mBAAA,qBAAqB,OAAO,UAAU;AAAA,UAE/C;AACE,mBAAO,OAAO,QAA8B;AAAA,QAAA;AAAA,MAEhD;AAAA,IACF,CACD;AAAA,EAAA;AAGH,WAAS,qBACP,wBACwB;AACjB,WAAA,IAAI,MAAM,wBAAwB;AAAA,MACvC,KAAK,CAAC,QAAQ,aAAa;AACzB,gBAAQ,UAAU;AAAA,UAChB,KAAK;AACH,mBAAO,IAAI,SACT,KAAK,QAAQ,MAAO,CAAA,EAAE;AAAA,cACpB,UAAU,MAAM,OAAO,MAAM,GAAG,IAAI,CAAC;AAAA,cACrC,SAAS,MAAM,QAAQ,QAAS,CAAA;AAAA,YAClC;AAAA,UAEJ,KAAK;AACH,mBAAO,IAAI,SACF,qBAAqB,OAAO,MAAM,GAAG,IAAI,CAAC;AAAA,UAGrD,KAAK;AACH,mBAAO,IAAI,SAAuD;AAChE,oBAAM,SAAS,OAAO,OAAO,GAAG,IAAI;AAGpC,qBAAI,KAAK,CAAC,IAAU,qBAAqB,MAAM,IACxC;AAAA,YACT;AAAA,UAEF,KAAK;AACH,mBAAO,IAAI,SACF,qBAAqB,OAAO,WAAW,GAAG,IAAI,CAAC;AAAA,UAG1D;AACE,mBAAO,OAAO,QAAwC;AAAA,QAAA;AAAA,MAE1D;AAAA,IACF,CACD;AAAA,EAAA;AAGI,SAAA;AACT;"}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* ConcurrencyLimiter manages the number of concurrent operations that can be performed.
|
|
3
|
-
* It ensures that the number of operations does not exceed a specified maximum limit.
|
|
4
|
-
*/
|
|
5
|
-
export declare class ConcurrencyLimiter {
|
|
6
|
-
current: number
|
|
7
|
-
resolvers: Array<() => void>
|
|
8
|
-
max: number
|
|
9
|
-
constructor(max: number)
|
|
10
|
-
/**
|
|
11
|
-
* Indicates when a slot for a new operation is ready.
|
|
12
|
-
* If under the limit, it resolves immediately; otherwise, it waits until a slot is free.
|
|
13
|
-
*/
|
|
14
|
-
ready: () => Promise<void>
|
|
15
|
-
/**
|
|
16
|
-
* Releases a slot, decrementing the current count of operations if nothing is in the queue.
|
|
17
|
-
* If there are operations waiting, it allows the next one in the queue to proceed.
|
|
18
|
-
*/
|
|
19
|
-
release: () => void
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export {}
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
class ConcurrencyLimiter {
|
|
2
|
-
current = 0;
|
|
3
|
-
resolvers = [];
|
|
4
|
-
max;
|
|
5
|
-
constructor(max) {
|
|
6
|
-
this.max = max;
|
|
7
|
-
}
|
|
8
|
-
/**
|
|
9
|
-
* Indicates when a slot for a new operation is ready.
|
|
10
|
-
* If under the limit, it resolves immediately; otherwise, it waits until a slot is free.
|
|
11
|
-
*/
|
|
12
|
-
ready = () => this.max === 1 / 0 ? Promise.resolve() : this.current < this.max ? (this.current++, Promise.resolve()) : new Promise((resolve) => {
|
|
13
|
-
this.resolvers.push(resolve);
|
|
14
|
-
});
|
|
15
|
-
/**
|
|
16
|
-
* Releases a slot, decrementing the current count of operations if nothing is in the queue.
|
|
17
|
-
* If there are operations waiting, it allows the next one in the queue to proceed.
|
|
18
|
-
*/
|
|
19
|
-
release = () => {
|
|
20
|
-
if (this.max === 1 / 0) return;
|
|
21
|
-
const nextResolver = this.resolvers.shift();
|
|
22
|
-
if (nextResolver) {
|
|
23
|
-
nextResolver();
|
|
24
|
-
return;
|
|
25
|
-
}
|
|
26
|
-
this.current = Math.max(0, this.current - 1);
|
|
27
|
-
};
|
|
28
|
-
}
|
|
29
|
-
export {
|
|
30
|
-
ConcurrencyLimiter
|
|
31
|
-
};
|
|
32
|
-
//# sourceMappingURL=concurrency-limiter.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"concurrency-limiter.mjs","sources":["../src/concurrency-limiter.ts"],"sourcesContent":["/**\n * ConcurrencyLimiter manages the number of concurrent operations that can be performed.\n * It ensures that the number of operations does not exceed a specified maximum limit.\n */\nexport class ConcurrencyLimiter {\n current = 0\n resolvers: Array<() => void> = []\n public max: number\n constructor(max: number) {\n this.max = max\n }\n\n /**\n * Indicates when a slot for a new operation is ready.\n * If under the limit, it resolves immediately; otherwise, it waits until a slot is free.\n */\n ready = (): Promise<void> => {\n if (this.max === Infinity) return Promise.resolve()\n\n if (this.current < this.max) {\n this.current++\n return Promise.resolve()\n }\n\n return new Promise<void>((resolve) => {\n this.resolvers.push(resolve)\n })\n }\n\n /**\n * Releases a slot, decrementing the current count of operations if nothing is in the queue.\n * If there are operations waiting, it allows the next one in the queue to proceed.\n */\n release = (): void => {\n if (this.max === Infinity) return\n\n const nextResolver = this.resolvers.shift()\n if (nextResolver) {\n nextResolver()\n return\n }\n\n this.current = Math.max(0, this.current - 1)\n }\n}\n"],"names":[],"mappings":"AAIO,MAAM,mBAAmB;AAAA,EAC9B,UAAU;AAAA,EACV,YAA+B,CAAC;AAAA,EACzB;AAAA,EACP,YAAY,KAAa;AACvB,SAAK,MAAM;AAAA,EAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOb,QAAQ,MACF,KAAK,QAAQ,QAAiB,QAAQ,YAEtC,KAAK,UAAU,KAAK,OACtB,KAAK,WACE,QAAQ,aAGV,IAAI,QAAc,CAAC,YAAY;AAC/B,SAAA,UAAU,KAAK,OAAO;AAAA,EAAA,CAC5B;AAAA;AAAA;AAAA;AAAA;AAAA,EAOH,UAAU,MAAY;AAChB,QAAA,KAAK,QAAQ,MAAU;AAErB,UAAA,eAAe,KAAK,UAAU,MAAM;AAC1C,QAAI,cAAc;AACH,mBAAA;AACb;AAAA,IAAA;AAGF,SAAK,UAAU,KAAK,IAAI,GAAG,KAAK,UAAU,CAAC;AAAA,EAC7C;AACF;"}
|
package/lib/content.d.mts
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Looks at the value and determines if it is deeply empty while not considering _type and _key attributes on objects.
|
|
3
|
-
* A value will be considered deeply empty if it is:
|
|
4
|
-
* - undefined or null
|
|
5
|
-
* - an object where all property values are deeply empty
|
|
6
|
-
* - an array where all items are deeply empty
|
|
7
|
-
* @param value - the value to check for deep emptiness
|
|
8
|
-
*/
|
|
9
|
-
export declare function isDeepEmpty(value: unknown): boolean
|
|
10
|
-
|
|
11
|
-
declare function isDeepEmptyArray(value: unknown[]): boolean
|
|
12
|
-
|
|
13
|
-
declare function isDeepEmptyObject(value: {[key: string]: any}): boolean
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* @deprecated Use `isDeepEmpty` instead
|
|
17
|
-
* todo: remove in v4
|
|
18
|
-
*/
|
|
19
|
-
export declare const isEmpty: typeof isDeepEmpty
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* @deprecated Use `isDeepEmpty` instead
|
|
23
|
-
* todo: remove in v4
|
|
24
|
-
*/
|
|
25
|
-
export declare const isEmptyArray: typeof isDeepEmptyArray
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* @deprecated Use `isDeepEmpty` instead
|
|
29
|
-
* todo: remove in v4
|
|
30
|
-
*/
|
|
31
|
-
export declare const isEmptyObject: typeof isDeepEmptyObject
|
|
32
|
-
|
|
33
|
-
export declare function isShallowEmptyObject(value: {[key: string]: unknown}): boolean
|
|
34
|
-
|
|
35
|
-
export declare function randomKey(length?: number): string
|
|
36
|
-
|
|
37
|
-
export declare function resolveTypeName(value: unknown): string
|
|
38
|
-
|
|
39
|
-
export {}
|
package/lib/content.mjs
DELETED
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
import getRandomValues from "get-random-values-esm";
|
|
2
|
-
var hasOwn = Object.prototype.hasOwnProperty.call.bind(Object.prototype.hasOwnProperty);
|
|
3
|
-
function isDeepEmptyObject(value) {
|
|
4
|
-
for (const key in value)
|
|
5
|
-
if (!(key === "_type" || key === "_key") && hasOwn(value, key) && !isDeepEmpty(value[key]))
|
|
6
|
-
return !1;
|
|
7
|
-
return !0;
|
|
8
|
-
}
|
|
9
|
-
function isDeepEmptyArray(value) {
|
|
10
|
-
for (let i = 0; i < value.length; i++)
|
|
11
|
-
if (!isDeepEmpty(value[i]))
|
|
12
|
-
return !1;
|
|
13
|
-
return !0;
|
|
14
|
-
}
|
|
15
|
-
function isDeepEmpty(value) {
|
|
16
|
-
if (value == null)
|
|
17
|
-
return !0;
|
|
18
|
-
const type = typeof value;
|
|
19
|
-
return Array.isArray(value) ? isDeepEmptyArray(value) : type === "object" ? isDeepEmptyObject(value) : !1;
|
|
20
|
-
}
|
|
21
|
-
const isEmptyArray = isDeepEmptyArray, isEmpty = isDeepEmpty, isEmptyObject = isDeepEmptyObject;
|
|
22
|
-
function isShallowEmptyObject(value) {
|
|
23
|
-
for (const key in value)
|
|
24
|
-
if (!(key === "_type" || key === "_key") && hasOwn(value, key) && value[key] !== void 0)
|
|
25
|
-
return !1;
|
|
26
|
-
return !0;
|
|
27
|
-
}
|
|
28
|
-
const getByteHexTable = /* @__PURE__ */ (() => {
|
|
29
|
-
let table;
|
|
30
|
-
return () => {
|
|
31
|
-
if (table)
|
|
32
|
-
return table;
|
|
33
|
-
table = [];
|
|
34
|
-
for (let i = 0; i < 256; ++i)
|
|
35
|
-
table[i] = (i + 256).toString(16).slice(1);
|
|
36
|
-
return table;
|
|
37
|
-
};
|
|
38
|
-
})();
|
|
39
|
-
function whatwgRNG(length = 16) {
|
|
40
|
-
const rnds8 = new Uint8Array(length);
|
|
41
|
-
return getRandomValues(rnds8), rnds8;
|
|
42
|
-
}
|
|
43
|
-
function randomKey(length) {
|
|
44
|
-
const table = getByteHexTable();
|
|
45
|
-
return whatwgRNG(length).reduce((str, n) => str + table[n], "").slice(0, length);
|
|
46
|
-
}
|
|
47
|
-
const toString = Object.prototype.toString;
|
|
48
|
-
function resolveJSType(val) {
|
|
49
|
-
switch (toString.call(val)) {
|
|
50
|
-
case "[object Function]":
|
|
51
|
-
return "function";
|
|
52
|
-
case "[object Date]":
|
|
53
|
-
return "date";
|
|
54
|
-
case "[object RegExp]":
|
|
55
|
-
return "regexp";
|
|
56
|
-
case "[object Arguments]":
|
|
57
|
-
return "arguments";
|
|
58
|
-
case "[object Array]":
|
|
59
|
-
return "array";
|
|
60
|
-
case "[object String]":
|
|
61
|
-
return "string";
|
|
62
|
-
}
|
|
63
|
-
if (typeof val == "object" && val && typeof val.length == "number")
|
|
64
|
-
try {
|
|
65
|
-
if (typeof val.callee == "function")
|
|
66
|
-
return "arguments";
|
|
67
|
-
} catch (ex) {
|
|
68
|
-
if (ex instanceof TypeError)
|
|
69
|
-
return "arguments";
|
|
70
|
-
}
|
|
71
|
-
return val === null ? "null" : val === void 0 ? "undefined" : val && val.nodeType === 1 ? "element" : val === Object(val) ? "object" : typeof val;
|
|
72
|
-
}
|
|
73
|
-
function resolveTypeName(value) {
|
|
74
|
-
const jsType = resolveJSType(value);
|
|
75
|
-
if (jsType !== "object")
|
|
76
|
-
return jsType;
|
|
77
|
-
const obj = value;
|
|
78
|
-
return "_type" in obj && obj._type || jsType;
|
|
79
|
-
}
|
|
80
|
-
export {
|
|
81
|
-
isDeepEmpty,
|
|
82
|
-
isEmpty,
|
|
83
|
-
isEmptyArray,
|
|
84
|
-
isEmptyObject,
|
|
85
|
-
isShallowEmptyObject,
|
|
86
|
-
randomKey,
|
|
87
|
-
resolveTypeName
|
|
88
|
-
};
|
|
89
|
-
//# sourceMappingURL=content.mjs.map
|
package/lib/content.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"content.mjs","sources":["../src/content/hasOwn.ts","../src/content/isDeepEmpty.ts","../src/content/isShallowEmptyObject.ts","../src/content/randomKey.ts","../src/content/resolveJSType.ts","../src/content/resolveTypeName.ts"],"sourcesContent":["export default Object.prototype.hasOwnProperty.call.bind(Object.prototype.hasOwnProperty)\n","import hasOwn from './hasOwn'\n\nfunction isDeepEmptyObject(value: {[key: string]: any}): boolean {\n for (const key in value) {\n if (key === '_type' || key === '_key') {\n continue\n }\n if (hasOwn(value, key) && !isDeepEmpty(value[key])) {\n return false\n }\n }\n return true\n}\n\nfunction isDeepEmptyArray(value: unknown[]): boolean {\n for (let i = 0; i < value.length; i++) {\n if (!isDeepEmpty(value[i])) {\n return false\n }\n }\n return true\n}\n\n/**\n * Looks at the value and determines if it is deeply empty while not considering _type and _key attributes on objects.\n * A value will be considered deeply empty if it is:\n * - undefined or null\n * - an object where all property values are deeply empty\n * - an array where all items are deeply empty\n * @param value - the value to check for deep emptiness\n */\nexport function isDeepEmpty(value: unknown): boolean {\n if (value === undefined || value === null) {\n return true\n }\n const type = typeof value\n\n if (Array.isArray(value)) {\n return isDeepEmptyArray(value)\n }\n if (type === 'object') {\n return isDeepEmptyObject(value)\n }\n return false\n}\n\n/**\n * @deprecated Use `isDeepEmpty` instead\n * todo: remove in v4\n */\nexport const isEmptyArray = isDeepEmptyArray\n\n/**\n * @deprecated Use `isDeepEmpty` instead\n * todo: remove in v4\n */\nexport const isEmpty = isDeepEmpty\n\n/**\n * @deprecated Use `isDeepEmpty` instead\n * todo: remove in v4\n */\nexport const isEmptyObject = isDeepEmptyObject\n","import hasOwn from './hasOwn'\n\nexport function isShallowEmptyObject(value: {[key: string]: unknown}): boolean {\n for (const key in value) {\n if (key === '_type' || key === '_key') {\n continue\n }\n if (hasOwn(value, key) && value[key] !== undefined) {\n return false\n }\n }\n return true\n}\n","import getRandomValues from 'get-random-values-esm'\n\nconst getByteHexTable = (() => {\n let table: any[]\n return () => {\n if (table) {\n return table\n }\n\n table = []\n for (let i = 0; i < 256; ++i) {\n table[i] = (i + 0x100).toString(16).slice(1)\n }\n return table\n }\n})()\n\n// WHATWG crypto RNG - https://w3c.github.io/webcrypto/Overview.html\nfunction whatwgRNG(length = 16) {\n const rnds8 = new Uint8Array(length)\n getRandomValues(rnds8)\n return rnds8\n}\n\nexport function randomKey(length?: number): string {\n const table = getByteHexTable()\n return whatwgRNG(length)\n .reduce((str, n) => str + table[n], '')\n .slice(0, length)\n}\n","const toString = Object.prototype.toString\n// Copied from https://github.com/ForbesLindesay/type-of, but inlined to have fine grained control\n\nexport function resolveJSType(val: unknown) {\n switch (toString.call(val)) {\n case '[object Function]':\n return 'function'\n case '[object Date]':\n return 'date'\n case '[object RegExp]':\n return 'regexp'\n case '[object Arguments]':\n return 'arguments'\n case '[object Array]':\n return 'array'\n case '[object String]':\n return 'string'\n default:\n }\n\n if (typeof val == 'object' && val && typeof (val as any).length == 'number') {\n try {\n if (typeof (val as any).callee == 'function') {\n return 'arguments'\n }\n } catch (ex) {\n if (ex instanceof TypeError) {\n return 'arguments'\n }\n }\n }\n\n if (val === null) {\n return 'null'\n }\n\n if (val === undefined) {\n return 'undefined'\n }\n\n if (val && (val as any).nodeType === 1) {\n return 'element'\n }\n\n if (val === Object(val)) {\n return 'object'\n }\n\n return typeof val\n}\n","import {resolveJSType} from './resolveJSType'\n\nexport function resolveTypeName(value: unknown): string {\n const jsType = resolveJSType(value)\n if (jsType !== 'object') {\n return jsType\n }\n\n const obj = value as Record<string, unknown> & {_type?: string}\n return ('_type' in obj && obj._type) || jsType\n}\n"],"names":[],"mappings":";AAAA,IAAA,SAAe,OAAO,UAAU,eAAe,KAAK,KAAK,OAAO,UAAU,cAAc;ACExF,SAAS,kBAAkB,OAAsC;AAC/D,aAAW,OAAO;AAChB,QAAI,EAAQ,QAAA,WAAW,QAAQ,WAG3B,OAAO,OAAO,GAAG,KAAK,CAAC,YAAY,MAAM,GAAG,CAAC;AACxC,aAAA;AAGJ,SAAA;AACT;AAEA,SAAS,iBAAiB,OAA2B;AACnD,WAAS,IAAI,GAAG,IAAI,MAAM,QAAQ;AAChC,QAAI,CAAC,YAAY,MAAM,CAAC,CAAC;AAChB,aAAA;AAGJ,SAAA;AACT;AAUO,SAAS,YAAY,OAAyB;AACnD,MAA2B,SAAU;AAC5B,WAAA;AAET,QAAM,OAAO,OAAO;AAEhB,SAAA,MAAM,QAAQ,KAAK,IACd,iBAAiB,KAAK,IAE3B,SAAS,WACJ,kBAAkB,KAAK,IAEzB;AACT;AAMO,MAAM,eAAe,kBAMf,UAAU,aAMV,gBAAgB;AC5DtB,SAAS,qBAAqB,OAA0C;AAC7E,aAAW,OAAO;AACZ,QAAA,EAAA,QAAQ,WAAW,QAAQ,WAG3B,OAAO,OAAO,GAAG,KAAK,MAAM,GAAG,MAAM;AAChC,aAAA;AAGJ,SAAA;AACT;ACVA,MAAM,kBAAyB,uBAAA;AACzB,MAAA;AACJ,SAAO,MAAM;AACP,QAAA;AACK,aAAA;AAGT,YAAQ,CAAC;AACT,aAAS,IAAI,GAAG,IAAI,KAAK,EAAE;AACnB,YAAA,CAAC,KAAK,IAAI,KAAO,SAAS,EAAE,EAAE,MAAM,CAAC;AAEtC,WAAA;AAAA,EACT;AACF,GAAG;AAGH,SAAS,UAAU,SAAS,IAAI;AACxB,QAAA,QAAQ,IAAI,WAAW,MAAM;AACnC,SAAA,gBAAgB,KAAK,GACd;AACT;AAEO,SAAS,UAAU,QAAyB;AACjD,QAAM,QAAQ,gBAAgB;AAC9B,SAAO,UAAU,MAAM,EACpB,OAAO,CAAC,KAAK,MAAM,MAAM,MAAM,CAAC,GAAG,EAAE,EACrC,MAAM,GAAG,MAAM;AACpB;AC7BA,MAAM,WAAW,OAAO,UAAU;AAG3B,SAAS,cAAc,KAAc;AAClC,UAAA,SAAS,KAAK,GAAG,GAAG;AAAA,IAC1B,KAAK;AACI,aAAA;AAAA,IACT,KAAK;AACI,aAAA;AAAA,IACT,KAAK;AACI,aAAA;AAAA,IACT,KAAK;AACI,aAAA;AAAA,IACT,KAAK;AACI,aAAA;AAAA,IACT,KAAK;AACI,aAAA;AAAA,EACT;AAGF,MAAI,OAAO,OAAO,YAAY,OAAO,OAAQ,IAAY,UAAU;AAC7D,QAAA;AACE,UAAA,OAAQ,IAAY,UAAU;AACzB,eAAA;AAAA,aAEF,IAAI;AACX,UAAI,cAAc;AACT,eAAA;AAAA,IAAA;AAKb,SAAI,QAAQ,OACH,SAGL,QAAQ,SACH,cAGL,OAAQ,IAAY,aAAa,IAC5B,YAGL,QAAQ,OAAO,GAAG,IACb,WAGF,OAAO;AAChB;AC/CO,SAAS,gBAAgB,OAAwB;AAChD,QAAA,SAAS,cAAc,KAAK;AAClC,MAAI,WAAW;AACN,WAAA;AAGT,QAAM,MAAM;AACJ,SAAA,WAAW,OAAO,IAAI,SAAU;AAC1C;"}
|
package/lib/fs.d.mts
DELETED
package/lib/fs.mjs
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import fs from "node:fs/promises";
|
|
2
|
-
import os from "node:os";
|
|
3
|
-
import path from "node:path";
|
|
4
|
-
async function pathIsEmpty(dir) {
|
|
5
|
-
try {
|
|
6
|
-
return (await fs.readdir(absolutify(dir))).length === 0;
|
|
7
|
-
} catch (err) {
|
|
8
|
-
if (err.code === "ENOENT")
|
|
9
|
-
return !0;
|
|
10
|
-
throw err;
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
function expandHome(filePath) {
|
|
14
|
-
if (filePath.charCodeAt(0) === 126) {
|
|
15
|
-
if (filePath.charCodeAt(1) === 43)
|
|
16
|
-
return path.join(process.cwd(), filePath.slice(2));
|
|
17
|
-
const home = os.homedir();
|
|
18
|
-
return home ? path.join(home, filePath.slice(1)) : filePath;
|
|
19
|
-
}
|
|
20
|
-
return filePath;
|
|
21
|
-
}
|
|
22
|
-
function absolutify(dir) {
|
|
23
|
-
const pathName = expandHome(dir);
|
|
24
|
-
return path.isAbsolute(pathName) ? pathName : path.resolve(process.cwd(), pathName);
|
|
25
|
-
}
|
|
26
|
-
export {
|
|
27
|
-
absolutify,
|
|
28
|
-
expandHome,
|
|
29
|
-
pathIsEmpty
|
|
30
|
-
};
|
|
31
|
-
//# sourceMappingURL=fs.mjs.map
|
package/lib/fs.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"fs.mjs","sources":["../src/fsTools.ts"],"sourcesContent":["import fs from 'node:fs/promises'\nimport os from 'node:os'\nimport path from 'node:path'\n\nexport async function pathIsEmpty(dir: string): Promise<boolean> {\n try {\n const content = await fs.readdir(absolutify(dir))\n return content.length === 0\n } catch (err) {\n if (err.code === 'ENOENT') {\n return true\n }\n\n throw err\n }\n}\n\nexport function expandHome(filePath: string): string {\n if (\n filePath.charCodeAt(0) === 126\n /* ~ */\n ) {\n if (\n filePath.charCodeAt(1) === 43\n /* + */\n ) {\n return path.join(process.cwd(), filePath.slice(2))\n }\n\n const home = os.homedir()\n return home ? path.join(home, filePath.slice(1)) : filePath\n }\n\n return filePath\n}\n\nexport function absolutify(dir: string): string {\n const pathName = expandHome(dir)\n return path.isAbsolute(pathName) ? pathName : path.resolve(process.cwd(), pathName)\n}\n"],"names":[],"mappings":";;;AAIA,eAAsB,YAAY,KAA+B;AAC3D,MAAA;AAEF,YADgB,MAAM,GAAG,QAAQ,WAAW,GAAG,CAAC,GACjC,WAAW;AAAA,WACnB,KAAK;AACZ,QAAI,IAAI,SAAS;AACR,aAAA;AAGH,UAAA;AAAA,EAAA;AAEV;AAEO,SAAS,WAAW,UAA0B;AACnD,MACE,SAAS,WAAW,CAAC,MAAM,KAE3B;AAEE,QAAA,SAAS,WAAW,CAAC,MAAM;AAGpB,aAAA,KAAK,KAAK,QAAQ,OAAO,SAAS,MAAM,CAAC,CAAC;AAG7C,UAAA,OAAO,GAAG,QAAQ;AACjB,WAAA,OAAO,KAAK,KAAK,MAAM,SAAS,MAAM,CAAC,CAAC,IAAI;AAAA,EAAA;AAG9C,SAAA;AACT;AAEO,SAAS,WAAW,KAAqB;AACxC,QAAA,WAAW,WAAW,GAAG;AACxB,SAAA,KAAK,WAAW,QAAQ,IAAI,WAAW,KAAK,QAAQ,QAAQ,IAAI,GAAG,QAAQ;AACpF;"}
|
package/lib/index.d.mts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {}
|
package/lib/index.mjs
DELETED
package/lib/index.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":""}
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
export declare const DEFAULT_DATE_FORMAT = 'YYYY-MM-DD'
|
|
2
|
-
|
|
3
|
-
export declare const DEFAULT_TIME_FORMAT = 'HH:mm'
|
|
4
|
-
|
|
5
|
-
export declare function format(
|
|
6
|
-
input: Date,
|
|
7
|
-
dateFormat: string,
|
|
8
|
-
options?: {
|
|
9
|
-
useUTC?: boolean
|
|
10
|
-
timeZone?: string
|
|
11
|
-
},
|
|
12
|
-
): string
|
|
13
|
-
|
|
14
|
-
export declare function isValidTimeZoneString(timeZone: string): boolean
|
|
15
|
-
|
|
16
|
-
export declare function parse(
|
|
17
|
-
dateString: string,
|
|
18
|
-
dateFormat?: string,
|
|
19
|
-
timeZone?: string,
|
|
20
|
-
): ParseResult
|
|
21
|
-
|
|
22
|
-
export declare type ParseResult = {
|
|
23
|
-
isValid: boolean
|
|
24
|
-
date?: Date
|
|
25
|
-
error?: string
|
|
26
|
-
} & (
|
|
27
|
-
| {
|
|
28
|
-
isValid: true
|
|
29
|
-
date: Date
|
|
30
|
-
}
|
|
31
|
-
| {
|
|
32
|
-
isValid: false
|
|
33
|
-
error?: string
|
|
34
|
-
}
|
|
35
|
-
)
|
|
36
|
-
|
|
37
|
-
export declare const sanitizeLocale: (locale: string) => string
|
|
38
|
-
|
|
39
|
-
export {}
|