@takeshape/util 11.143.2 → 11.154.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/dist/common/clone.d.ts +2 -2
- package/dist/common/clone.js +3 -3
- package/dist/common/mime.js +30 -5
- package/dist/common/sleep.d.ts +1 -0
- package/dist/common/sleep.js +13 -0
- package/dist/common/strings.d.ts +2 -0
- package/dist/common/strings.js +6 -0
- package/package.json +4 -5
package/dist/common/clone.d.ts
CHANGED
|
@@ -35,7 +35,7 @@ export declare function deepCloneWith(obj: unknown, customizer: DeepCloneWithCus
|
|
|
35
35
|
export type CloneWithPathHelper = (value: unknown, key: string | number | undefined, parent: Record<string, unknown> | unknown[] | undefined, path: string[]) => unknown;
|
|
36
36
|
/**
|
|
37
37
|
* Clone any JSON serializable value and transform using a callback
|
|
38
|
-
* @param
|
|
38
|
+
* @param initialValue the value to clone
|
|
39
39
|
* @param customizer a callback that is called for every key/index
|
|
40
40
|
*/
|
|
41
|
-
export declare function deepCloneWithPath(
|
|
41
|
+
export declare function deepCloneWithPath(initialValue: unknown, customizer: CloneWithPathHelper): unknown;
|
package/dist/common/clone.js
CHANGED
|
@@ -71,10 +71,10 @@ export function deepCloneWith(obj, customizer) {
|
|
|
71
71
|
}
|
|
72
72
|
/**
|
|
73
73
|
* Clone any JSON serializable value and transform using a callback
|
|
74
|
-
* @param
|
|
74
|
+
* @param initialValue the value to clone
|
|
75
75
|
* @param customizer a callback that is called for every key/index
|
|
76
76
|
*/
|
|
77
|
-
export function deepCloneWithPath(
|
|
77
|
+
export function deepCloneWithPath(initialValue, customizer) {
|
|
78
78
|
const clone = (value, key, parent, path) => {
|
|
79
79
|
const customizedValue = customizer(value, key, parent, path);
|
|
80
80
|
if (customizedValue === REMOVE) {
|
|
@@ -106,5 +106,5 @@ export function deepCloneWithPath(obj, customizer) {
|
|
|
106
106
|
}
|
|
107
107
|
return cloneValue;
|
|
108
108
|
};
|
|
109
|
-
return clone(
|
|
109
|
+
return clone(initialValue, undefined, undefined, []);
|
|
110
110
|
}
|
package/dist/common/mime.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import mime from 'mime
|
|
1
|
+
import mime from 'mime';
|
|
2
2
|
const compressedMimeTypes = new Set([
|
|
3
3
|
'application/atom+xml',
|
|
4
4
|
'application/javascript',
|
|
@@ -35,15 +35,40 @@ const compressedMimeTypes = new Set([
|
|
|
35
35
|
'text/xml'
|
|
36
36
|
]);
|
|
37
37
|
// Application/octetstream
|
|
38
|
-
const DEFAULT_TYPE = mime.
|
|
38
|
+
const DEFAULT_TYPE = mime.getType('bin');
|
|
39
|
+
/**
|
|
40
|
+
* Extracted from implementation https://github.com/jshttp/mime-types/blob/541f9c57b3e418fc449fa84be4a69a1e1a7835db/index.js#L51
|
|
41
|
+
* It returns for all types defined in mime-db https://github.com/jshttp/mime-db/blob/master/db.json
|
|
42
|
+
* @param mimeType
|
|
43
|
+
*/
|
|
44
|
+
function getDefaultCharset(mimeType) {
|
|
45
|
+
const [type, subtype] = mimeType.toLowerCase().split('/');
|
|
46
|
+
if (type === 'text') {
|
|
47
|
+
return 'UTF-8';
|
|
48
|
+
}
|
|
49
|
+
if (type === 'application') {
|
|
50
|
+
if (subtype.includes('+xml') ||
|
|
51
|
+
subtype.includes('+json') ||
|
|
52
|
+
subtype === 'json' ||
|
|
53
|
+
subtype === 'javascript' ||
|
|
54
|
+
subtype === 'vnd.syncml.dm+wbxml' ||
|
|
55
|
+
subtype === 'vnd.wap.wbxml') {
|
|
56
|
+
return 'UTF-8';
|
|
57
|
+
}
|
|
58
|
+
if (subtype === 'news-checkgroups' || subtype === 'news-groupinfo')
|
|
59
|
+
return 'US-ASCII';
|
|
60
|
+
if (subtype === 'prs.cyn')
|
|
61
|
+
return '7-BIT';
|
|
62
|
+
}
|
|
63
|
+
}
|
|
39
64
|
/**
|
|
40
65
|
* Gets the content type of the file, based on it's extension.
|
|
41
66
|
* @param {String} src Path to file fow which content type should be evaluated.
|
|
42
67
|
* @return {String} Returns string with content type and charset.
|
|
43
68
|
*/
|
|
44
69
|
export function contentType(src) {
|
|
45
|
-
let type = (mime.
|
|
46
|
-
const charset =
|
|
70
|
+
let type = (mime.getType(src) || DEFAULT_TYPE).replace('-', '');
|
|
71
|
+
const charset = getDefaultCharset(type);
|
|
47
72
|
if (charset) {
|
|
48
73
|
type += `; charset=${charset}`;
|
|
49
74
|
}
|
|
@@ -55,6 +80,6 @@ export function contentType(src) {
|
|
|
55
80
|
* @return {Boolean} Returns true if we should compress
|
|
56
81
|
*/
|
|
57
82
|
export function shouldCompress(src) {
|
|
58
|
-
const mimeType = mime.
|
|
83
|
+
const mimeType = mime.getType(src);
|
|
59
84
|
return Boolean(mimeType && compressedMimeTypes.has(mimeType));
|
|
60
85
|
}
|
package/dist/common/sleep.d.ts
CHANGED
package/dist/common/sleep.js
CHANGED
|
@@ -3,3 +3,16 @@ export async function sleep(ms) {
|
|
|
3
3
|
setTimeout(resolve, ms);
|
|
4
4
|
});
|
|
5
5
|
}
|
|
6
|
+
export const cancelableSleep = (ms, signal) => {
|
|
7
|
+
return new Promise((resolve) => {
|
|
8
|
+
if (signal?.aborted) {
|
|
9
|
+
resolve(false);
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
const timeoutId = setTimeout(() => resolve(true), ms);
|
|
13
|
+
signal?.addEventListener('abort', () => {
|
|
14
|
+
clearTimeout(timeoutId);
|
|
15
|
+
resolve(false);
|
|
16
|
+
});
|
|
17
|
+
});
|
|
18
|
+
};
|
package/dist/common/strings.d.ts
CHANGED
|
@@ -17,6 +17,8 @@ export declare function isIntegerLike(value: string | number): boolean;
|
|
|
17
17
|
export declare function encodePropertyName(value: string): string;
|
|
18
18
|
export declare function base64Encode(str: string): string;
|
|
19
19
|
export declare function base64Decode(str: string): string;
|
|
20
|
+
export declare function base64UrlEncode(str: string): string;
|
|
21
|
+
export declare function base64UrlDecode(str: string): string;
|
|
20
22
|
/**
|
|
21
23
|
* Replace {{key}} or {key} in a string with the value of the key in the data object.
|
|
22
24
|
*/
|
package/dist/common/strings.js
CHANGED
|
@@ -77,6 +77,12 @@ export function base64Encode(str) {
|
|
|
77
77
|
export function base64Decode(str) {
|
|
78
78
|
return isBrowser ? window.atob(str) : Buffer.from(str, 'base64').toString();
|
|
79
79
|
}
|
|
80
|
+
export function base64UrlEncode(str) {
|
|
81
|
+
return isBrowser ? window.btoa(str) : Buffer.from(str).toString('base64url');
|
|
82
|
+
}
|
|
83
|
+
export function base64UrlDecode(str) {
|
|
84
|
+
return isBrowser ? window.atob(str) : Buffer.from(str, 'base64url').toString();
|
|
85
|
+
}
|
|
80
86
|
/**
|
|
81
87
|
* Replace {{key}} or {key} in a string with the value of the key in the data object.
|
|
82
88
|
*/
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@takeshape/util",
|
|
3
|
-
"version": "11.
|
|
3
|
+
"version": "11.154.1",
|
|
4
4
|
"description": "Shared utilities",
|
|
5
5
|
"homepage": "https://www.takeshape.io",
|
|
6
6
|
"repository": {
|
|
@@ -40,13 +40,13 @@
|
|
|
40
40
|
"htmlparser2": "9.1.0",
|
|
41
41
|
"lodash": "4.17.21",
|
|
42
42
|
"markdown-draft-js": "github:incompl/markdown-draft-js#deterministic-entity-keys-with-lib",
|
|
43
|
-
"mime
|
|
43
|
+
"mime": "4.1.0",
|
|
44
44
|
"shortid": "2.2.16",
|
|
45
45
|
"tiny-invariant": "1.3.3",
|
|
46
46
|
"uint8array-extras": "1.4.0",
|
|
47
47
|
"url-parse": "1.5.3",
|
|
48
|
-
"@takeshape/prism": "11.
|
|
49
|
-
"@takeshape/routing": "11.
|
|
48
|
+
"@takeshape/prism": "11.154.1",
|
|
49
|
+
"@takeshape/routing": "11.154.1"
|
|
50
50
|
},
|
|
51
51
|
"devDependencies": {
|
|
52
52
|
"@types/classnames": "2.2.11",
|
|
@@ -54,7 +54,6 @@
|
|
|
54
54
|
"@types/he": "1.2.0",
|
|
55
55
|
"@types/lodash": "4.17.20",
|
|
56
56
|
"@types/markdown-draft-js": "2.2.4",
|
|
57
|
-
"@types/mime-types": "2.1.0",
|
|
58
57
|
"@types/shortid": "0.0.29",
|
|
59
58
|
"domhandler": "5.0.3",
|
|
60
59
|
"stripe": "13.8.0"
|