@mado/utils 0.0.1 → 0.2.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/CHANGELOG.md +13 -0
- package/dist/capitalize.cjs +10 -0
- package/dist/capitalize.cjs.map +1 -0
- package/dist/capitalize.d.cts +3 -0
- package/dist/capitalize.d.ts +3 -0
- package/dist/capitalize.js +8 -0
- package/dist/capitalize.js.map +1 -0
- package/dist/index.cjs +21 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -1
- package/dist/isNil.cjs +10 -0
- package/dist/isNil.cjs.map +1 -0
- package/dist/isNil.d.cts +3 -0
- package/dist/isNil.d.ts +3 -0
- package/dist/isNil.js +8 -0
- package/dist/isNil.js.map +1 -0
- package/dist/storageAvailable.cjs +25 -0
- package/dist/storageAvailable.cjs.map +1 -0
- package/dist/storageAvailable.d.cts +6 -0
- package/dist/storageAvailable.d.ts +6 -0
- package/dist/storageAvailable.js +23 -0
- package/dist/storageAvailable.js.map +1 -0
- package/package.json +2 -1
- package/src/capitalize.ts +3 -0
- package/src/index.ts +3 -0
- package/src/isNil.ts +3 -0
- package/src/storageAvailable.ts +33 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
# @mado/utils
|
|
2
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
|
+
|
|
3
16
|
## 0.0.1
|
|
4
17
|
|
|
5
18
|
### Patch Changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/capitalize.ts"],"names":[],"mappings":";AAAO,SAAS,WAAW,KAAqB;AAC9C,SAAO,IAAI,OAAO,CAAC,EAAE,YAAY,IAAI,IAAI,UAAU,CAAC;AACtD","sourcesContent":["export function capitalize(str: string): string {\n return str.charAt(0).toUpperCase() + str.substring(1);\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/capitalize.ts"],"names":[],"mappings":";AAAO,SAAS,WAAW,KAAqB;AAC9C,SAAO,IAAI,OAAO,CAAC,EAAE,YAAY,IAAI,IAAI,UAAU,CAAC;AACtD","sourcesContent":["export function capitalize(str: string): string {\n return str.charAt(0).toUpperCase() + str.substring(1);\n}\n"]}
|
package/dist/index.cjs
CHANGED
|
@@ -1,14 +1,35 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
var capitalize_cjs = require('./capitalize.cjs');
|
|
3
4
|
var debounce_cjs = require('./debounce.cjs');
|
|
5
|
+
var isNil_cjs = require('./isNil.cjs');
|
|
6
|
+
var storageAvailable_cjs = require('./storageAvailable.cjs');
|
|
4
7
|
|
|
5
8
|
|
|
6
9
|
|
|
10
|
+
Object.keys(capitalize_cjs).forEach(function (k) {
|
|
11
|
+
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
12
|
+
enumerable: true,
|
|
13
|
+
get: function () { return capitalize_cjs[k]; }
|
|
14
|
+
});
|
|
15
|
+
});
|
|
7
16
|
Object.keys(debounce_cjs).forEach(function (k) {
|
|
8
17
|
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
9
18
|
enumerable: true,
|
|
10
19
|
get: function () { return debounce_cjs[k]; }
|
|
11
20
|
});
|
|
12
21
|
});
|
|
22
|
+
Object.keys(isNil_cjs).forEach(function (k) {
|
|
23
|
+
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
24
|
+
enumerable: true,
|
|
25
|
+
get: function () { return isNil_cjs[k]; }
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
Object.keys(storageAvailable_cjs).forEach(function (k) {
|
|
29
|
+
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
30
|
+
enumerable: true,
|
|
31
|
+
get: function () { return storageAvailable_cjs[k]; }
|
|
32
|
+
});
|
|
33
|
+
});
|
|
13
34
|
//# sourceMappingURL=out.js.map
|
|
14
35
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"names":[],"mappings":";AAAA,cAAc","sourcesContent":["export * from './debounce';\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"names":[],"mappings":";AAAA,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc","sourcesContent":["export * from './capitalize';\nexport * from './debounce';\nexport * from './isNil';\nexport * from './storageAvailable';\n"]}
|
package/dist/index.d.cts
CHANGED
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"names":[],"mappings":";AAAA,cAAc","sourcesContent":["export * from './debounce';\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"names":[],"mappings":";AAAA,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc","sourcesContent":["export * from './capitalize';\nexport * from './debounce';\nexport * from './isNil';\nexport * from './storageAvailable';\n"]}
|
package/dist/isNil.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
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.d.cts
ADDED
package/dist/isNil.d.ts
ADDED
package/dist/isNil.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
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"]}
|
|
@@ -0,0 +1,25 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
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"]}
|
|
@@ -0,0 +1,6 @@
|
|
|
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
|
+
declare function storageAvailable(type: 'localStorage' | 'sessionStorage'): boolean;
|
|
5
|
+
|
|
6
|
+
export { storageAvailable };
|
|
@@ -0,0 +1,6 @@
|
|
|
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
|
+
declare function storageAvailable(type: 'localStorage' | 'sessionStorage'): boolean;
|
|
5
|
+
|
|
6
|
+
export { storageAvailable };
|
|
@@ -0,0 +1,23 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mado/utils",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"main": "./dist/index.cjs",
|
|
6
6
|
"module": "./dist/index.js",
|
|
@@ -40,6 +40,7 @@
|
|
|
40
40
|
"scripts": {
|
|
41
41
|
"build": "tsup",
|
|
42
42
|
"test": "vitest run",
|
|
43
|
+
"test:coverage": "vitest run --coverage",
|
|
43
44
|
"lint": "eslint .",
|
|
44
45
|
"publint": "publint",
|
|
45
46
|
"typecheck": "tsc"
|
package/src/index.ts
CHANGED
package/src/isNil.ts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
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
|
+
}
|