@mado/utils 0.3.0 → 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/dist/capitalize.cjs +1 -3
- package/dist/capitalize.cjs.map +1 -1
- package/dist/capitalize.js +1 -3
- package/dist/capitalize.js.map +1 -1
- package/dist/debounce.cjs +2 -3
- package/dist/debounce.cjs.map +1 -1
- package/dist/debounce.d.cts +2 -1
- package/dist/debounce.d.ts +2 -1
- package/dist/debounce.js +2 -3
- package/dist/debounce.js.map +1 -1
- package/dist/index.cjs +20 -44
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +6 -4
- package/dist/index.d.ts +6 -4
- package/dist/index.js +9 -8
- package/dist/index.js.map +1 -1
- package/dist/invariant.cjs +39 -0
- package/dist/invariant.cjs.map +1 -0
- package/dist/invariant.d.cts +14 -0
- package/dist/invariant.d.ts +14 -0
- package/dist/invariant.js +34 -0
- package/dist/invariant.js.map +1 -0
- package/dist/{isNil.cjs → is-nil.cjs} +1 -3
- package/dist/is-nil.cjs.map +1 -0
- package/dist/is-nil.js +6 -0
- package/dist/is-nil.js.map +1 -0
- package/dist/is-object-like.cjs +8 -0
- package/dist/is-object-like.cjs.map +1 -0
- package/dist/is-object-like.js +6 -0
- package/dist/is-object-like.js.map +1 -0
- package/dist/{isPlainObject.cjs → is-plain-object.cjs} +3 -5
- package/dist/is-plain-object.cjs.map +1 -0
- package/dist/is-plain-object.d.cts +3 -0
- package/dist/is-plain-object.d.ts +3 -0
- package/dist/{isPlainObject.js → is-plain-object.js} +2 -4
- package/dist/is-plain-object.js.map +1 -0
- package/dist/remember.cjs +15 -0
- package/dist/remember.cjs.map +1 -0
- package/dist/remember.d.cts +3 -0
- package/dist/remember.d.ts +3 -0
- package/dist/remember.js +13 -0
- package/dist/remember.js.map +1 -0
- package/dist/storage-available.cjs +20 -0
- package/dist/storage-available.cjs.map +1 -0
- package/dist/storage-available.js +18 -0
- package/dist/storage-available.js.map +1 -0
- package/package.json +28 -21
- package/CHANGELOG.md +0 -26
- package/dist/isNil.cjs.map +0 -1
- package/dist/isNil.js +0 -8
- package/dist/isNil.js.map +0 -1
- package/dist/isObjectLike.cjs +0 -10
- package/dist/isObjectLike.cjs.map +0 -1
- package/dist/isObjectLike.js +0 -8
- package/dist/isObjectLike.js.map +0 -1
- package/dist/isPlainObject.cjs.map +0 -1
- package/dist/isPlainObject.d.cts +0 -3
- package/dist/isPlainObject.d.ts +0 -3
- package/dist/isPlainObject.js.map +0 -1
- package/dist/storageAvailable.cjs +0 -25
- package/dist/storageAvailable.cjs.map +0 -1
- package/dist/storageAvailable.js +0 -23
- package/dist/storageAvailable.js.map +0 -1
- package/src/capitalize.ts +0 -3
- package/src/debounce.ts +0 -25
- package/src/index.ts +0 -6
- package/src/isNil.ts +0 -3
- package/src/isObjectLike.ts +0 -3
- package/src/isPlainObject.ts +0 -17
- package/src/storageAvailable.ts +0 -33
- /package/dist/{isNil.d.cts → is-nil.d.cts} +0 -0
- /package/dist/{isNil.d.ts → is-nil.d.ts} +0 -0
- /package/dist/{isObjectLike.d.cts → is-object-like.d.cts} +0 -0
- /package/dist/{isObjectLike.d.ts → is-object-like.d.ts} +0 -0
- /package/dist/{storageAvailable.d.cts → storage-available.d.cts} +0 -0
- /package/dist/{storageAvailable.d.ts → storage-available.d.ts} +0 -0
package/LICENSE
CHANGED
package/dist/capitalize.cjs
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
// src/capitalize.ts
|
|
4
3
|
function capitalize(str) {
|
|
5
4
|
return str.charAt(0).toUpperCase() + str.substring(1);
|
|
6
5
|
}
|
|
7
6
|
|
|
8
7
|
exports.capitalize = capitalize;
|
|
9
|
-
//# sourceMappingURL=
|
|
10
|
-
//# sourceMappingURL=capitalize.cjs.map
|
|
8
|
+
//# sourceMappingURL=capitalize.cjs.map
|
package/dist/capitalize.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/capitalize.ts"],"
|
|
1
|
+
{"version":3,"file":"capitalize.cjs","sources":["../src/capitalize.ts"],"sourcesContent":["export function capitalize(str: string): string {\n return str.charAt(0).toUpperCase() + str.substring(1);\n}\n"],"names":["capitalize","str","charAt","toUpperCase","substring"],"mappings":";;AAAO,SAASA,UAAUA,CAACC,GAAW,EAAU;AAC9C,EAAA,OAAOA,GAAG,CAACC,MAAM,CAAC,CAAC,CAAC,CAACC,WAAW,EAAE,GAAGF,GAAG,CAACG,SAAS,CAAC,CAAC,CAAC;AACvD;;"}
|
package/dist/capitalize.js
CHANGED
package/dist/capitalize.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/capitalize.ts"],"
|
|
1
|
+
{"version":3,"file":"capitalize.js","sources":["../src/capitalize.ts"],"sourcesContent":["export function capitalize(str: string): string {\n return str.charAt(0).toUpperCase() + str.substring(1);\n}\n"],"names":["capitalize","str","charAt","toUpperCase","substring"],"mappings":"AAAO,SAASA,UAAUA,CAACC,GAAW,EAAU;AAC9C,EAAA,OAAOA,GAAG,CAACC,MAAM,CAAC,CAAC,CAAC,CAACC,WAAW,EAAE,GAAGF,GAAG,CAACG,SAAS,CAAC,CAAC,CAAC;AACvD;;"}
|
package/dist/debounce.cjs
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
// src/debounce.ts
|
|
4
3
|
function debounce(func, wait = 166) {
|
|
5
4
|
let timeout;
|
|
6
5
|
function debounced(...args) {
|
|
7
6
|
clearTimeout(timeout);
|
|
8
7
|
timeout = setTimeout(() => {
|
|
8
|
+
// @ts-ignore
|
|
9
9
|
func.apply(this, args);
|
|
10
10
|
}, wait);
|
|
11
11
|
}
|
|
@@ -16,5 +16,4 @@ function debounce(func, wait = 166) {
|
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
exports.debounce = debounce;
|
|
19
|
-
//# sourceMappingURL=
|
|
20
|
-
//# sourceMappingURL=debounce.cjs.map
|
|
19
|
+
//# sourceMappingURL=debounce.cjs.map
|
package/dist/debounce.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/debounce.ts"],"
|
|
1
|
+
{"version":3,"file":"debounce.cjs","sources":["../src/debounce.ts"],"sourcesContent":["export interface Cancelable {\n cancel: () => void;\n}\n\nexport function debounce<T extends (...args: any[]) => any>(func: T, wait = 166): T & Cancelable {\n let timeout: ReturnType<typeof setTimeout>;\n\n function debounced(...args: Parameters<T>) {\n clearTimeout(timeout);\n\n timeout = setTimeout(() => {\n // @ts-ignore\n func.apply(this, args);\n }, wait);\n }\n\n debounced.cancel = () => {\n clearTimeout(timeout);\n };\n\n return debounced as T & Cancelable;\n}\n"],"names":["debounce","func","wait","timeout","debounced","args","clearTimeout","setTimeout","apply","cancel"],"mappings":";;AAIO,SAASA,QAAQA,CAAoCC,IAAO,EAAEC,IAAI,GAAG,GAAG,EAAkB;AAC/F,EAAA,IAAIC,OAAsC;AAE1C,EAAA,SAASC,SAASA,CAAC,GAAGC,IAAmB,EAAE;IACzCC,YAAY,CAACH,OAAO,CAAC;IAErBA,OAAO,GAAGI,UAAU,CAAC,MAAM;AACzB;AACAN,MAAAA,IAAI,CAACO,KAAK,CAAC,IAAI,EAAEH,IAAI,CAAC;IACxB,CAAC,EAAEH,IAAI,CAAC;AACV,EAAA;EAEAE,SAAS,CAACK,MAAM,GAAG,MAAM;IACvBH,YAAY,CAACH,OAAO,CAAC;EACvB,CAAC;AAED,EAAA,OAAOC,SAAS;AAClB;;"}
|
package/dist/debounce.d.cts
CHANGED
package/dist/debounce.d.ts
CHANGED
package/dist/debounce.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
// src/debounce.ts
|
|
2
1
|
function debounce(func, wait = 166) {
|
|
3
2
|
let timeout;
|
|
4
3
|
function debounced(...args) {
|
|
5
4
|
clearTimeout(timeout);
|
|
6
5
|
timeout = setTimeout(() => {
|
|
6
|
+
// @ts-ignore
|
|
7
7
|
func.apply(this, args);
|
|
8
8
|
}, wait);
|
|
9
9
|
}
|
|
@@ -14,5 +14,4 @@ function debounce(func, wait = 166) {
|
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
export { debounce };
|
|
17
|
-
//# sourceMappingURL=
|
|
18
|
-
//# sourceMappingURL=debounce.js.map
|
|
17
|
+
//# sourceMappingURL=debounce.js.map
|
package/dist/debounce.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/debounce.ts"],"
|
|
1
|
+
{"version":3,"file":"debounce.js","sources":["../src/debounce.ts"],"sourcesContent":["export interface Cancelable {\n cancel: () => void;\n}\n\nexport function debounce<T extends (...args: any[]) => any>(func: T, wait = 166): T & Cancelable {\n let timeout: ReturnType<typeof setTimeout>;\n\n function debounced(...args: Parameters<T>) {\n clearTimeout(timeout);\n\n timeout = setTimeout(() => {\n // @ts-ignore\n func.apply(this, args);\n }, wait);\n }\n\n debounced.cancel = () => {\n clearTimeout(timeout);\n };\n\n return debounced as T & Cancelable;\n}\n"],"names":["debounce","func","wait","timeout","debounced","args","clearTimeout","setTimeout","apply","cancel"],"mappings":"AAIO,SAASA,QAAQA,CAAoCC,IAAO,EAAEC,IAAI,GAAG,GAAG,EAAkB;AAC/F,EAAA,IAAIC,OAAsC;AAE1C,EAAA,SAASC,SAASA,CAAC,GAAGC,IAAmB,EAAE;IACzCC,YAAY,CAACH,OAAO,CAAC;IAErBA,OAAO,GAAGI,UAAU,CAAC,MAAM;AACzB;AACAN,MAAAA,IAAI,CAACO,KAAK,CAAC,IAAI,EAAEH,IAAI,CAAC;IACxB,CAAC,EAAEH,IAAI,CAAC;AACV,EAAA;EAEAE,SAAS,CAACK,MAAM,GAAG,MAAM;IACvBH,YAAY,CAACH,OAAO,CAAC;EACvB,CAAC;AAED,EAAA,OAAOC,SAAS;AAClB;;"}
|
package/dist/index.cjs
CHANGED
|
@@ -1,49 +1,25 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
var
|
|
5
|
-
var
|
|
6
|
-
var
|
|
7
|
-
var
|
|
8
|
-
var
|
|
3
|
+
var capitalize = require('./capitalize.cjs');
|
|
4
|
+
var debounce = require('./debounce.cjs');
|
|
5
|
+
var invariant = require('./invariant.cjs');
|
|
6
|
+
var isNil = require('./is-nil.cjs');
|
|
7
|
+
var isObjectLike = require('./is-object-like.cjs');
|
|
8
|
+
var isPlainObject = require('./is-plain-object.cjs');
|
|
9
|
+
var remember = require('./remember.cjs');
|
|
10
|
+
var storageAvailable = require('./storage-available.cjs');
|
|
9
11
|
|
|
10
12
|
|
|
11
13
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
Object.keys(isNil_cjs).forEach(function (k) {
|
|
25
|
-
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
26
|
-
enumerable: true,
|
|
27
|
-
get: function () { return isNil_cjs[k]; }
|
|
28
|
-
});
|
|
29
|
-
});
|
|
30
|
-
Object.keys(isObjectLike_cjs).forEach(function (k) {
|
|
31
|
-
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
32
|
-
enumerable: true,
|
|
33
|
-
get: function () { return isObjectLike_cjs[k]; }
|
|
34
|
-
});
|
|
35
|
-
});
|
|
36
|
-
Object.keys(isPlainObject_cjs).forEach(function (k) {
|
|
37
|
-
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
38
|
-
enumerable: true,
|
|
39
|
-
get: function () { return isPlainObject_cjs[k]; }
|
|
40
|
-
});
|
|
41
|
-
});
|
|
42
|
-
Object.keys(storageAvailable_cjs).forEach(function (k) {
|
|
43
|
-
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
44
|
-
enumerable: true,
|
|
45
|
-
get: function () { return storageAvailable_cjs[k]; }
|
|
46
|
-
});
|
|
47
|
-
});
|
|
48
|
-
//# sourceMappingURL=out.js.map
|
|
49
|
-
//# sourceMappingURL=index.cjs.map
|
|
14
|
+
exports.capitalize = capitalize.capitalize;
|
|
15
|
+
exports.debounce = debounce.debounce;
|
|
16
|
+
exports.InvariantError = invariant.InvariantError;
|
|
17
|
+
exports.invariant = invariant.invariant;
|
|
18
|
+
exports.invariantResponse = invariant.invariantResponse;
|
|
19
|
+
exports.isInvariantError = invariant.isInvariantError;
|
|
20
|
+
exports.isNil = isNil.isNil;
|
|
21
|
+
exports.isObjectLike = isObjectLike.isObjectLike;
|
|
22
|
+
exports.isPlainObject = isPlainObject.isPlainObject;
|
|
23
|
+
exports.remember = remember.remember;
|
|
24
|
+
exports.storageAvailable = storageAvailable.storageAvailable;
|
|
25
|
+
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;"}
|
package/dist/index.d.cts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
export { capitalize } from './capitalize.cjs';
|
|
2
2
|
export { Cancelable, debounce } from './debounce.cjs';
|
|
3
|
-
export {
|
|
4
|
-
export {
|
|
5
|
-
export {
|
|
6
|
-
export {
|
|
3
|
+
export { InvariantError, invariant, invariantResponse, isInvariantError } from './invariant.cjs';
|
|
4
|
+
export { isNil } from './is-nil.cjs';
|
|
5
|
+
export { isObjectLike } from './is-object-like.cjs';
|
|
6
|
+
export { isPlainObject } from './is-plain-object.cjs';
|
|
7
|
+
export { remember } from './remember.cjs';
|
|
8
|
+
export { storageAvailable } from './storage-available.cjs';
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
export { capitalize } from './capitalize.js';
|
|
2
2
|
export { Cancelable, debounce } from './debounce.js';
|
|
3
|
-
export {
|
|
4
|
-
export {
|
|
5
|
-
export {
|
|
6
|
-
export {
|
|
3
|
+
export { InvariantError, invariant, invariantResponse, isInvariantError } from './invariant.js';
|
|
4
|
+
export { isNil } from './is-nil.js';
|
|
5
|
+
export { isObjectLike } from './is-object-like.js';
|
|
6
|
+
export { isPlainObject } from './is-plain-object.js';
|
|
7
|
+
export { remember } from './remember.js';
|
|
8
|
+
export { storageAvailable } from './storage-available.js';
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
export
|
|
2
|
-
export
|
|
3
|
-
export
|
|
4
|
-
export
|
|
5
|
-
export
|
|
6
|
-
export
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
export { capitalize } from './capitalize.js';
|
|
2
|
+
export { debounce } from './debounce.js';
|
|
3
|
+
export { InvariantError, invariant, invariantResponse, isInvariantError } from './invariant.js';
|
|
4
|
+
export { isNil } from './is-nil.js';
|
|
5
|
+
export { isObjectLike } from './is-object-like.js';
|
|
6
|
+
export { isPlainObject } from './is-plain-object.js';
|
|
7
|
+
export { remember } from './remember.js';
|
|
8
|
+
export { storageAvailable } from './storage-available.js';
|
|
9
|
+
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
class InvariantError extends Error {
|
|
4
|
+
constructor(message) {
|
|
5
|
+
super(message);
|
|
6
|
+
this.name = 'InvariantError';
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
function isInvariantError(error) {
|
|
10
|
+
return error instanceof InvariantError;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* @throws {InvariantError}
|
|
15
|
+
*/
|
|
16
|
+
function invariant(condition, message) {
|
|
17
|
+
if (!condition) {
|
|
18
|
+
throw new InvariantError(typeof message === 'function' ? message() : message);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* @throws {Response}
|
|
24
|
+
*/
|
|
25
|
+
function invariantResponse(condition, message, responseInit) {
|
|
26
|
+
if (!condition) {
|
|
27
|
+
// eslint-disable-next-line @typescript-eslint/only-throw-error
|
|
28
|
+
throw new Response(typeof message === 'function' ? message() : message, {
|
|
29
|
+
status: 400,
|
|
30
|
+
...responseInit
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
exports.InvariantError = InvariantError;
|
|
36
|
+
exports.invariant = invariant;
|
|
37
|
+
exports.invariantResponse = invariantResponse;
|
|
38
|
+
exports.isInvariantError = isInvariantError;
|
|
39
|
+
//# sourceMappingURL=invariant.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"invariant.cjs","sources":["../src/invariant.ts"],"sourcesContent":["export class InvariantError extends Error {\n constructor(message: string) {\n super(message);\n\n this.name = 'InvariantError';\n }\n}\n\nexport function isInvariantError(error: unknown): error is InvariantError {\n return error instanceof InvariantError;\n}\n\n/**\n * @throws {InvariantError}\n */\nexport function invariant(condition: unknown, message: string | (() => string)): asserts condition {\n if (!condition) {\n throw new InvariantError(typeof message === 'function' ? message() : message);\n }\n}\n\n/**\n * @throws {Response}\n */\nexport function invariantResponse(\n condition: unknown,\n message: string | (() => string),\n responseInit?: ResponseInit,\n): asserts condition {\n if (!condition) {\n // eslint-disable-next-line @typescript-eslint/only-throw-error\n throw new Response(typeof message === 'function' ? message() : message, {\n status: 400,\n ...responseInit,\n });\n }\n}\n"],"names":["InvariantError","Error","constructor","message","name","isInvariantError","error","invariant","condition","invariantResponse","responseInit","Response","status"],"mappings":";;AAAO,MAAMA,cAAc,SAASC,KAAK,CAAC;EACxCC,WAAWA,CAACC,OAAe,EAAE;IAC3B,KAAK,CAACA,OAAO,CAAC;IAEd,IAAI,CAACC,IAAI,GAAG,gBAAgB;AAC9B,EAAA;AACF;AAEO,SAASC,gBAAgBA,CAACC,KAAc,EAA2B;EACxE,OAAOA,KAAK,YAAYN,cAAc;AACxC;;AAEA;AACA;AACA;AACO,SAASO,SAASA,CAACC,SAAkB,EAAEL,OAAgC,EAAqB;EACjG,IAAI,CAACK,SAAS,EAAE;AACd,IAAA,MAAM,IAAIR,cAAc,CAAC,OAAOG,OAAO,KAAK,UAAU,GAAGA,OAAO,EAAE,GAAGA,OAAO,CAAC;AAC/E,EAAA;AACF;;AAEA;AACA;AACA;AACO,SAASM,iBAAiBA,CAC/BD,SAAkB,EAClBL,OAAgC,EAChCO,YAA2B,EACR;EACnB,IAAI,CAACF,SAAS,EAAE;AACd;AACA,IAAA,MAAM,IAAIG,QAAQ,CAAC,OAAOR,OAAO,KAAK,UAAU,GAAGA,OAAO,EAAE,GAAGA,OAAO,EAAE;AACtES,MAAAA,MAAM,EAAE,GAAG;MACX,GAAGF;AACL,KAAC,CAAC;AACJ,EAAA;AACF;;;;;"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
declare class InvariantError extends Error {
|
|
2
|
+
constructor(message: string);
|
|
3
|
+
}
|
|
4
|
+
declare function isInvariantError(error: unknown): error is InvariantError;
|
|
5
|
+
/**
|
|
6
|
+
* @throws {InvariantError}
|
|
7
|
+
*/
|
|
8
|
+
declare function invariant(condition: unknown, message: string | (() => string)): asserts condition;
|
|
9
|
+
/**
|
|
10
|
+
* @throws {Response}
|
|
11
|
+
*/
|
|
12
|
+
declare function invariantResponse(condition: unknown, message: string | (() => string), responseInit?: ResponseInit): asserts condition;
|
|
13
|
+
|
|
14
|
+
export { InvariantError, invariant, invariantResponse, isInvariantError };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
declare class InvariantError extends Error {
|
|
2
|
+
constructor(message: string);
|
|
3
|
+
}
|
|
4
|
+
declare function isInvariantError(error: unknown): error is InvariantError;
|
|
5
|
+
/**
|
|
6
|
+
* @throws {InvariantError}
|
|
7
|
+
*/
|
|
8
|
+
declare function invariant(condition: unknown, message: string | (() => string)): asserts condition;
|
|
9
|
+
/**
|
|
10
|
+
* @throws {Response}
|
|
11
|
+
*/
|
|
12
|
+
declare function invariantResponse(condition: unknown, message: string | (() => string), responseInit?: ResponseInit): asserts condition;
|
|
13
|
+
|
|
14
|
+
export { InvariantError, invariant, invariantResponse, isInvariantError };
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
class InvariantError extends Error {
|
|
2
|
+
constructor(message) {
|
|
3
|
+
super(message);
|
|
4
|
+
this.name = 'InvariantError';
|
|
5
|
+
}
|
|
6
|
+
}
|
|
7
|
+
function isInvariantError(error) {
|
|
8
|
+
return error instanceof InvariantError;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* @throws {InvariantError}
|
|
13
|
+
*/
|
|
14
|
+
function invariant(condition, message) {
|
|
15
|
+
if (!condition) {
|
|
16
|
+
throw new InvariantError(typeof message === 'function' ? message() : message);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* @throws {Response}
|
|
22
|
+
*/
|
|
23
|
+
function invariantResponse(condition, message, responseInit) {
|
|
24
|
+
if (!condition) {
|
|
25
|
+
// eslint-disable-next-line @typescript-eslint/only-throw-error
|
|
26
|
+
throw new Response(typeof message === 'function' ? message() : message, {
|
|
27
|
+
status: 400,
|
|
28
|
+
...responseInit
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export { InvariantError, invariant, invariantResponse, isInvariantError };
|
|
34
|
+
//# sourceMappingURL=invariant.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"invariant.js","sources":["../src/invariant.ts"],"sourcesContent":["export class InvariantError extends Error {\n constructor(message: string) {\n super(message);\n\n this.name = 'InvariantError';\n }\n}\n\nexport function isInvariantError(error: unknown): error is InvariantError {\n return error instanceof InvariantError;\n}\n\n/**\n * @throws {InvariantError}\n */\nexport function invariant(condition: unknown, message: string | (() => string)): asserts condition {\n if (!condition) {\n throw new InvariantError(typeof message === 'function' ? message() : message);\n }\n}\n\n/**\n * @throws {Response}\n */\nexport function invariantResponse(\n condition: unknown,\n message: string | (() => string),\n responseInit?: ResponseInit,\n): asserts condition {\n if (!condition) {\n // eslint-disable-next-line @typescript-eslint/only-throw-error\n throw new Response(typeof message === 'function' ? message() : message, {\n status: 400,\n ...responseInit,\n });\n }\n}\n"],"names":["InvariantError","Error","constructor","message","name","isInvariantError","error","invariant","condition","invariantResponse","responseInit","Response","status"],"mappings":"AAAO,MAAMA,cAAc,SAASC,KAAK,CAAC;EACxCC,WAAWA,CAACC,OAAe,EAAE;IAC3B,KAAK,CAACA,OAAO,CAAC;IAEd,IAAI,CAACC,IAAI,GAAG,gBAAgB;AAC9B,EAAA;AACF;AAEO,SAASC,gBAAgBA,CAACC,KAAc,EAA2B;EACxE,OAAOA,KAAK,YAAYN,cAAc;AACxC;;AAEA;AACA;AACA;AACO,SAASO,SAASA,CAACC,SAAkB,EAAEL,OAAgC,EAAqB;EACjG,IAAI,CAACK,SAAS,EAAE;AACd,IAAA,MAAM,IAAIR,cAAc,CAAC,OAAOG,OAAO,KAAK,UAAU,GAAGA,OAAO,EAAE,GAAGA,OAAO,CAAC;AAC/E,EAAA;AACF;;AAEA;AACA;AACA;AACO,SAASM,iBAAiBA,CAC/BD,SAAkB,EAClBL,OAAgC,EAChCO,YAA2B,EACR;EACnB,IAAI,CAACF,SAAS,EAAE;AACd;AACA,IAAA,MAAM,IAAIG,QAAQ,CAAC,OAAOR,OAAO,KAAK,UAAU,GAAGA,OAAO,EAAE,GAAGA,OAAO,EAAE;AACtES,MAAAA,MAAM,EAAE,GAAG;MACX,GAAGF;AACL,KAAC,CAAC;AACJ,EAAA;AACF;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"is-nil.cjs","sources":["../src/is-nil.ts"],"sourcesContent":["export function isNil(value: unknown): value is null | undefined {\n return value == null;\n}\n"],"names":["isNil","value"],"mappings":";;AAAO,SAASA,KAAKA,CAACC,KAAc,EAA6B;EAC/D,OAAOA,KAAK,IAAI,IAAI;AACtB;;"}
|
package/dist/is-nil.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"is-nil.js","sources":["../src/is-nil.ts"],"sourcesContent":["export function isNil(value: unknown): value is null | undefined {\n return value == null;\n}\n"],"names":["isNil","value"],"mappings":"AAAO,SAASA,KAAKA,CAACC,KAAc,EAA6B;EAC/D,OAAOA,KAAK,IAAI,IAAI;AACtB;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"is-object-like.cjs","sources":["../src/is-object-like.ts"],"sourcesContent":["export function isObjectLike(value: unknown): value is object {\n return typeof value === 'object' && value !== null;\n}\n"],"names":["isObjectLike","value"],"mappings":";;AAAO,SAASA,YAAYA,CAACC,KAAc,EAAmB;AAC5D,EAAA,OAAO,OAAOA,KAAK,KAAK,QAAQ,IAAIA,KAAK,KAAK,IAAI;AACpD;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"is-object-like.js","sources":["../src/is-object-like.ts"],"sourcesContent":["export function isObjectLike(value: unknown): value is object {\n return typeof value === 'object' && value !== null;\n}\n"],"names":["isObjectLike","value"],"mappings":"AAAO,SAASA,YAAYA,CAACC,KAAc,EAAmB;AAC5D,EAAA,OAAO,OAAOA,KAAK,KAAK,QAAQ,IAAIA,KAAK,KAAK,IAAI;AACpD;;"}
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var isObjectLike = require('./is-object-like.cjs');
|
|
4
4
|
|
|
5
|
-
// src/isPlainObject.ts
|
|
6
5
|
function isPlainObject(value) {
|
|
7
|
-
if (!
|
|
6
|
+
if (!isObjectLike.isObjectLike(value)) {
|
|
8
7
|
return false;
|
|
9
8
|
}
|
|
10
9
|
const prototype = Object.getPrototypeOf(value);
|
|
@@ -12,5 +11,4 @@ function isPlainObject(value) {
|
|
|
12
11
|
}
|
|
13
12
|
|
|
14
13
|
exports.isPlainObject = isPlainObject;
|
|
15
|
-
//# sourceMappingURL=
|
|
16
|
-
//# sourceMappingURL=isPlainObject.cjs.map
|
|
14
|
+
//# sourceMappingURL=is-plain-object.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"is-plain-object.cjs","sources":["../src/is-plain-object.ts"],"sourcesContent":["import { isObjectLike } from './is-object-like';\n\nexport function isPlainObject(value: unknown): value is object {\n if (!isObjectLike(value)) {\n return false;\n }\n\n const prototype = Object.getPrototypeOf(value);\n\n return (\n (prototype === null || prototype === Object.prototype || Object.getPrototypeOf(prototype) === null) &&\n !(Symbol.toStringTag in value) &&\n !(Symbol.iterator in value)\n );\n}\n"],"names":["isPlainObject","value","isObjectLike","prototype","Object","getPrototypeOf","Symbol","toStringTag","iterator"],"mappings":";;;;AAEO,SAASA,aAAaA,CAACC,KAAc,EAAmB;AAC7D,EAAA,IAAI,CAACC,yBAAY,CAACD,KAAK,CAAC,EAAE;AACxB,IAAA,OAAO,KAAK;AACd,EAAA;AAEA,EAAA,MAAME,SAAS,GAAGC,MAAM,CAACC,cAAc,CAACJ,KAAK,CAAC;AAE9C,EAAA,OACE,CAACE,SAAS,KAAK,IAAI,IAAIA,SAAS,KAAKC,MAAM,CAACD,SAAS,IAAIC,MAAM,CAACC,cAAc,CAACF,SAAS,CAAC,KAAK,IAAI,KAClG,EAAEG,MAAM,CAACC,WAAW,IAAIN,KAAK,CAAC,IAC9B,EAAEK,MAAM,CAACE,QAAQ,IAAIP,KAAK,CAAC;AAE/B;;"}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { isObjectLike } from './
|
|
1
|
+
import { isObjectLike } from './is-object-like.js';
|
|
2
2
|
|
|
3
|
-
// src/isPlainObject.ts
|
|
4
3
|
function isPlainObject(value) {
|
|
5
4
|
if (!isObjectLike(value)) {
|
|
6
5
|
return false;
|
|
@@ -10,5 +9,4 @@ function isPlainObject(value) {
|
|
|
10
9
|
}
|
|
11
10
|
|
|
12
11
|
export { isPlainObject };
|
|
13
|
-
//# sourceMappingURL=
|
|
14
|
-
//# sourceMappingURL=isPlainObject.js.map
|
|
12
|
+
//# sourceMappingURL=is-plain-object.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"is-plain-object.js","sources":["../src/is-plain-object.ts"],"sourcesContent":["import { isObjectLike } from './is-object-like';\n\nexport function isPlainObject(value: unknown): value is object {\n if (!isObjectLike(value)) {\n return false;\n }\n\n const prototype = Object.getPrototypeOf(value);\n\n return (\n (prototype === null || prototype === Object.prototype || Object.getPrototypeOf(prototype) === null) &&\n !(Symbol.toStringTag in value) &&\n !(Symbol.iterator in value)\n );\n}\n"],"names":["isPlainObject","value","isObjectLike","prototype","Object","getPrototypeOf","Symbol","toStringTag","iterator"],"mappings":";;AAEO,SAASA,aAAaA,CAACC,KAAc,EAAmB;AAC7D,EAAA,IAAI,CAACC,YAAY,CAACD,KAAK,CAAC,EAAE;AACxB,IAAA,OAAO,KAAK;AACd,EAAA;AAEA,EAAA,MAAME,SAAS,GAAGC,MAAM,CAACC,cAAc,CAACJ,KAAK,CAAC;AAE9C,EAAA,OACE,CAACE,SAAS,KAAK,IAAI,IAAIA,SAAS,KAAKC,MAAM,CAACD,SAAS,IAAIC,MAAM,CAACC,cAAc,CAACF,SAAS,CAAC,KAAK,IAAI,KAClG,EAAEG,MAAM,CAACC,WAAW,IAAIN,KAAK,CAAC,IAC9B,EAAEK,MAAM,CAACE,QAAQ,IAAIP,KAAK,CAAC;AAE/B;;"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
function remember(name, getValue) {
|
|
4
|
+
const ctx = globalThis;
|
|
5
|
+
if (!ctx.__remember) {
|
|
6
|
+
ctx.__remember = new Map();
|
|
7
|
+
}
|
|
8
|
+
if (!ctx.__remember.has(name)) {
|
|
9
|
+
ctx.__remember.set(name, getValue());
|
|
10
|
+
}
|
|
11
|
+
return ctx.__remember.get(name);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
exports.remember = remember;
|
|
15
|
+
//# sourceMappingURL=remember.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"remember.cjs","sources":["../src/remember.ts"],"sourcesContent":["declare namespace globalThis {\n // eslint-disable-next-line no-var\n var __remember: Map<string, any> | undefined;\n}\n\nexport function remember<T>(name: string, getValue: () => T): T {\n const ctx = globalThis;\n\n if (!ctx.__remember) {\n ctx.__remember = new Map();\n }\n\n if (!ctx.__remember.has(name)) {\n ctx.__remember.set(name, getValue());\n }\n\n return ctx.__remember.get(name) as T;\n}\n"],"names":["remember","name","getValue","ctx","globalThis","__remember","Map","has","set","get"],"mappings":";;AAKO,SAASA,QAAQA,CAAIC,IAAY,EAAEC,QAAiB,EAAK;EAC9D,MAAMC,GAAG,GAAGC,UAAU;AAEtB,EAAA,IAAI,CAACD,GAAG,CAACE,UAAU,EAAE;AACnBF,IAAAA,GAAG,CAACE,UAAU,GAAG,IAAIC,GAAG,EAAE;AAC5B,EAAA;EAEA,IAAI,CAACH,GAAG,CAACE,UAAU,CAACE,GAAG,CAACN,IAAI,CAAC,EAAE;IAC7BE,GAAG,CAACE,UAAU,CAACG,GAAG,CAACP,IAAI,EAAEC,QAAQ,EAAE,CAAC;AACtC,EAAA;AAEA,EAAA,OAAOC,GAAG,CAACE,UAAU,CAACI,GAAG,CAACR,IAAI,CAAC;AACjC;;"}
|
package/dist/remember.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
function remember(name, getValue) {
|
|
2
|
+
const ctx = globalThis;
|
|
3
|
+
if (!ctx.__remember) {
|
|
4
|
+
ctx.__remember = new Map();
|
|
5
|
+
}
|
|
6
|
+
if (!ctx.__remember.has(name)) {
|
|
7
|
+
ctx.__remember.set(name, getValue());
|
|
8
|
+
}
|
|
9
|
+
return ctx.__remember.get(name);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export { remember };
|
|
13
|
+
//# sourceMappingURL=remember.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"remember.js","sources":["../src/remember.ts"],"sourcesContent":["declare namespace globalThis {\n // eslint-disable-next-line no-var\n var __remember: Map<string, any> | undefined;\n}\n\nexport function remember<T>(name: string, getValue: () => T): T {\n const ctx = globalThis;\n\n if (!ctx.__remember) {\n ctx.__remember = new Map();\n }\n\n if (!ctx.__remember.has(name)) {\n ctx.__remember.set(name, getValue());\n }\n\n return ctx.__remember.get(name) as T;\n}\n"],"names":["remember","name","getValue","ctx","globalThis","__remember","Map","has","set","get"],"mappings":"AAKO,SAASA,QAAQA,CAAIC,IAAY,EAAEC,QAAiB,EAAK;EAC9D,MAAMC,GAAG,GAAGC,UAAU;AAEtB,EAAA,IAAI,CAACD,GAAG,CAACE,UAAU,EAAE;AACnBF,IAAAA,GAAG,CAACE,UAAU,GAAG,IAAIC,GAAG,EAAE;AAC5B,EAAA;EAEA,IAAI,CAACH,GAAG,CAACE,UAAU,CAACE,GAAG,CAACN,IAAI,CAAC,EAAE;IAC7BE,GAAG,CAACE,UAAU,CAACG,GAAG,CAACP,IAAI,EAAEC,QAAQ,EAAE,CAAC;AACtC,EAAA;AAEA,EAAA,OAAOC,GAAG,CAACE,UAAU,CAACI,GAAG,CAACR,IAAI,CAAC;AACjC;;"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Web_Storage_API/Using_the_Web_Storage_API#feature-detecting_localstorage MDN}
|
|
5
|
+
*/
|
|
6
|
+
function storageAvailable(type) {
|
|
7
|
+
let storage;
|
|
8
|
+
try {
|
|
9
|
+
storage = window[type];
|
|
10
|
+
const x = `__${type}__`;
|
|
11
|
+
storage.setItem(x, x);
|
|
12
|
+
storage.removeItem(x);
|
|
13
|
+
return true;
|
|
14
|
+
} catch (e) {
|
|
15
|
+
return e instanceof DOMException && e.name === 'QuotaExceededError' && !!storage && storage.length !== 0;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
exports.storageAvailable = storageAvailable;
|
|
20
|
+
//# sourceMappingURL=storage-available.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"storage-available.cjs","sources":["../src/storage-available.ts"],"sourcesContent":["/**\n * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Web_Storage_API/Using_the_Web_Storage_API#feature-detecting_localstorage MDN}\n */\nexport function storageAvailable(type: 'localStorage' | 'sessionStorage'): boolean {\n let storage;\n\n try {\n storage = window[type];\n\n const x = `__${type}__`;\n storage.setItem(x, x);\n storage.removeItem(x);\n\n return true;\n } catch (e) {\n return e instanceof DOMException && e.name === 'QuotaExceededError' && !!storage && storage.length !== 0;\n }\n}\n"],"names":["storageAvailable","type","storage","window","x","setItem","removeItem","e","DOMException","name","length"],"mappings":";;AAAA;AACA;AACA;AACO,SAASA,gBAAgBA,CAACC,IAAuC,EAAW;AACjF,EAAA,IAAIC,OAAO;EAEX,IAAI;AACFA,IAAAA,OAAO,GAAGC,MAAM,CAACF,IAAI,CAAC;AAEtB,IAAA,MAAMG,CAAC,GAAG,CAAA,EAAA,EAAKH,IAAI,CAAA,EAAA,CAAI;AACvBC,IAAAA,OAAO,CAACG,OAAO,CAACD,CAAC,EAAEA,CAAC,CAAC;AACrBF,IAAAA,OAAO,CAACI,UAAU,CAACF,CAAC,CAAC;AAErB,IAAA,OAAO,IAAI;EACb,CAAC,CAAC,OAAOG,CAAC,EAAE;AACV,IAAA,OAAOA,CAAC,YAAYC,YAAY,IAAID,CAAC,CAACE,IAAI,KAAK,oBAAoB,IAAI,CAAC,CAACP,OAAO,IAAIA,OAAO,CAACQ,MAAM,KAAK,CAAC;AAC1G,EAAA;AACF;;"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Web_Storage_API/Using_the_Web_Storage_API#feature-detecting_localstorage MDN}
|
|
3
|
+
*/
|
|
4
|
+
function storageAvailable(type) {
|
|
5
|
+
let storage;
|
|
6
|
+
try {
|
|
7
|
+
storage = window[type];
|
|
8
|
+
const x = `__${type}__`;
|
|
9
|
+
storage.setItem(x, x);
|
|
10
|
+
storage.removeItem(x);
|
|
11
|
+
return true;
|
|
12
|
+
} catch (e) {
|
|
13
|
+
return e instanceof DOMException && e.name === 'QuotaExceededError' && !!storage && storage.length !== 0;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export { storageAvailable };
|
|
18
|
+
//# sourceMappingURL=storage-available.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"storage-available.js","sources":["../src/storage-available.ts"],"sourcesContent":["/**\n * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Web_Storage_API/Using_the_Web_Storage_API#feature-detecting_localstorage MDN}\n */\nexport function storageAvailable(type: 'localStorage' | 'sessionStorage'): boolean {\n let storage;\n\n try {\n storage = window[type];\n\n const x = `__${type}__`;\n storage.setItem(x, x);\n storage.removeItem(x);\n\n return true;\n } catch (e) {\n return e instanceof DOMException && e.name === 'QuotaExceededError' && !!storage && storage.length !== 0;\n }\n}\n"],"names":["storageAvailable","type","storage","window","x","setItem","removeItem","e","DOMException","name","length"],"mappings":"AAAA;AACA;AACA;AACO,SAASA,gBAAgBA,CAACC,IAAuC,EAAW;AACjF,EAAA,IAAIC,OAAO;EAEX,IAAI;AACFA,IAAAA,OAAO,GAAGC,MAAM,CAACF,IAAI,CAAC;AAEtB,IAAA,MAAMG,CAAC,GAAG,CAAA,EAAA,EAAKH,IAAI,CAAA,EAAA,CAAI;AACvBC,IAAAA,OAAO,CAACG,OAAO,CAACD,CAAC,EAAEA,CAAC,CAAC;AACrBF,IAAAA,OAAO,CAACI,UAAU,CAACF,CAAC,CAAC;AAErB,IAAA,OAAO,IAAI;EACb,CAAC,CAAC,OAAOG,CAAC,EAAE;AACV,IAAA,OAAOA,CAAC,YAAYC,YAAY,IAAID,CAAC,CAACE,IAAI,KAAK,oBAAoB,IAAI,CAAC,CAACP,OAAO,IAAIA,OAAO,CAACQ,MAAM,KAAK,CAAC;AAC1G,EAAA;AACF;;"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,24 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mado/utils",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.1",
|
|
4
|
+
"homepage": "https://github.com/doinki/mado/tree/main/packages/mado-utils#readme",
|
|
5
|
+
"bugs": "https://github.com/doinki/mado/issues",
|
|
4
6
|
"license": "MIT",
|
|
7
|
+
"author": {
|
|
8
|
+
"name": "doinki",
|
|
9
|
+
"email": "doinki94@gmail.com",
|
|
10
|
+
"url": "https://github.com/doinki"
|
|
11
|
+
},
|
|
12
|
+
"repository": {
|
|
13
|
+
"type": "git",
|
|
14
|
+
"url": "git+https://github.com/doinki/mado.git",
|
|
15
|
+
"directory": "packages/mado-utils"
|
|
16
|
+
},
|
|
17
|
+
"files": [
|
|
18
|
+
"dist"
|
|
19
|
+
],
|
|
20
|
+
"type": "module",
|
|
21
|
+
"sideEffects": false,
|
|
5
22
|
"main": "./dist/index.cjs",
|
|
6
23
|
"module": "./dist/index.js",
|
|
7
24
|
"types": "./dist/index.d.ts",
|
|
@@ -18,31 +35,21 @@
|
|
|
18
35
|
},
|
|
19
36
|
"./package.json": "./package.json"
|
|
20
37
|
},
|
|
21
|
-
"
|
|
22
|
-
"
|
|
23
|
-
"name": "doinki",
|
|
24
|
-
"url": "https://github.com/doinki"
|
|
38
|
+
"publishConfig": {
|
|
39
|
+
"access": "public"
|
|
25
40
|
},
|
|
26
|
-
"
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
"
|
|
31
|
-
|
|
32
|
-
"homepage": "https://github.com/doinki/mado/tree/main/packages/mado-utils#readme",
|
|
33
|
-
"repository": {
|
|
34
|
-
"directory": "packages/mado-utils",
|
|
35
|
-
"type": "git",
|
|
36
|
-
"url": "https://github.com/doinki/mado.git"
|
|
41
|
+
"dependencies": {
|
|
42
|
+
"@babel/runtime": "^7.29.10"
|
|
43
|
+
},
|
|
44
|
+
"devDependencies": {
|
|
45
|
+
"@vitest/coverage-istanbul": "^5.0.5",
|
|
46
|
+
"happy-dom": "^21.0.3"
|
|
37
47
|
},
|
|
38
|
-
"sideEffects": false,
|
|
39
|
-
"type": "module",
|
|
40
48
|
"scripts": {
|
|
41
|
-
"build": "
|
|
49
|
+
"build": "rimraf dist && rollup -c --environment NODE_ENV:production",
|
|
42
50
|
"test": "vitest run",
|
|
43
51
|
"test:coverage": "vitest run --coverage",
|
|
44
|
-
"lint": "eslint .",
|
|
45
52
|
"publint": "publint",
|
|
46
|
-
"typecheck": "tsc"
|
|
53
|
+
"typecheck": "tsc --noEmit"
|
|
47
54
|
}
|
|
48
55
|
}
|
package/CHANGELOG.md
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
# @mado/utils
|
|
2
|
-
|
|
3
|
-
## 0.3.0
|
|
4
|
-
|
|
5
|
-
### Minor Changes
|
|
6
|
-
|
|
7
|
-
- 7da15aa: Add isObjectLike and isPlainObject functions
|
|
8
|
-
|
|
9
|
-
## 0.2.0
|
|
10
|
-
|
|
11
|
-
### Minor Changes
|
|
12
|
-
|
|
13
|
-
- ce252f2: - Add capitalize function
|
|
14
|
-
- Add isNil function
|
|
15
|
-
|
|
16
|
-
## 0.1.0
|
|
17
|
-
|
|
18
|
-
### Minor Changes
|
|
19
|
-
|
|
20
|
-
- 2fcb4c0: feat(utils): Add storageAvailable function
|
|
21
|
-
|
|
22
|
-
## 0.0.1
|
|
23
|
-
|
|
24
|
-
### Patch Changes
|
|
25
|
-
|
|
26
|
-
- d2e133c: feat(utils): 🎉
|
package/dist/isNil.cjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/isNil.ts"],"names":[],"mappings":";AAAO,SAAS,MAAM,OAA2C;AAC/D,SAAO,SAAS;AAClB","sourcesContent":["export function isNil(value: unknown): value is null | undefined {\n return value == null;\n}\n"]}
|
package/dist/isNil.js
DELETED
package/dist/isNil.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/isNil.ts"],"names":[],"mappings":";AAAO,SAAS,MAAM,OAA2C;AAC/D,SAAO,SAAS;AAClB","sourcesContent":["export function isNil(value: unknown): value is null | undefined {\n return value == null;\n}\n"]}
|
package/dist/isObjectLike.cjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/isObjectLike.ts"],"names":[],"mappings":";AAAO,SAAS,aAAa,OAAiC;AAC5D,SAAO,OAAO,UAAU,YAAY,UAAU;AAChD","sourcesContent":["export function isObjectLike(value: unknown): value is object {\n return typeof value === 'object' && value !== null;\n}\n"]}
|
package/dist/isObjectLike.js
DELETED
package/dist/isObjectLike.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/isObjectLike.ts"],"names":[],"mappings":";AAAO,SAAS,aAAa,OAAiC;AAC5D,SAAO,OAAO,UAAU,YAAY,UAAU;AAChD","sourcesContent":["export function isObjectLike(value: unknown): value is object {\n return typeof value === 'object' && value !== null;\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/isPlainObject.ts"],"names":[],"mappings":";AAAA,SAAS,oBAAoB;AAEtB,SAAS,cAAgC,OAA4B;AAC1E,MAAI,CAAC,aAAa,KAAK,GAAG;AACxB,WAAO;AAAA,EACT;AAEA,QAAM,YAAY,OAAO,eAAe,KAAK;AAE7C,UACG,cAAc,QACb,cAAc,OAAO,aACrB,OAAO,eAAe,SAAS,MAAM,SACvC,EAAE,OAAO,eAAe,UACxB,EAAE,OAAO,YAAY;AAEzB","sourcesContent":["import { isObjectLike } from './isObjectLike';\n\nexport function isPlainObject<T extends object>(value: unknown): value is T {\n if (!isObjectLike(value)) {\n return false;\n }\n\n const prototype = Object.getPrototypeOf(value);\n\n return (\n (prototype === null ||\n prototype === Object.prototype ||\n Object.getPrototypeOf(prototype) === null) &&\n !(Symbol.toStringTag in value) &&\n !(Symbol.iterator in value)\n );\n}\n"]}
|
package/dist/isPlainObject.d.cts
DELETED
package/dist/isPlainObject.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/isPlainObject.ts"],"names":[],"mappings":";AAAA,SAAS,oBAAoB;AAEtB,SAAS,cAAgC,OAA4B;AAC1E,MAAI,CAAC,aAAa,KAAK,GAAG;AACxB,WAAO;AAAA,EACT;AAEA,QAAM,YAAY,OAAO,eAAe,KAAK;AAE7C,UACG,cAAc,QACb,cAAc,OAAO,aACrB,OAAO,eAAe,SAAS,MAAM,SACvC,EAAE,OAAO,eAAe,UACxB,EAAE,OAAO,YAAY;AAEzB","sourcesContent":["import { isObjectLike } from './isObjectLike';\n\nexport function isPlainObject<T extends object>(value: unknown): value is T {\n if (!isObjectLike(value)) {\n return false;\n }\n\n const prototype = Object.getPrototypeOf(value);\n\n return (\n (prototype === null ||\n prototype === Object.prototype ||\n Object.getPrototypeOf(prototype) === null) &&\n !(Symbol.toStringTag in value) &&\n !(Symbol.iterator in value)\n );\n}\n"]}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
// src/storageAvailable.ts
|
|
4
|
-
function storageAvailable(type) {
|
|
5
|
-
let storage;
|
|
6
|
-
try {
|
|
7
|
-
storage = window[type];
|
|
8
|
-
const x = "__storage_test__";
|
|
9
|
-
storage.setItem(x, x);
|
|
10
|
-
storage.removeItem(x);
|
|
11
|
-
return true;
|
|
12
|
-
} catch (e) {
|
|
13
|
-
return e instanceof DOMException && // everything except Firefox
|
|
14
|
-
(e.code === 22 || // Firefox
|
|
15
|
-
e.code === 1014 || // test name field too, because code might not be present
|
|
16
|
-
// everything except Firefox
|
|
17
|
-
e.name === "QuotaExceededError" || // Firefox
|
|
18
|
-
e.name === "NS_ERROR_DOM_QUOTA_REACHED") && // acknowledge QuotaExceededError only if there's something already stored
|
|
19
|
-
!!storage && storage.length !== 0;
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
exports.storageAvailable = storageAvailable;
|
|
24
|
-
//# sourceMappingURL=out.js.map
|
|
25
|
-
//# sourceMappingURL=storageAvailable.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/storageAvailable.ts"],"names":[],"mappings":";AAGO,SAAS,iBACd,MACS;AACT,MAAI;AAEJ,MAAI;AACF,cAAU,OAAO,IAAI;AACrB,UAAM,IAAI;AACV,YAAQ,QAAQ,GAAG,CAAC;AACpB,YAAQ,WAAW,CAAC;AAEpB,WAAO;AAAA,EACT,SAAS,GAAG;AACV,WACE,aAAa;AAAA,KAEZ,EAAE,SAAS;AAAA,IAEV,EAAE,SAAS;AAAA;AAAA,IAGX,EAAE,SAAS;AAAA,IAEX,EAAE,SAAS;AAAA,IAEb,CAAC,CAAC,WACF,QAAQ,WAAW;AAAA,EAEvB;AACF","sourcesContent":["/**\n * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Web_Storage_API/Using_the_Web_Storage_API#feature-detecting_localstorage MDN}\n */\nexport function storageAvailable(\n type: 'localStorage' | 'sessionStorage',\n): boolean {\n let storage;\n\n try {\n storage = window[type];\n const x = '__storage_test__';\n storage.setItem(x, x);\n storage.removeItem(x);\n\n return true;\n } catch (e) {\n return (\n e instanceof DOMException &&\n // everything except Firefox\n (e.code === 22 ||\n // Firefox\n e.code === 1014 ||\n // test name field too, because code might not be present\n // everything except Firefox\n e.name === 'QuotaExceededError' ||\n // Firefox\n e.name === 'NS_ERROR_DOM_QUOTA_REACHED') &&\n // acknowledge QuotaExceededError only if there's something already stored\n !!storage &&\n storage.length !== 0\n );\n }\n}\n"]}
|
package/dist/storageAvailable.js
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
// src/storageAvailable.ts
|
|
2
|
-
function storageAvailable(type) {
|
|
3
|
-
let storage;
|
|
4
|
-
try {
|
|
5
|
-
storage = window[type];
|
|
6
|
-
const x = "__storage_test__";
|
|
7
|
-
storage.setItem(x, x);
|
|
8
|
-
storage.removeItem(x);
|
|
9
|
-
return true;
|
|
10
|
-
} catch (e) {
|
|
11
|
-
return e instanceof DOMException && // everything except Firefox
|
|
12
|
-
(e.code === 22 || // Firefox
|
|
13
|
-
e.code === 1014 || // test name field too, because code might not be present
|
|
14
|
-
// everything except Firefox
|
|
15
|
-
e.name === "QuotaExceededError" || // Firefox
|
|
16
|
-
e.name === "NS_ERROR_DOM_QUOTA_REACHED") && // acknowledge QuotaExceededError only if there's something already stored
|
|
17
|
-
!!storage && storage.length !== 0;
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export { storageAvailable };
|
|
22
|
-
//# sourceMappingURL=out.js.map
|
|
23
|
-
//# sourceMappingURL=storageAvailable.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/storageAvailable.ts"],"names":[],"mappings":";AAGO,SAAS,iBACd,MACS;AACT,MAAI;AAEJ,MAAI;AACF,cAAU,OAAO,IAAI;AACrB,UAAM,IAAI;AACV,YAAQ,QAAQ,GAAG,CAAC;AACpB,YAAQ,WAAW,CAAC;AAEpB,WAAO;AAAA,EACT,SAAS,GAAG;AACV,WACE,aAAa;AAAA,KAEZ,EAAE,SAAS;AAAA,IAEV,EAAE,SAAS;AAAA;AAAA,IAGX,EAAE,SAAS;AAAA,IAEX,EAAE,SAAS;AAAA,IAEb,CAAC,CAAC,WACF,QAAQ,WAAW;AAAA,EAEvB;AACF","sourcesContent":["/**\n * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Web_Storage_API/Using_the_Web_Storage_API#feature-detecting_localstorage MDN}\n */\nexport function storageAvailable(\n type: 'localStorage' | 'sessionStorage',\n): boolean {\n let storage;\n\n try {\n storage = window[type];\n const x = '__storage_test__';\n storage.setItem(x, x);\n storage.removeItem(x);\n\n return true;\n } catch (e) {\n return (\n e instanceof DOMException &&\n // everything except Firefox\n (e.code === 22 ||\n // Firefox\n e.code === 1014 ||\n // test name field too, because code might not be present\n // everything except Firefox\n e.name === 'QuotaExceededError' ||\n // Firefox\n e.name === 'NS_ERROR_DOM_QUOTA_REACHED') &&\n // acknowledge QuotaExceededError only if there's something already stored\n !!storage &&\n storage.length !== 0\n );\n }\n}\n"]}
|
package/src/capitalize.ts
DELETED
package/src/debounce.ts
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
export interface Cancelable {
|
|
2
|
-
cancel: () => void;
|
|
3
|
-
}
|
|
4
|
-
|
|
5
|
-
export function debounce<T extends (...args: any[]) => any>(
|
|
6
|
-
func: T,
|
|
7
|
-
wait = 166,
|
|
8
|
-
): T & Cancelable {
|
|
9
|
-
let timeout: ReturnType<typeof setTimeout>;
|
|
10
|
-
|
|
11
|
-
function debounced(...args: Parameters<T>) {
|
|
12
|
-
clearTimeout(timeout);
|
|
13
|
-
|
|
14
|
-
timeout = setTimeout(() => {
|
|
15
|
-
// @ts-ignore
|
|
16
|
-
func.apply(this, args);
|
|
17
|
-
}, wait);
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
debounced.cancel = () => {
|
|
21
|
-
clearTimeout(timeout);
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
return debounced as T & Cancelable;
|
|
25
|
-
}
|
package/src/index.ts
DELETED
package/src/isNil.ts
DELETED
package/src/isObjectLike.ts
DELETED
package/src/isPlainObject.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { isObjectLike } from './isObjectLike';
|
|
2
|
-
|
|
3
|
-
export function isPlainObject<T extends object>(value: unknown): value is T {
|
|
4
|
-
if (!isObjectLike(value)) {
|
|
5
|
-
return false;
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
const prototype = Object.getPrototypeOf(value);
|
|
9
|
-
|
|
10
|
-
return (
|
|
11
|
-
(prototype === null ||
|
|
12
|
-
prototype === Object.prototype ||
|
|
13
|
-
Object.getPrototypeOf(prototype) === null) &&
|
|
14
|
-
!(Symbol.toStringTag in value) &&
|
|
15
|
-
!(Symbol.iterator in value)
|
|
16
|
-
);
|
|
17
|
-
}
|
package/src/storageAvailable.ts
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Web_Storage_API/Using_the_Web_Storage_API#feature-detecting_localstorage MDN}
|
|
3
|
-
*/
|
|
4
|
-
export function storageAvailable(
|
|
5
|
-
type: 'localStorage' | 'sessionStorage',
|
|
6
|
-
): boolean {
|
|
7
|
-
let storage;
|
|
8
|
-
|
|
9
|
-
try {
|
|
10
|
-
storage = window[type];
|
|
11
|
-
const x = '__storage_test__';
|
|
12
|
-
storage.setItem(x, x);
|
|
13
|
-
storage.removeItem(x);
|
|
14
|
-
|
|
15
|
-
return true;
|
|
16
|
-
} catch (e) {
|
|
17
|
-
return (
|
|
18
|
-
e instanceof DOMException &&
|
|
19
|
-
// everything except Firefox
|
|
20
|
-
(e.code === 22 ||
|
|
21
|
-
// Firefox
|
|
22
|
-
e.code === 1014 ||
|
|
23
|
-
// test name field too, because code might not be present
|
|
24
|
-
// everything except Firefox
|
|
25
|
-
e.name === 'QuotaExceededError' ||
|
|
26
|
-
// Firefox
|
|
27
|
-
e.name === 'NS_ERROR_DOM_QUOTA_REACHED') &&
|
|
28
|
-
// acknowledge QuotaExceededError only if there's something already stored
|
|
29
|
-
!!storage &&
|
|
30
|
-
storage.length !== 0
|
|
31
|
-
);
|
|
32
|
-
}
|
|
33
|
-
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|