@mado/utils 0.2.0 → 0.4.0
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 -1
- package/dist/capitalize.cjs.map +1 -1
- package/dist/capitalize.js +1 -1
- package/dist/capitalize.js.map +1 -1
- package/dist/debounce.cjs +1 -1
- package/dist/debounce.cjs.map +1 -1
- package/dist/debounce.js +1 -1
- package/dist/debounce.js.map +1 -1
- package/dist/index.cjs +31 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +6 -2
- package/dist/index.d.ts +6 -2
- package/dist/index.js +7 -3
- package/dist/index.js.map +1 -1
- package/dist/invariant.cjs +32 -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 +27 -0
- package/dist/invariant.js.map +1 -0
- package/dist/{isNil.cjs → is-nil.cjs} +3 -3
- package/dist/is-nil.cjs.map +1 -0
- package/dist/is-nil.js +8 -0
- package/dist/is-nil.js.map +1 -0
- package/dist/is-object-like.cjs +10 -0
- package/dist/is-object-like.cjs.map +1 -0
- package/dist/is-object-like.d.cts +3 -0
- package/dist/is-object-like.d.ts +3 -0
- package/dist/is-object-like.js +8 -0
- package/dist/is-object-like.js.map +1 -0
- package/dist/is-plain-object.cjs +16 -0
- 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/is-plain-object.js +14 -0
- package/dist/is-plain-object.js.map +1 -0
- package/dist/remember.cjs +17 -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 +15 -0
- package/dist/remember.js.map +1 -0
- package/dist/storage-available.cjs +19 -0
- package/dist/storage-available.cjs.map +1 -0
- package/dist/storage-available.js +17 -0
- package/dist/storage-available.js.map +1 -0
- package/package.json +10 -9
- package/CHANGELOG.md +0 -20
- package/dist/isNil.cjs.map +0 -1
- package/dist/isNil.js +0 -8
- package/dist/isNil.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 -4
- package/src/isNil.ts +0 -3
- 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/{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
package/dist/capitalize.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/capitalize.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../src/capitalize.ts"],"names":[],"mappings":";;;AAAO,SAAS,WAAW,GAAA,EAAqB;AAC9C,EAAA,OAAO,GAAA,CAAI,OAAO,CAAC,CAAA,CAAE,aAAY,GAAI,GAAA,CAAI,UAAU,CAAC,CAAA;AACtD","file":"capitalize.cjs","sourcesContent":["export function capitalize(str: string): string {\n return str.charAt(0).toUpperCase() + str.substring(1);\n}\n"]}
|
package/dist/capitalize.js
CHANGED
package/dist/capitalize.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/capitalize.ts"],"names":[],"mappings":";AAAO,SAAS,WAAW,
|
|
1
|
+
{"version":3,"sources":["../src/capitalize.ts"],"names":[],"mappings":";AAAO,SAAS,WAAW,GAAA,EAAqB;AAC9C,EAAA,OAAO,GAAA,CAAI,OAAO,CAAC,CAAA,CAAE,aAAY,GAAI,GAAA,CAAI,UAAU,CAAC,CAAA;AACtD","file":"capitalize.js","sourcesContent":["export function capitalize(str: string): string {\n return str.charAt(0).toUpperCase() + str.substring(1);\n}\n"]}
|
package/dist/debounce.cjs
CHANGED
package/dist/debounce.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/debounce.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../src/debounce.ts"],"names":[],"mappings":";;;AAIO,SAAS,QAAA,CAA4C,IAAA,EAAS,IAAA,GAAO,GAAA,EAAqB;AAC/F,EAAA,IAAI,OAAA;AAEJ,EAAA,SAAS,aAAa,IAAA,EAAqB;AACzC,IAAA,YAAA,CAAa,OAAO,CAAA;AAEpB,IAAA,OAAA,GAAU,WAAW,MAAM;AAEzB,MAAA,IAAA,CAAK,KAAA,CAAM,MAAM,IAAI,CAAA;AAAA,IACvB,GAAG,IAAI,CAAA;AAAA,EACT;AAEA,EAAA,SAAA,CAAU,SAAS,MAAM;AACvB,IAAA,YAAA,CAAa,OAAO,CAAA;AAAA,EACtB,CAAA;AAEA,EAAA,OAAO,SAAA;AACT","file":"debounce.cjs","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"]}
|
package/dist/debounce.js
CHANGED
package/dist/debounce.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/debounce.ts"],"names":[],"mappings":";AAIO,SAAS,
|
|
1
|
+
{"version":3,"sources":["../src/debounce.ts"],"names":[],"mappings":";AAIO,SAAS,QAAA,CAA4C,IAAA,EAAS,IAAA,GAAO,GAAA,EAAqB;AAC/F,EAAA,IAAI,OAAA;AAEJ,EAAA,SAAS,aAAa,IAAA,EAAqB;AACzC,IAAA,YAAA,CAAa,OAAO,CAAA;AAEpB,IAAA,OAAA,GAAU,WAAW,MAAM;AAEzB,MAAA,IAAA,CAAK,KAAA,CAAM,MAAM,IAAI,CAAA;AAAA,IACvB,GAAG,IAAI,CAAA;AAAA,EACT;AAEA,EAAA,SAAA,CAAU,SAAS,MAAM;AACvB,IAAA,YAAA,CAAa,OAAO,CAAA;AAAA,EACtB,CAAA;AAEA,EAAA,OAAO,SAAA;AACT","file":"debounce.js","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"]}
|
package/dist/index.cjs
CHANGED
|
@@ -2,8 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
var capitalize_cjs = require('./capitalize.cjs');
|
|
4
4
|
var debounce_cjs = require('./debounce.cjs');
|
|
5
|
-
var
|
|
6
|
-
var
|
|
5
|
+
var invariant_cjs = require('./invariant.cjs');
|
|
6
|
+
var isNil_cjs = require('./is-nil.cjs');
|
|
7
|
+
var isObjectLike_cjs = require('./is-object-like.cjs');
|
|
8
|
+
var isPlainObject_cjs = require('./is-plain-object.cjs');
|
|
9
|
+
var remember_cjs = require('./remember.cjs');
|
|
10
|
+
var storageAvailable_cjs = require('./storage-available.cjs');
|
|
7
11
|
|
|
8
12
|
|
|
9
13
|
|
|
@@ -19,17 +23,41 @@ Object.keys(debounce_cjs).forEach(function (k) {
|
|
|
19
23
|
get: function () { return debounce_cjs[k]; }
|
|
20
24
|
});
|
|
21
25
|
});
|
|
26
|
+
Object.keys(invariant_cjs).forEach(function (k) {
|
|
27
|
+
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
28
|
+
enumerable: true,
|
|
29
|
+
get: function () { return invariant_cjs[k]; }
|
|
30
|
+
});
|
|
31
|
+
});
|
|
22
32
|
Object.keys(isNil_cjs).forEach(function (k) {
|
|
23
33
|
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
24
34
|
enumerable: true,
|
|
25
35
|
get: function () { return isNil_cjs[k]; }
|
|
26
36
|
});
|
|
27
37
|
});
|
|
38
|
+
Object.keys(isObjectLike_cjs).forEach(function (k) {
|
|
39
|
+
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
40
|
+
enumerable: true,
|
|
41
|
+
get: function () { return isObjectLike_cjs[k]; }
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
Object.keys(isPlainObject_cjs).forEach(function (k) {
|
|
45
|
+
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
46
|
+
enumerable: true,
|
|
47
|
+
get: function () { return isPlainObject_cjs[k]; }
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
Object.keys(remember_cjs).forEach(function (k) {
|
|
51
|
+
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
52
|
+
enumerable: true,
|
|
53
|
+
get: function () { return remember_cjs[k]; }
|
|
54
|
+
});
|
|
55
|
+
});
|
|
28
56
|
Object.keys(storageAvailable_cjs).forEach(function (k) {
|
|
29
57
|
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
30
58
|
enumerable: true,
|
|
31
59
|
get: function () { return storageAvailable_cjs[k]; }
|
|
32
60
|
});
|
|
33
61
|
});
|
|
34
|
-
//# sourceMappingURL=
|
|
62
|
+
//# sourceMappingURL=index.cjs.map
|
|
35
63
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":[
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"index.cjs","sourcesContent":[]}
|
package/dist/index.d.cts
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
export { capitalize } from './capitalize.cjs';
|
|
2
2
|
export { Cancelable, debounce } from './debounce.cjs';
|
|
3
|
-
export {
|
|
4
|
-
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,4 +1,8 @@
|
|
|
1
1
|
export { capitalize } from './capitalize.js';
|
|
2
2
|
export { Cancelable, debounce } from './debounce.js';
|
|
3
|
-
export {
|
|
4
|
-
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,6 +1,10 @@
|
|
|
1
1
|
export * from './capitalize.js';
|
|
2
2
|
export * from './debounce.js';
|
|
3
|
-
export * from './
|
|
4
|
-
export * from './
|
|
5
|
-
|
|
3
|
+
export * from './invariant.js';
|
|
4
|
+
export * from './is-nil.js';
|
|
5
|
+
export * from './is-object-like.js';
|
|
6
|
+
export * from './is-plain-object.js';
|
|
7
|
+
export * from './remember.js';
|
|
8
|
+
export * from './storage-available.js';
|
|
9
|
+
//# sourceMappingURL=index.js.map
|
|
6
10
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":[
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"index.js","sourcesContent":[]}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// src/invariant.ts
|
|
4
|
+
var InvariantError = class extends Error {
|
|
5
|
+
constructor(message) {
|
|
6
|
+
super(message);
|
|
7
|
+
this.name = "InvariantError";
|
|
8
|
+
}
|
|
9
|
+
};
|
|
10
|
+
function isInvariantError(error) {
|
|
11
|
+
return error instanceof InvariantError;
|
|
12
|
+
}
|
|
13
|
+
function invariant(condition, message) {
|
|
14
|
+
if (!condition) {
|
|
15
|
+
throw new InvariantError(typeof message === "function" ? message() : message);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
function invariantResponse(condition, message, responseInit) {
|
|
19
|
+
if (!condition) {
|
|
20
|
+
throw new Response(typeof message === "function" ? message() : message, {
|
|
21
|
+
status: 400,
|
|
22
|
+
...responseInit
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
exports.InvariantError = InvariantError;
|
|
28
|
+
exports.invariant = invariant;
|
|
29
|
+
exports.invariantResponse = invariantResponse;
|
|
30
|
+
exports.isInvariantError = isInvariantError;
|
|
31
|
+
//# sourceMappingURL=invariant.cjs.map
|
|
32
|
+
//# sourceMappingURL=invariant.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/invariant.ts"],"names":[],"mappings":";;;AAAO,IAAM,cAAA,GAAN,cAA6B,KAAA,CAAM;AAAA,EACxC,YAAY,OAAA,EAAiB;AAC3B,IAAA,KAAA,CAAM,OAAO,CAAA;AAEb,IAAA,IAAA,CAAK,IAAA,GAAO,gBAAA;AAAA,EACd;AACF;AAEO,SAAS,iBAAiB,KAAA,EAAyC;AACxE,EAAA,OAAO,KAAA,YAAiB,cAAA;AAC1B;AAKO,SAAS,SAAA,CAAU,WAAoB,OAAA,EAAqD;AACjG,EAAA,IAAI,CAAC,SAAA,EAAW;AACd,IAAA,MAAM,IAAI,cAAA,CAAe,OAAO,YAAY,UAAA,GAAa,OAAA,KAAY,OAAO,CAAA;AAAA,EAC9E;AACF;AAKO,SAAS,iBAAA,CACd,SAAA,EACA,OAAA,EACA,YAAA,EACmB;AACnB,EAAA,IAAI,CAAC,SAAA,EAAW;AAEd,IAAA,MAAM,IAAI,QAAA,CAAS,OAAO,YAAY,UAAA,GAAa,OAAA,KAAY,OAAA,EAAS;AAAA,MACtE,MAAA,EAAQ,GAAA;AAAA,MACR,GAAG;AAAA,KACJ,CAAA;AAAA,EACH;AACF","file":"invariant.cjs","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"]}
|
|
@@ -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,27 @@
|
|
|
1
|
+
// src/invariant.ts
|
|
2
|
+
var InvariantError = class extends Error {
|
|
3
|
+
constructor(message) {
|
|
4
|
+
super(message);
|
|
5
|
+
this.name = "InvariantError";
|
|
6
|
+
}
|
|
7
|
+
};
|
|
8
|
+
function isInvariantError(error) {
|
|
9
|
+
return error instanceof InvariantError;
|
|
10
|
+
}
|
|
11
|
+
function invariant(condition, message) {
|
|
12
|
+
if (!condition) {
|
|
13
|
+
throw new InvariantError(typeof message === "function" ? message() : message);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
function invariantResponse(condition, message, responseInit) {
|
|
17
|
+
if (!condition) {
|
|
18
|
+
throw new Response(typeof message === "function" ? message() : message, {
|
|
19
|
+
status: 400,
|
|
20
|
+
...responseInit
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export { InvariantError, invariant, invariantResponse, isInvariantError };
|
|
26
|
+
//# sourceMappingURL=invariant.js.map
|
|
27
|
+
//# sourceMappingURL=invariant.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/invariant.ts"],"names":[],"mappings":";AAAO,IAAM,cAAA,GAAN,cAA6B,KAAA,CAAM;AAAA,EACxC,YAAY,OAAA,EAAiB;AAC3B,IAAA,KAAA,CAAM,OAAO,CAAA;AAEb,IAAA,IAAA,CAAK,IAAA,GAAO,gBAAA;AAAA,EACd;AACF;AAEO,SAAS,iBAAiB,KAAA,EAAyC;AACxE,EAAA,OAAO,KAAA,YAAiB,cAAA;AAC1B;AAKO,SAAS,SAAA,CAAU,WAAoB,OAAA,EAAqD;AACjG,EAAA,IAAI,CAAC,SAAA,EAAW;AACd,IAAA,MAAM,IAAI,cAAA,CAAe,OAAO,YAAY,UAAA,GAAa,OAAA,KAAY,OAAO,CAAA;AAAA,EAC9E;AACF;AAKO,SAAS,iBAAA,CACd,SAAA,EACA,OAAA,EACA,YAAA,EACmB;AACnB,EAAA,IAAI,CAAC,SAAA,EAAW;AAEd,IAAA,MAAM,IAAI,QAAA,CAAS,OAAO,YAAY,UAAA,GAAa,OAAA,KAAY,OAAA,EAAS;AAAA,MACtE,MAAA,EAAQ,GAAA;AAAA,MACR,GAAG;AAAA,KACJ,CAAA;AAAA,EACH;AACF","file":"invariant.js","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"]}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
// src/
|
|
3
|
+
// src/is-nil.ts
|
|
4
4
|
function isNil(value) {
|
|
5
5
|
return value == null;
|
|
6
6
|
}
|
|
7
7
|
|
|
8
8
|
exports.isNil = isNil;
|
|
9
|
-
//# sourceMappingURL=
|
|
10
|
-
//# sourceMappingURL=
|
|
9
|
+
//# sourceMappingURL=is-nil.cjs.map
|
|
10
|
+
//# sourceMappingURL=is-nil.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/is-nil.ts"],"names":[],"mappings":";;;AAAO,SAAS,MAAM,KAAA,EAA2C;AAC/D,EAAA,OAAO,KAAA,IAAS,IAAA;AAClB","file":"is-nil.cjs","sourcesContent":["export function isNil(value: unknown): value is null | undefined {\n return value == null;\n}\n"]}
|
package/dist/is-nil.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/is-nil.ts"],"names":[],"mappings":";AAAO,SAAS,MAAM,KAAA,EAA2C;AAC/D,EAAA,OAAO,KAAA,IAAS,IAAA;AAClB","file":"is-nil.js","sourcesContent":["export function isNil(value: unknown): value is null | undefined {\n return value == null;\n}\n"]}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// src/is-object-like.ts
|
|
4
|
+
function isObjectLike(value) {
|
|
5
|
+
return typeof value === "object" && value !== null;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
exports.isObjectLike = isObjectLike;
|
|
9
|
+
//# sourceMappingURL=is-object-like.cjs.map
|
|
10
|
+
//# sourceMappingURL=is-object-like.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/is-object-like.ts"],"names":[],"mappings":";;;AAAO,SAAS,aAAa,KAAA,EAAiC;AAC5D,EAAA,OAAO,OAAO,KAAA,KAAU,QAAA,IAAY,KAAA,KAAU,IAAA;AAChD","file":"is-object-like.cjs","sourcesContent":["export function isObjectLike(value: unknown): value is object {\n return typeof value === 'object' && value !== null;\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/is-object-like.ts"],"names":[],"mappings":";AAAO,SAAS,aAAa,KAAA,EAAiC;AAC5D,EAAA,OAAO,OAAO,KAAA,KAAU,QAAA,IAAY,KAAA,KAAU,IAAA;AAChD","file":"is-object-like.js","sourcesContent":["export function isObjectLike(value: unknown): value is object {\n return typeof value === 'object' && value !== null;\n}\n"]}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var isObjectLike_cjs = require('./is-object-like.cjs');
|
|
4
|
+
|
|
5
|
+
// src/is-plain-object.ts
|
|
6
|
+
function isPlainObject(value) {
|
|
7
|
+
if (!isObjectLike_cjs.isObjectLike(value)) {
|
|
8
|
+
return false;
|
|
9
|
+
}
|
|
10
|
+
const prototype = Object.getPrototypeOf(value);
|
|
11
|
+
return (prototype === null || prototype === Object.prototype || Object.getPrototypeOf(prototype) === null) && !(Symbol.toStringTag in value) && !(Symbol.iterator in value);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
exports.isPlainObject = isPlainObject;
|
|
15
|
+
//# sourceMappingURL=is-plain-object.cjs.map
|
|
16
|
+
//# sourceMappingURL=is-plain-object.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/is-plain-object.ts"],"names":["isObjectLike"],"mappings":";;;;;AAEO,SAAS,cAAc,KAAA,EAAiC;AAC7D,EAAA,IAAI,CAACA,6BAAA,CAAa,KAAK,CAAA,EAAG;AACxB,IAAA,OAAO,KAAA;AAAA,EACT;AAEA,EAAA,MAAM,SAAA,GAAY,MAAA,CAAO,cAAA,CAAe,KAAK,CAAA;AAE7C,EAAA,OAAA,CACG,cAAc,IAAA,IAAQ,SAAA,KAAc,MAAA,CAAO,SAAA,IAAa,OAAO,cAAA,CAAe,SAAS,CAAA,KAAM,IAAA,KAC9F,EAAE,MAAA,CAAO,WAAA,IAAe,KAAA,CAAA,IACxB,EAAE,OAAO,QAAA,IAAY,KAAA,CAAA;AAEzB","file":"is-plain-object.cjs","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"]}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { isObjectLike } from './is-object-like.js';
|
|
2
|
+
|
|
3
|
+
// src/is-plain-object.ts
|
|
4
|
+
function isPlainObject(value) {
|
|
5
|
+
if (!isObjectLike(value)) {
|
|
6
|
+
return false;
|
|
7
|
+
}
|
|
8
|
+
const prototype = Object.getPrototypeOf(value);
|
|
9
|
+
return (prototype === null || prototype === Object.prototype || Object.getPrototypeOf(prototype) === null) && !(Symbol.toStringTag in value) && !(Symbol.iterator in value);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export { isPlainObject };
|
|
13
|
+
//# sourceMappingURL=is-plain-object.js.map
|
|
14
|
+
//# sourceMappingURL=is-plain-object.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/is-plain-object.ts"],"names":[],"mappings":";;;AAEO,SAAS,cAAc,KAAA,EAAiC;AAC7D,EAAA,IAAI,CAAC,YAAA,CAAa,KAAK,CAAA,EAAG;AACxB,IAAA,OAAO,KAAA;AAAA,EACT;AAEA,EAAA,MAAM,SAAA,GAAY,MAAA,CAAO,cAAA,CAAe,KAAK,CAAA;AAE7C,EAAA,OAAA,CACG,cAAc,IAAA,IAAQ,SAAA,KAAc,MAAA,CAAO,SAAA,IAAa,OAAO,cAAA,CAAe,SAAS,CAAA,KAAM,IAAA,KAC9F,EAAE,MAAA,CAAO,WAAA,IAAe,KAAA,CAAA,IACxB,EAAE,OAAO,QAAA,IAAY,KAAA,CAAA;AAEzB","file":"is-plain-object.js","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"]}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// src/remember.ts
|
|
4
|
+
function remember(name, getValue) {
|
|
5
|
+
const ctx = globalThis;
|
|
6
|
+
if (!ctx.__remember) {
|
|
7
|
+
ctx.__remember = /* @__PURE__ */ new Map();
|
|
8
|
+
}
|
|
9
|
+
if (!ctx.__remember.has(name)) {
|
|
10
|
+
ctx.__remember.set(name, getValue());
|
|
11
|
+
}
|
|
12
|
+
return ctx.__remember.get(name);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
exports.remember = remember;
|
|
16
|
+
//# sourceMappingURL=remember.cjs.map
|
|
17
|
+
//# sourceMappingURL=remember.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/remember.ts"],"names":[],"mappings":";;;AAKO,SAAS,QAAA,CAAY,MAAc,QAAA,EAAsB;AAC9D,EAAA,MAAM,GAAA,GAAM,UAAA;AAEZ,EAAA,IAAI,CAAC,IAAI,UAAA,EAAY;AACnB,IAAA,GAAA,CAAI,UAAA,uBAAiB,GAAA,EAAI;AAAA,EAC3B;AAEA,EAAA,IAAI,CAAC,GAAA,CAAI,UAAA,CAAW,GAAA,CAAI,IAAI,CAAA,EAAG;AAC7B,IAAA,GAAA,CAAI,UAAA,CAAW,GAAA,CAAI,IAAA,EAAM,QAAA,EAAU,CAAA;AAAA,EACrC;AAEA,EAAA,OAAO,GAAA,CAAI,UAAA,CAAW,GAAA,CAAI,IAAI,CAAA;AAChC","file":"remember.cjs","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"]}
|
package/dist/remember.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// src/remember.ts
|
|
2
|
+
function remember(name, getValue) {
|
|
3
|
+
const ctx = globalThis;
|
|
4
|
+
if (!ctx.__remember) {
|
|
5
|
+
ctx.__remember = /* @__PURE__ */ new Map();
|
|
6
|
+
}
|
|
7
|
+
if (!ctx.__remember.has(name)) {
|
|
8
|
+
ctx.__remember.set(name, getValue());
|
|
9
|
+
}
|
|
10
|
+
return ctx.__remember.get(name);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export { remember };
|
|
14
|
+
//# sourceMappingURL=remember.js.map
|
|
15
|
+
//# sourceMappingURL=remember.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/remember.ts"],"names":[],"mappings":";AAKO,SAAS,QAAA,CAAY,MAAc,QAAA,EAAsB;AAC9D,EAAA,MAAM,GAAA,GAAM,UAAA;AAEZ,EAAA,IAAI,CAAC,IAAI,UAAA,EAAY;AACnB,IAAA,GAAA,CAAI,UAAA,uBAAiB,GAAA,EAAI;AAAA,EAC3B;AAEA,EAAA,IAAI,CAAC,GAAA,CAAI,UAAA,CAAW,GAAA,CAAI,IAAI,CAAA,EAAG;AAC7B,IAAA,GAAA,CAAI,UAAA,CAAW,GAAA,CAAI,IAAA,EAAM,QAAA,EAAU,CAAA;AAAA,EACrC;AAEA,EAAA,OAAO,GAAA,CAAI,UAAA,CAAW,GAAA,CAAI,IAAI,CAAA;AAChC","file":"remember.js","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"]}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// src/storage-available.ts
|
|
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
|
+
exports.storageAvailable = storageAvailable;
|
|
18
|
+
//# sourceMappingURL=storage-available.cjs.map
|
|
19
|
+
//# sourceMappingURL=storage-available.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/storage-available.ts"],"names":[],"mappings":";;;AAGO,SAAS,iBAAiB,IAAA,EAAkD;AACjF,EAAA,IAAI,OAAA;AAEJ,EAAA,IAAI;AACF,IAAA,OAAA,GAAU,OAAO,IAAI,CAAA;AAErB,IAAA,MAAM,CAAA,GAAI,KAAK,IAAI,CAAA,EAAA,CAAA;AACnB,IAAA,OAAA,CAAQ,OAAA,CAAQ,GAAG,CAAC,CAAA;AACpB,IAAA,OAAA,CAAQ,WAAW,CAAC,CAAA;AAEpB,IAAA,OAAO,IAAA;AAAA,EACT,SAAS,CAAA,EAAG;AACV,IAAA,OAAO,CAAA,YAAa,gBAAgB,CAAA,CAAE,IAAA,KAAS,wBAAwB,CAAC,CAAC,OAAA,IAAW,OAAA,CAAQ,MAAA,KAAW,CAAA;AAAA,EACzG;AACF","file":"storage-available.cjs","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"]}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// src/storage-available.ts
|
|
2
|
+
function storageAvailable(type) {
|
|
3
|
+
let storage;
|
|
4
|
+
try {
|
|
5
|
+
storage = window[type];
|
|
6
|
+
const x = `__${type}__`;
|
|
7
|
+
storage.setItem(x, x);
|
|
8
|
+
storage.removeItem(x);
|
|
9
|
+
return true;
|
|
10
|
+
} catch (e) {
|
|
11
|
+
return e instanceof DOMException && e.name === "QuotaExceededError" && !!storage && storage.length !== 0;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export { storageAvailable };
|
|
16
|
+
//# sourceMappingURL=storage-available.js.map
|
|
17
|
+
//# sourceMappingURL=storage-available.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/storage-available.ts"],"names":[],"mappings":";AAGO,SAAS,iBAAiB,IAAA,EAAkD;AACjF,EAAA,IAAI,OAAA;AAEJ,EAAA,IAAI;AACF,IAAA,OAAA,GAAU,OAAO,IAAI,CAAA;AAErB,IAAA,MAAM,CAAA,GAAI,KAAK,IAAI,CAAA,EAAA,CAAA;AACnB,IAAA,OAAA,CAAQ,OAAA,CAAQ,GAAG,CAAC,CAAA;AACpB,IAAA,OAAA,CAAQ,WAAW,CAAC,CAAA;AAEpB,IAAA,OAAO,IAAA;AAAA,EACT,SAAS,CAAA,EAAG;AACV,IAAA,OAAO,CAAA,YAAa,gBAAgB,CAAA,CAAE,IAAA,KAAS,wBAAwB,CAAC,CAAC,OAAA,IAAW,OAAA,CAAQ,MAAA,KAAW,CAAA;AAAA,EACzG;AACF","file":"storage-available.js","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"]}
|
package/package.json
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mado/utils",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"license": "MIT",
|
|
5
|
+
"sideEffects": false,
|
|
6
|
+
"type": "module",
|
|
5
7
|
"main": "./dist/index.cjs",
|
|
6
8
|
"module": "./dist/index.js",
|
|
7
9
|
"types": "./dist/index.d.ts",
|
|
@@ -25,24 +27,23 @@
|
|
|
25
27
|
},
|
|
26
28
|
"bugs": "https://github.com/doinki/mado/issues",
|
|
27
29
|
"files": [
|
|
28
|
-
"dist"
|
|
29
|
-
"src",
|
|
30
|
-
"CHANGELOG.md"
|
|
30
|
+
"dist"
|
|
31
31
|
],
|
|
32
32
|
"homepage": "https://github.com/doinki/mado/tree/main/packages/mado-utils#readme",
|
|
33
33
|
"repository": {
|
|
34
34
|
"directory": "packages/mado-utils",
|
|
35
35
|
"type": "git",
|
|
36
|
-
"url": "https://github.com/doinki/mado.git"
|
|
36
|
+
"url": "git+https://github.com/doinki/mado.git"
|
|
37
|
+
},
|
|
38
|
+
"publishConfig": {
|
|
39
|
+
"access": "public"
|
|
37
40
|
},
|
|
38
|
-
"sideEffects": false,
|
|
39
|
-
"type": "module",
|
|
40
41
|
"scripts": {
|
|
41
42
|
"build": "tsup",
|
|
42
43
|
"test": "vitest run",
|
|
43
44
|
"test:coverage": "vitest run --coverage",
|
|
44
|
-
"lint": "eslint
|
|
45
|
+
"lint": "eslint",
|
|
45
46
|
"publint": "publint",
|
|
46
|
-
"typecheck": "tsc"
|
|
47
|
+
"typecheck": "tsc --noEmit"
|
|
47
48
|
}
|
|
48
49
|
}
|
package/CHANGELOG.md
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
# @mado/utils
|
|
2
|
-
|
|
3
|
-
## 0.2.0
|
|
4
|
-
|
|
5
|
-
### Minor Changes
|
|
6
|
-
|
|
7
|
-
- ce252f2: - Add capitalize function
|
|
8
|
-
- Add isNil function
|
|
9
|
-
|
|
10
|
-
## 0.1.0
|
|
11
|
-
|
|
12
|
-
### Minor Changes
|
|
13
|
-
|
|
14
|
-
- 2fcb4c0: feat(utils): Add storageAvailable function
|
|
15
|
-
|
|
16
|
-
## 0.0.1
|
|
17
|
-
|
|
18
|
-
### Patch Changes
|
|
19
|
-
|
|
20
|
-
- 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"]}
|
|
@@ -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/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
|