@silvermine/toolbox 0.1.0 → 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/commitlint.config.js +1 -1
- package/dist/commonjs/index.js +12 -1
- package/dist/commonjs/index.js.map +1 -1
- package/dist/commonjs/types/KeyValueStringObject.js +8 -8
- package/dist/commonjs/types/KeyValueStringObject.js.map +1 -1
- package/dist/commonjs/types/StringArrayOfStringsMap.js +6 -6
- package/dist/commonjs/types/StringArrayOfStringsMap.js.map +1 -1
- package/dist/commonjs/types/StringMap.js +6 -6
- package/dist/commonjs/types/StringMap.js.map +1 -1
- package/dist/commonjs/types/StringUnknownMap.js +4 -3
- package/dist/commonjs/types/StringUnknownMap.js.map +1 -1
- package/dist/commonjs/utils/chunk.js +3 -2
- package/dist/commonjs/utils/chunk.js.map +1 -1
- package/dist/commonjs/utils/delay.js +3 -2
- package/dist/commonjs/utils/delay.js.map +1 -1
- package/dist/commonjs/utils/escape-html.js +23 -0
- package/dist/commonjs/utils/escape-html.js.map +1 -0
- package/dist/commonjs/utils/flatten.js +3 -6
- package/dist/commonjs/utils/flatten.js.map +1 -1
- package/dist/commonjs/utils/get-tag-string.js +1 -0
- package/dist/commonjs/utils/get-tag-string.js.map +1 -1
- package/dist/commonjs/utils/get.js +99 -0
- package/dist/commonjs/utils/get.js.map +1 -0
- package/dist/commonjs/utils/has-defined.js +2 -1
- package/dist/commonjs/utils/has-defined.js.map +1 -1
- package/dist/commonjs/utils/is-arguments.js +2 -1
- package/dist/commonjs/utils/is-arguments.js.map +1 -1
- package/dist/commonjs/utils/is-array-of-strings.js +4 -4
- package/dist/commonjs/utils/is-array-of-strings.js.map +1 -1
- package/dist/commonjs/utils/is-array.js +1 -0
- package/dist/commonjs/utils/is-array.js.map +1 -1
- package/dist/commonjs/utils/is-empty.js +5 -4
- package/dist/commonjs/utils/is-empty.js.map +1 -1
- package/dist/commonjs/utils/is-enum-value.js +3 -2
- package/dist/commonjs/utils/is-enum-value.js.map +1 -1
- package/dist/commonjs/utils/is-map-with-values-of-type.js +3 -3
- package/dist/commonjs/utils/is-map-with-values-of-type.js.map +1 -1
- package/dist/commonjs/utils/is-not-null-or-undefined.js +13 -0
- package/dist/commonjs/utils/is-not-null-or-undefined.js.map +1 -0
- package/dist/commonjs/utils/is-null.js +8 -0
- package/dist/commonjs/utils/is-null.js.map +1 -0
- package/dist/commonjs/utils/is-number.js +3 -2
- package/dist/commonjs/utils/is-number.js.map +1 -1
- package/dist/commonjs/utils/is-object.js +2 -1
- package/dist/commonjs/utils/is-object.js.map +1 -1
- package/dist/commonjs/utils/is-promise-like.js +3 -2
- package/dist/commonjs/utils/is-promise-like.js.map +1 -1
- package/dist/commonjs/utils/is-promise.js +3 -2
- package/dist/commonjs/utils/is-promise.js.map +1 -1
- package/dist/commonjs/utils/is-string.js +3 -2
- package/dist/commonjs/utils/is-string.js.map +1 -1
- package/dist/commonjs/utils/is-undefined.js +1 -0
- package/dist/commonjs/utils/is-undefined.js.map +1 -1
- package/dist/commonjs/utils/make-template.js +73 -0
- package/dist/commonjs/utils/make-template.js.map +1 -0
- package/dist/commonjs/utils/pluck.js +2 -1
- package/dist/commonjs/utils/pluck.js.map +1 -1
- package/dist/esm/index.js +11 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/utils/chunk.js.map +1 -1
- package/dist/esm/utils/escape-html.js +19 -0
- package/dist/esm/utils/escape-html.js.map +1 -0
- package/dist/esm/utils/flatten.js.map +1 -1
- package/dist/esm/utils/get.js +96 -0
- package/dist/esm/utils/get.js.map +1 -0
- package/dist/esm/utils/is-not-null-or-undefined.js +9 -0
- package/dist/esm/utils/is-not-null-or-undefined.js.map +1 -0
- package/dist/esm/utils/is-null.js +4 -0
- package/dist/esm/utils/is-null.js.map +1 -0
- package/dist/esm/utils/is-undefined.js.map +1 -1
- package/dist/esm/utils/make-template.js +69 -0
- package/dist/esm/utils/make-template.js.map +1 -0
- package/dist/esm/utils/pluck.js.map +1 -1
- package/dist/types/index.d.ts +5 -0
- package/dist/types/utils/chunk.d.ts +1 -1
- package/dist/types/utils/escape-html.d.ts +1 -0
- package/dist/types/utils/flatten.d.ts +1 -1
- package/dist/types/utils/get.d.ts +8 -0
- package/dist/types/utils/is-not-null-or-undefined.d.ts +4 -0
- package/dist/types/utils/is-null.d.ts +1 -0
- package/dist/types/utils/is-undefined.d.ts +1 -1
- package/dist/types/utils/make-template.d.ts +41 -0
- package/dist/types/utils/pluck.d.ts +1 -1
- package/package.json +10 -10
- package/src/index.ts +5 -0
- package/src/utils/chunk.ts +1 -1
- package/src/utils/escape-html.ts +24 -0
- package/src/utils/flatten.ts +2 -2
- package/src/utils/get.ts +156 -0
- package/src/utils/is-not-null-or-undefined.ts +10 -0
- package/src/utils/is-null.ts +3 -0
- package/src/utils/is-undefined.ts +1 -1
- package/src/utils/make-template.ts +90 -0
- package/src/utils/pluck.ts +1 -1
- package/.nvmrc +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"is-promise-like.js","sourceRoot":"","sources":["../../../src/utils/is-promise-like.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"is-promise-like.js","sourceRoot":"","sources":["../../../src/utils/is-promise-like.ts"],"names":[],"mappings":";;;AAAA,6CAAyC;AACzC,2CAAuC;AAEvC;;;;;;GAMG;AACH,SAAgB,aAAa,CAAC,CAAM;IACjC,OAAO,sBAAS,CAAC,CAAC,CAAC,IAAI,CAAC,oBAAQ,CAAC,CAAC,CAAC,IAAI,OAAQ,CAAS,CAAC,IAAI,KAAK,UAAU,CAAC,CAAC;AACjF,CAAC;AAFD,sCAEC"}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
exports.isPromise = void 0;
|
|
4
|
+
const is_object_1 = require("./is-object");
|
|
5
|
+
const get_tag_string_1 = require("./get-tag-string");
|
|
5
6
|
/**
|
|
6
7
|
* Type guard for `Promise`s.
|
|
7
8
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"is-promise.js","sourceRoot":"","sources":["../../../src/utils/is-promise.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"is-promise.js","sourceRoot":"","sources":["../../../src/utils/is-promise.ts"],"names":[],"mappings":";;;AAAA,2CAAuC;AACvC,qDAAgD;AAEhD;;;;GAIG;AACH,SAAgB,SAAS,CAAC,CAAM;IAC7B,OAAO,oBAAQ,CAAC,CAAC,CAAC,IAAI,6BAAY,CAAC,CAAC,CAAC,KAAK,kBAAkB,CAAC;AAChE,CAAC;AAFD,8BAEC"}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
exports.isString = void 0;
|
|
4
|
+
const is_object_1 = require("./is-object");
|
|
5
|
+
const get_tag_string_1 = require("./get-tag-string");
|
|
5
6
|
/**
|
|
6
7
|
* Type guard for `string`s.
|
|
7
8
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"is-string.js","sourceRoot":"","sources":["../../../src/utils/is-string.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"is-string.js","sourceRoot":"","sources":["../../../src/utils/is-string.ts"],"names":[],"mappings":";;;AAAA,2CAAuC;AACvC,qDAAgD;AAEhD;;;;;;GAMG;AACH,SAAgB,QAAQ,CAAC,CAAM;IAC5B,OAAO,OAAO,CAAC,KAAK,QAAQ,IAAI,CAAC,oBAAQ,CAAC,CAAC,CAAC,IAAI,6BAAY,CAAC,CAAC,CAAC,KAAK,iBAAiB,CAAC,CAAC;AAC1F,CAAC;AAFD,4BAEC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"is-undefined.js","sourceRoot":"","sources":["../../../src/utils/is-undefined.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"is-undefined.js","sourceRoot":"","sources":["../../../src/utils/is-undefined.ts"],"names":[],"mappings":";;;AAAA,SAAgB,WAAW,CAAC,GAAY;IACrC,OAAO,CAAC,OAAO,GAAG,KAAK,WAAW,CAAC,CAAC;AACvC,CAAC;AAFD,kCAEC"}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.makeTemplate = void 0;
|
|
4
|
+
const get_1 = require("./get");
|
|
5
|
+
const escape_html_1 = require("./escape-html");
|
|
6
|
+
const DEFAULT_SETTINGS = {
|
|
7
|
+
escape: /<%-([\s\S]+?)%>/g,
|
|
8
|
+
interpolate: /<%=([\s\S]+?)%>/g,
|
|
9
|
+
};
|
|
10
|
+
function getValue(path, data) {
|
|
11
|
+
return get_1.get(data, (path || '').trim(), '');
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* A simple replacement for _.template from either Underscore or Lodash that removes the
|
|
15
|
+
* features that make those libraries incompatible with Content Security Policy (CSP).
|
|
16
|
+
* Specifically, this implementation supports only interpolation (escaped and unescaped)
|
|
17
|
+
* and does not support JS evaluation.
|
|
18
|
+
*
|
|
19
|
+
* Use this function just like you would have used _.template:
|
|
20
|
+
*
|
|
21
|
+
* ```ts
|
|
22
|
+
* template = template('Hello <%= name %>');
|
|
23
|
+
* console.log(template({ name: 'John Smith' }));
|
|
24
|
+
* ```
|
|
25
|
+
*
|
|
26
|
+
* This function only supports:
|
|
27
|
+
*
|
|
28
|
+
* `<%= … %>`: interpolate a value
|
|
29
|
+
* `<%- … %>`: interpolate and HTML escape a value
|
|
30
|
+
*
|
|
31
|
+
* The following are NOT supported:
|
|
32
|
+
*
|
|
33
|
+
* `<% … %>`: JS evaluation
|
|
34
|
+
* `<% print('Hello ' + epithet); %>`: JS evaluation with the print function
|
|
35
|
+
*
|
|
36
|
+
* Templating in Underscore/Lodash works by building/evaluation a JS function using a
|
|
37
|
+
* string, essentially using `eval()` to evaluate the string as JS. This meant that if
|
|
38
|
+
* your template referred to a variable that did not exist, you would see a JS error
|
|
39
|
+
* thrown. In this function, however, undefined variables in the template will result in
|
|
40
|
+
* an empty string placed in that location.
|
|
41
|
+
*/
|
|
42
|
+
function makeTemplate(text, userSettings) {
|
|
43
|
+
let parts = [], index = 0, settings = Object.assign({}, DEFAULT_SETTINGS, userSettings || {}), regExpPattern, matcher;
|
|
44
|
+
regExpPattern = [
|
|
45
|
+
settings.escape.source,
|
|
46
|
+
settings.interpolate.source,
|
|
47
|
+
];
|
|
48
|
+
matcher = new RegExp(regExpPattern.join('|') + '|$', 'g');
|
|
49
|
+
text.replace(matcher, (match, escape, interpolate, offset) => {
|
|
50
|
+
parts.push(text.slice(index, offset));
|
|
51
|
+
index = offset + match.length;
|
|
52
|
+
if (escape) {
|
|
53
|
+
parts.push((data) => {
|
|
54
|
+
return escape_html_1.escapeHTML(getValue(escape, data));
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
else if (interpolate) {
|
|
58
|
+
parts.push(getValue.bind(null, interpolate));
|
|
59
|
+
}
|
|
60
|
+
// The types for this callback require us to return a string, but we don't really
|
|
61
|
+
// care about the result of the call to `replace`, so we just return an empty string
|
|
62
|
+
// here.
|
|
63
|
+
return '';
|
|
64
|
+
});
|
|
65
|
+
return (data) => {
|
|
66
|
+
return parts.reduce((memo, part) => {
|
|
67
|
+
const result = (typeof part === 'function') ? `${part(data)}` : part;
|
|
68
|
+
return memo + result;
|
|
69
|
+
}, '');
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
exports.makeTemplate = makeTemplate;
|
|
73
|
+
//# sourceMappingURL=make-template.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"make-template.js","sourceRoot":"","sources":["../../../src/utils/make-template.ts"],"names":[],"mappings":";;;AAAA,+BAA4B;AAC5B,+CAA2C;AAE3C,MAAM,gBAAgB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C,IAAI,EAAE,WAAW,CAAC,CAAC,CAAC;SAC/C;QAED,iFAAiF;QACjF,oFAAoF;QACpF,QAAQ;QACR,OAAO,EAAE,CAAC;IACb,CAAC,CAAC,CAAC;IAEH,OAAO,CAAC,IAAa,EAAU,EAAE;QAC9B,OAAO,KAAK,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,IAAI,EAAU,EAAE;YACxC,MAAM,MAAM,GAAG,CAAC,OAAO,IAAI,KAAK,UAAU,CAAC,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;YAErE,OAAO,IAAI,GAAG,MAAM,CAAC;QACxB,CAAC,EAAE,EAAE,CAAW,CAAC;IACpB,CAAC,CAAC;AACL,CAAC;AAvCD,oCAuCC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pluck.js","sourceRoot":"","sources":["../../../src/utils/pluck.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"pluck.js","sourceRoot":"","sources":["../../../src/utils/pluck.ts"],"names":[],"mappings":";;;AAAA,SAAgB,KAAK,CAAuB,OAAqB,EAAE,GAAM;IACtE,OAAO,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE;QACtB,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC;IACjB,CAAC,CAAC,CAAC;AACN,CAAC;AAJD,sBAIC"}
|
package/dist/esm/index.js
CHANGED
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
export * from './types/KeyValueStringObject';
|
|
2
|
+
export * from './types/Omit';
|
|
3
|
+
export * from './types/Optional';
|
|
4
|
+
export * from './types/PropsWithType';
|
|
5
|
+
export * from './types/RequireDefined';
|
|
6
|
+
export * from './types/RequireOptional';
|
|
2
7
|
export * from './types/StringArrayOfStringsMap';
|
|
3
8
|
export * from './types/StringMap';
|
|
4
9
|
export * from './types/StringUnknownMap';
|
|
10
|
+
export * from './types/Writable';
|
|
5
11
|
export * from './utils/has-defined';
|
|
6
12
|
export * from './utils/is-arguments';
|
|
7
13
|
export * from './utils/is-array';
|
|
@@ -15,8 +21,13 @@ export * from './utils/is-promise';
|
|
|
15
21
|
export * from './utils/is-promise-like';
|
|
16
22
|
export * from './utils/is-string';
|
|
17
23
|
export * from './utils/is-undefined';
|
|
24
|
+
export * from './utils/is-null';
|
|
25
|
+
export * from './utils/is-not-null-or-undefined';
|
|
18
26
|
export * from './utils/chunk';
|
|
19
27
|
export * from './utils/flatten';
|
|
20
28
|
export * from './utils/pluck';
|
|
21
29
|
export * from './utils/delay';
|
|
30
|
+
export * from './utils/get';
|
|
31
|
+
export * from './utils/escape-html';
|
|
32
|
+
export * from './utils/make-template';
|
|
22
33
|
//# sourceMappingURL=index.js.map
|
package/dist/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,8BAA8B,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,8BAA8B,CAAC;AAC7C,cAAc,cAAc,CAAC;AAC7B,cAAc,kBAAkB,CAAC;AACjC,cAAc,uBAAuB,CAAC;AACtC,cAAc,wBAAwB,CAAC;AACvC,cAAc,yBAAyB,CAAC;AACxC,cAAc,iCAAiC,CAAC;AAChD,cAAc,mBAAmB,CAAC;AAClC,cAAc,0BAA0B,CAAC;AACzC,cAAc,kBAAkB,CAAC;AAEjC,cAAc,qBAAqB,CAAC;AACpC,cAAc,sBAAsB,CAAC;AACrC,cAAc,kBAAkB,CAAC;AACjC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,kBAAkB,CAAC;AACjC,cAAc,uBAAuB,CAAC;AACtC,cAAc,oCAAoC,CAAC;AACnD,cAAc,mBAAmB,CAAC;AAClC,cAAc,mBAAmB,CAAC;AAClC,cAAc,oBAAoB,CAAC;AACnC,cAAc,yBAAyB,CAAC;AACxC,cAAc,mBAAmB,CAAC;AAClC,cAAc,sBAAsB,CAAC;AACrC,cAAc,iBAAiB,CAAC;AAChC,cAAc,kCAAkC,CAAC;AAEjD,cAAc,eAAe,CAAC;AAC9B,cAAc,iBAAiB,CAAC;AAChC,cAAc,eAAe,CAAC;AAC9B,cAAc,eAAe,CAAC;AAC9B,cAAc,aAAa,CAAC;AAC5B,cAAc,qBAAqB,CAAC;AACpC,cAAc,uBAAuB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chunk.js","sourceRoot":"","sources":["../../../src/utils/chunk.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,KAAK,CAAI,
|
|
1
|
+
{"version":3,"file":"chunk.js","sourceRoot":"","sources":["../../../src/utils/chunk.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,KAAK,CAAI,IAAkB,EAAE,IAAY;IACtD,IAAI,IAAI,GAAG,CAAC,EAAE;QACX,OAAO,EAAE,CAAC;KACZ;IAED,MAAM,MAAM,GAAU,EAAE,CAAC;IAEzB,IAAI,CAAC,GAAG,CAAC,CAAC;IAEV,OAAO,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE;QACrB,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC;QACrC,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC;KACf;IAED,OAAO,MAAM,CAAC;AACjB,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { isString } from './is-string';
|
|
2
|
+
const ESCAPE_ENTITIES = {
|
|
3
|
+
'&': '&',
|
|
4
|
+
'<': '<',
|
|
5
|
+
'>': '>',
|
|
6
|
+
'"': '"',
|
|
7
|
+
"'": ''',
|
|
8
|
+
'`': '`',
|
|
9
|
+
};
|
|
10
|
+
const ESCAPE_ENTITIES_PATTERN = '(?:' + Object.keys(ESCAPE_ENTITIES).join('|') + ')', ESCAPE_ENTITIES_REGEX = new RegExp(ESCAPE_ENTITIES_PATTERN), ESCAPE_ENTITIES_REPLACE_REGEX = new RegExp(ESCAPE_ENTITIES_PATTERN, 'g');
|
|
11
|
+
export function escapeHTML(str) {
|
|
12
|
+
if (isString(str) && ESCAPE_ENTITIES_REGEX.test(str)) {
|
|
13
|
+
return str.replace(ESCAPE_ENTITIES_REPLACE_REGEX, (match) => {
|
|
14
|
+
return ESCAPE_ENTITIES[match];
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
return str;
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=escape-html.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"escape-html.js","sourceRoot":"","sources":["../../../src/utils/escape-html.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAEvC,MAAM,eAAe,GAA2B;IAC7C,GAAG,EAAE,OAAO;IACZ,GAAG,EAAE,MAAM;IACX,GAAG,EAAE,MAAM;IACX,GAAG,EAAE,QAAQ;IACb,GAAG,EAAE,QAAQ;IACb,GAAG,EAAE,QAAQ;CACf,CAAC;AAEF,MAAM,uBAAuB,GAAG,KAAK,GAAG,MAAM,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,GAAG,EAC9E,qBAAqB,GAAG,IAAI,MAAM,CAAC,uBAAuB,CAAC,EAC3D,6BAA6B,GAAG,IAAI,MAAM,CAAC,uBAAuB,EAAE,GAAG,CAAC,CAAC;AAE/E,MAAM,UAAU,UAAU,CAAC,GAAY;IACpC,IAAI,QAAQ,CAAC,GAAG,CAAC,IAAI,qBAAqB,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE;QACnD,OAAO,GAAG,CAAC,OAAO,CAAC,6BAA6B,EAAE,CAAC,KAAK,EAAE,EAAE;YACzD,OAAO,eAAe,CAAC,KAAK,CAAC,CAAC;QACjC,CAAC,CAAC,CAAC;KACL;IAED,OAAO,GAAG,CAAC;AACd,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"flatten.js","sourceRoot":"","sources":["../../../src/utils/flatten.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,OAAO,CAAI,GAAG,
|
|
1
|
+
{"version":3,"file":"flatten.js","sourceRoot":"","sources":["../../../src/utils/flatten.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,OAAO,CAAI,GAAG,KAAgC;IAC3D,OAAO,KAAK,CAAC,MAAM,CAAC,CAAC,IAAS,EAAE,IAAI,EAAE,EAAE;QACrC,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IAC5B,CAAC,EAAE,EAAS,CAAC,CAAC;AACjB,CAAC"}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Much of the code in this file is adapted from Lodash's _.get implementation:
|
|
3
|
+
*
|
|
4
|
+
* https://github.com/lodash/lodash/blob/2da024c3b4f9947a48517639de7560457cd4ec6c/get.js
|
|
5
|
+
* https://github.com/lodash/lodash/blob/2da024c3b4f9947a48517639de7560457cd4ec6c/.internal/baseGet.js
|
|
6
|
+
* https://github.com/lodash/lodash/blob/2da024c3b4f9947a48517639de7560457cd4ec6c/.internal/castPath.js
|
|
7
|
+
* https://github.com/lodash/lodash/blob/2da024c3b4f9947a48517639de7560457cd4ec6c/.internal/stringToPath.js
|
|
8
|
+
* https://github.com/lodash/lodash/blob/2da024c3b4f9947a48517639de7560457cd4ec6c/.internal/toKey.js
|
|
9
|
+
*/
|
|
10
|
+
import { getTagString } from './get-tag-string';
|
|
11
|
+
import { isObject } from './is-object';
|
|
12
|
+
function isSymbol(value) {
|
|
13
|
+
const type = typeof value;
|
|
14
|
+
return (type === 'symbol') || (type === 'object' &&
|
|
15
|
+
value !== undefined &&
|
|
16
|
+
value !== null &&
|
|
17
|
+
getTagString(value) === '[object Symbol]');
|
|
18
|
+
}
|
|
19
|
+
function toKey(value) {
|
|
20
|
+
if (typeof value === 'string' || isSymbol(value)) {
|
|
21
|
+
return value;
|
|
22
|
+
}
|
|
23
|
+
return Object.is(value, -0) ? '-0' : `${value}`;
|
|
24
|
+
}
|
|
25
|
+
const IS_DEEP_PROP_REGEX = /\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/, IS_PLAIN_PROP_REGEX = /^\w*$/;
|
|
26
|
+
function isKey(value, object) {
|
|
27
|
+
if (Array.isArray(value)) {
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
const type = typeof value;
|
|
31
|
+
if (type === 'number' || type === 'boolean' || value === null || value === undefined || isSymbol(value)) {
|
|
32
|
+
return true;
|
|
33
|
+
}
|
|
34
|
+
return IS_PLAIN_PROP_REGEX.test(value) || !IS_DEEP_PROP_REGEX.test(value) ||
|
|
35
|
+
(object !== null && object !== undefined && value in Object(object));
|
|
36
|
+
}
|
|
37
|
+
const DOT_CHAR_CODE = '.'.charCodeAt(0), ESCAPE_CHAR_REGEX = /\\(\\)?/g;
|
|
38
|
+
/* eslint-disable no-useless-concat */
|
|
39
|
+
const PROP_NAME_REGEX = RegExp(
|
|
40
|
+
// Match anything that isn't a dot or bracket.
|
|
41
|
+
'[^.[\\]]+' + '|' +
|
|
42
|
+
// Or match property names within brackets.
|
|
43
|
+
'\\[(?:' +
|
|
44
|
+
// Match a non-string expression.
|
|
45
|
+
'([^"\'][^[]*)' + '|' +
|
|
46
|
+
// Or match strings (supports escaping characters).
|
|
47
|
+
'(["\'])((?:(?!\\2)[^\\\\]|\\\\.)*?)\\2' +
|
|
48
|
+
')\\]' + '|' +
|
|
49
|
+
// Or match "" as the space between consecutive dots or empty brackets.
|
|
50
|
+
'(?=(?:\\.|\\[\\])(?:\\.|\\[\\]|$))', 'g');
|
|
51
|
+
/* eslint-enable no-useless-concat */
|
|
52
|
+
function stringToPath(str) {
|
|
53
|
+
const result = [];
|
|
54
|
+
if (str.charCodeAt(0) === DOT_CHAR_CODE) {
|
|
55
|
+
result.push('');
|
|
56
|
+
}
|
|
57
|
+
str.replace(PROP_NAME_REGEX, (match, expression, quote, subString) => {
|
|
58
|
+
let key = match;
|
|
59
|
+
if (quote) {
|
|
60
|
+
key = subString.replace(ESCAPE_CHAR_REGEX, '$1');
|
|
61
|
+
}
|
|
62
|
+
else if (expression) {
|
|
63
|
+
key = expression;
|
|
64
|
+
}
|
|
65
|
+
result.push(key);
|
|
66
|
+
// The types for this callback require us to return a string, but we don't really
|
|
67
|
+
// care about the result of the call to `replace`, so we just return an empty string
|
|
68
|
+
// here.
|
|
69
|
+
return '';
|
|
70
|
+
});
|
|
71
|
+
return result;
|
|
72
|
+
}
|
|
73
|
+
function createPathArray(value, object) {
|
|
74
|
+
if (Array.isArray(value)) {
|
|
75
|
+
return value;
|
|
76
|
+
}
|
|
77
|
+
return isKey(value, object) ? [value] : stringToPath(value);
|
|
78
|
+
}
|
|
79
|
+
function get(obj, path, defaultValue) {
|
|
80
|
+
if (!isObject(obj)) {
|
|
81
|
+
return defaultValue;
|
|
82
|
+
}
|
|
83
|
+
const pathArray = createPathArray(path, obj), length = pathArray.length;
|
|
84
|
+
let index = 0, resultObj = obj;
|
|
85
|
+
while (resultObj !== null && resultObj !== undefined && index < length) {
|
|
86
|
+
resultObj = resultObj[toKey(pathArray[index])];
|
|
87
|
+
index += 1;
|
|
88
|
+
}
|
|
89
|
+
const result = (index > 0 && index === length) ? resultObj : undefined;
|
|
90
|
+
if (result === undefined) {
|
|
91
|
+
return defaultValue;
|
|
92
|
+
}
|
|
93
|
+
return result;
|
|
94
|
+
}
|
|
95
|
+
export { get };
|
|
96
|
+
//# sourceMappingURL=get.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get.js","sourceRoot":"","sources":["../../../src/utils/get.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AA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CAAC,YAAY,CAAC,KAAK,CAAC,CAAC;AACjE,CAAC;AAwBD,SAAS,GAAG,CACT,GAAY,EACZ,IAAiD,EACjD,YAAsB;IAEtB,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE;QACjB,OAAO,YAAY,CAAC;KACtB;IAED,MAAM,SAAS,GAAG,eAAe,CAAC,IAAI,EAAE,GAAG,CAAC,EACtC,MAAM,GAAG,SAAS,CAAC,MAAM,CAAC;IAEhC,IAAI,KAAK,GAAG,CAAC,EACT,SAAS,GAAY,GAAG,CAAC;IAE7B,OAAO,SAAS,KAAK,IAAI,IAAI,SAAS,KAAK,SAAS,IAAI,KAAK,GAAG,MAAM,EAAE;QACrE,SAAS,GAAI,SAAiB,CAAC,KAAK,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;QAExD,KAAK,IAAI,CAAC,CAAC;KACb;IAED,MAAM,MAAM,GAAG,CAAC,KAAK,GAAG,CAAC,IAAI,KAAK,KAAK,MAAM,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC;IAEvE,IAAI,MAAM,KAAK,SAAS,EAAE;QACvB,OAAO,YAAY,CAAC;KACtB;IAED,OAAO,MAA6B,CAAC;AACxC,CAAC;AAED,OAAO,EAAE,GAAG,EAAE,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { isNull } from './is-null';
|
|
2
|
+
import { isUndefined } from './is-undefined';
|
|
3
|
+
/**
|
|
4
|
+
* Checks if `o` is not either null or undefined
|
|
5
|
+
*/
|
|
6
|
+
export function isNotNullOrUndefined(o) {
|
|
7
|
+
return !(isNull(o) || isUndefined(o));
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=is-not-null-or-undefined.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"is-not-null-or-undefined.js","sourceRoot":"","sources":["../../../src/utils/is-not-null-or-undefined.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AACnC,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAG7C;;GAEG;AACH,MAAM,UAAU,oBAAoB,CAAI,CAAuB;IAC5D,OAAO,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC;AACzC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"is-null.js","sourceRoot":"","sources":["../../../src/utils/is-null.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,MAAM,CAAC,GAAY;IAChC,OAAO,GAAG,KAAK,IAAI,CAAC;AACvB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"is-undefined.js","sourceRoot":"","sources":["../../../src/utils/is-undefined.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,WAAW,CAAC,
|
|
1
|
+
{"version":3,"file":"is-undefined.js","sourceRoot":"","sources":["../../../src/utils/is-undefined.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,WAAW,CAAC,GAAY;IACrC,OAAO,CAAC,OAAO,GAAG,KAAK,WAAW,CAAC,CAAC;AACvC,CAAC"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { get } from './get';
|
|
2
|
+
import { escapeHTML } from './escape-html';
|
|
3
|
+
const DEFAULT_SETTINGS = {
|
|
4
|
+
escape: /<%-([\s\S]+?)%>/g,
|
|
5
|
+
interpolate: /<%=([\s\S]+?)%>/g,
|
|
6
|
+
};
|
|
7
|
+
function getValue(path, data) {
|
|
8
|
+
return get(data, (path || '').trim(), '');
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* A simple replacement for _.template from either Underscore or Lodash that removes the
|
|
12
|
+
* features that make those libraries incompatible with Content Security Policy (CSP).
|
|
13
|
+
* Specifically, this implementation supports only interpolation (escaped and unescaped)
|
|
14
|
+
* and does not support JS evaluation.
|
|
15
|
+
*
|
|
16
|
+
* Use this function just like you would have used _.template:
|
|
17
|
+
*
|
|
18
|
+
* ```ts
|
|
19
|
+
* template = template('Hello <%= name %>');
|
|
20
|
+
* console.log(template({ name: 'John Smith' }));
|
|
21
|
+
* ```
|
|
22
|
+
*
|
|
23
|
+
* This function only supports:
|
|
24
|
+
*
|
|
25
|
+
* `<%= … %>`: interpolate a value
|
|
26
|
+
* `<%- … %>`: interpolate and HTML escape a value
|
|
27
|
+
*
|
|
28
|
+
* The following are NOT supported:
|
|
29
|
+
*
|
|
30
|
+
* `<% … %>`: JS evaluation
|
|
31
|
+
* `<% print('Hello ' + epithet); %>`: JS evaluation with the print function
|
|
32
|
+
*
|
|
33
|
+
* Templating in Underscore/Lodash works by building/evaluation a JS function using a
|
|
34
|
+
* string, essentially using `eval()` to evaluate the string as JS. This meant that if
|
|
35
|
+
* your template referred to a variable that did not exist, you would see a JS error
|
|
36
|
+
* thrown. In this function, however, undefined variables in the template will result in
|
|
37
|
+
* an empty string placed in that location.
|
|
38
|
+
*/
|
|
39
|
+
export function makeTemplate(text, userSettings) {
|
|
40
|
+
let parts = [], index = 0, settings = Object.assign({}, DEFAULT_SETTINGS, userSettings || {}), regExpPattern, matcher;
|
|
41
|
+
regExpPattern = [
|
|
42
|
+
settings.escape.source,
|
|
43
|
+
settings.interpolate.source,
|
|
44
|
+
];
|
|
45
|
+
matcher = new RegExp(regExpPattern.join('|') + '|$', 'g');
|
|
46
|
+
text.replace(matcher, (match, escape, interpolate, offset) => {
|
|
47
|
+
parts.push(text.slice(index, offset));
|
|
48
|
+
index = offset + match.length;
|
|
49
|
+
if (escape) {
|
|
50
|
+
parts.push((data) => {
|
|
51
|
+
return escapeHTML(getValue(escape, data));
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
else if (interpolate) {
|
|
55
|
+
parts.push(getValue.bind(null, interpolate));
|
|
56
|
+
}
|
|
57
|
+
// The types for this callback require us to return a string, but we don't really
|
|
58
|
+
// care about the result of the call to `replace`, so we just return an empty string
|
|
59
|
+
// here.
|
|
60
|
+
return '';
|
|
61
|
+
});
|
|
62
|
+
return (data) => {
|
|
63
|
+
return parts.reduce((memo, part) => {
|
|
64
|
+
const result = (typeof part === 'function') ? `${part(data)}` : part;
|
|
65
|
+
return memo + result;
|
|
66
|
+
}, '');
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
//# sourceMappingURL=make-template.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"make-template.js","sourceRoot":"","sources":["../../../src/utils/make-template.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,OAAO,CAAC;AAC5B,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAE3C,MAAM,gBAAgB,GAA4B;IAC/C,MAAM,EAAE,kBAAkB;IAC1B,WAAW,EAAE,kBAAkB;CACjC,CAAC;AAEF,SAAS,QAAQ,CAAC,IAAY,EAAE,IAAS;IACtC,OAAO,GAAG,CAAC,IAAI,EAAE,CAAC,IAAI,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,EAAE,EAAE,CAAC,CAAC;AAC7C,CAAC;AAWD;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,MAAM,UAAU,YAAY,CAAC,IAAY,EAAE,YAAsC;IAG9E,IAAI,KAAK,GAAkC,EAAE,EACzC,KAAK,GAAG,CAAC,EACT,QAAQ,GAAG,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,gBAAgB,EAAE,YAAY,IAAI,EAAE,CAAC,EAClE,aAAa,EAAE,OAAO,CAAC;IAE3B,aAAa,GAAG;QACb,QAAQ,CAAC,MAAM,CAAC,MAAM;QACtB,QAAQ,CAAC,WAAW,CAAC,MAAM;KAC7B,CAAC;IACF,OAAO,GAAG,IAAI,MAAM,CAAC,aAAa,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,IAAI,EAAE,GAAG,CAAC,CAAC;IAE1D,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,EAAE;QAC1D,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC,CAAC;QACtC,KAAK,GAAG,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC;QAE9B,IAAI,MAAM,EAAE;YACT,KAAK,CAAC,IAAI,CAAC,CAAC,IAAS,EAAE,EAAE;gBACtB,OAAO,UAAU,CAAC,QAAQ,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC,CAAC;YAC7C,CAAC,CAAC,CAAC;SACL;aAAM,IAAI,WAAW,EAAE;YACrB,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,EAAE,WAAW,CAAC,CAAC,CAAC;SAC/C;QAED,iFAAiF;QACjF,oFAAoF;QACpF,QAAQ;QACR,OAAO,EAAE,CAAC;IACb,CAAC,CAAC,CAAC;IAEH,OAAO,CAAC,IAAa,EAAU,EAAE;QAC9B,OAAO,KAAK,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,IAAI,EAAU,EAAE;YACxC,MAAM,MAAM,GAAG,CAAC,OAAO,IAAI,KAAK,UAAU,CAAC,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;YAErE,OAAO,IAAI,GAAG,MAAM,CAAC;QACxB,CAAC,EAAE,EAAE,CAAW,CAAC;IACpB,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pluck.js","sourceRoot":"","sources":["../../../src/utils/pluck.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,KAAK,CAAuB,
|
|
1
|
+
{"version":3,"file":"pluck.js","sourceRoot":"","sources":["../../../src/utils/pluck.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,KAAK,CAAuB,OAAqB,EAAE,GAAM;IACtE,OAAO,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE;QACtB,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC;IACjB,CAAC,CAAC,CAAC;AACN,CAAC"}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -21,7 +21,12 @@ export * from './utils/is-promise';
|
|
|
21
21
|
export * from './utils/is-promise-like';
|
|
22
22
|
export * from './utils/is-string';
|
|
23
23
|
export * from './utils/is-undefined';
|
|
24
|
+
export * from './utils/is-null';
|
|
25
|
+
export * from './utils/is-not-null-or-undefined';
|
|
24
26
|
export * from './utils/chunk';
|
|
25
27
|
export * from './utils/flatten';
|
|
26
28
|
export * from './utils/pluck';
|
|
27
29
|
export * from './utils/delay';
|
|
30
|
+
export * from './utils/get';
|
|
31
|
+
export * from './utils/escape-html';
|
|
32
|
+
export * from './utils/make-template';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare function chunk<T>(list: T[], size: number): T[][];
|
|
1
|
+
export declare function chunk<T>(list: readonly T[], size: number): T[][];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function escapeHTML(str: unknown): unknown;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare function flatten<T>(...lists: T[][]): T[];
|
|
1
|
+
export declare function flatten<T>(...lists: Readonly<Readonly<T[]>[]>): T[];
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
interface StringRepresentable {
|
|
2
|
+
toString(): string;
|
|
3
|
+
}
|
|
4
|
+
declare function get<TObject extends object, TKey extends keyof TObject>(obj: TObject, path: TKey | [TKey]): TObject[TKey] | undefined;
|
|
5
|
+
declare function get<TObject extends object, TKey extends keyof TObject>(obj: TObject, path: TKey | [TKey], defaultValue: TObject[TKey]): TObject[TKey];
|
|
6
|
+
declare function get<TObject extends object, TResult = unknown>(obj: TObject, path: StringRepresentable | StringRepresentable[], defaultValue: TResult): TResult;
|
|
7
|
+
declare function get<TObject extends object, TResult = unknown>(obj: TObject, path: StringRepresentable | StringRepresentable[]): TResult | undefined;
|
|
8
|
+
export { get };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function isNull(val: unknown): val is null;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare function isUndefined(val:
|
|
1
|
+
export declare function isUndefined(val: unknown): val is undefined;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
export interface ToolboxTemplateSettings {
|
|
2
|
+
escape: {
|
|
3
|
+
source: string;
|
|
4
|
+
};
|
|
5
|
+
interpolate: {
|
|
6
|
+
source: string;
|
|
7
|
+
};
|
|
8
|
+
}
|
|
9
|
+
export interface ToolboxTemplateFunction {
|
|
10
|
+
(data: Record<string, any>): string;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* A simple replacement for _.template from either Underscore or Lodash that removes the
|
|
14
|
+
* features that make those libraries incompatible with Content Security Policy (CSP).
|
|
15
|
+
* Specifically, this implementation supports only interpolation (escaped and unescaped)
|
|
16
|
+
* and does not support JS evaluation.
|
|
17
|
+
*
|
|
18
|
+
* Use this function just like you would have used _.template:
|
|
19
|
+
*
|
|
20
|
+
* ```ts
|
|
21
|
+
* template = template('Hello <%= name %>');
|
|
22
|
+
* console.log(template({ name: 'John Smith' }));
|
|
23
|
+
* ```
|
|
24
|
+
*
|
|
25
|
+
* This function only supports:
|
|
26
|
+
*
|
|
27
|
+
* `<%= … %>`: interpolate a value
|
|
28
|
+
* `<%- … %>`: interpolate and HTML escape a value
|
|
29
|
+
*
|
|
30
|
+
* The following are NOT supported:
|
|
31
|
+
*
|
|
32
|
+
* `<% … %>`: JS evaluation
|
|
33
|
+
* `<% print('Hello ' + epithet); %>`: JS evaluation with the print function
|
|
34
|
+
*
|
|
35
|
+
* Templating in Underscore/Lodash works by building/evaluation a JS function using a
|
|
36
|
+
* string, essentially using `eval()` to evaluate the string as JS. This meant that if
|
|
37
|
+
* your template referred to a variable that did not exist, you would see a JS error
|
|
38
|
+
* thrown. In this function, however, undefined variables in the template will result in
|
|
39
|
+
* an empty string placed in that location.
|
|
40
|
+
*/
|
|
41
|
+
export declare function makeTemplate(text: string, userSettings?: ToolboxTemplateSettings): (data: unknown) => string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare function pluck<T, K extends keyof T>(sources: T[], key: K): T[K][];
|
|
1
|
+
export declare function pluck<T, K extends keyof T>(sources: readonly T[], key: K): T[K][];
|
package/package.json
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@silvermine/toolbox",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "A library of common TypeScript types, custom type guards, and utility functions.",
|
|
5
5
|
"main": "./dist/commonjs/index",
|
|
6
6
|
"types": "./dist/types/index.d.ts",
|
|
7
7
|
"module": "./dist/esm/index",
|
|
8
8
|
"scripts": {
|
|
9
9
|
"prepare": "grunt build",
|
|
10
|
-
"test": "check-node-version --npm 6.
|
|
10
|
+
"test:node-version": "check-node-version --npm 6.14.12 --print",
|
|
11
|
+
"test": "npm run test:node-version && TS_NODE_PROJECT='tests/tsconfig.json' TS_NODE_FILES=true nyc mocha --opts ./.mocha.opts",
|
|
11
12
|
"commitlint": "commitlint --from 0b9d320"
|
|
12
13
|
},
|
|
13
14
|
"author": "Matt Luedke",
|
|
@@ -29,26 +30,25 @@
|
|
|
29
30
|
"tslib": "1.9.x"
|
|
30
31
|
},
|
|
31
32
|
"devDependencies": {
|
|
32
|
-
"@commitlint/cli": "8.3.5",
|
|
33
|
-
"@commitlint/config-conventional": "8.3.4",
|
|
34
|
-
"@commitlint/travis-cli": "8.3.5",
|
|
35
33
|
"@silvermine/chai-strictly-equal": "1.1.0",
|
|
36
|
-
"@silvermine/eslint-config": "3.
|
|
37
|
-
"@silvermine/
|
|
34
|
+
"@silvermine/eslint-config": "3.1.0-beta.0",
|
|
35
|
+
"@silvermine/standardization": "1.2.1",
|
|
36
|
+
"@silvermine/typescript-config": "git+https://github.com/silvermine/typescript-config.git#23213e33077089e723629dead5342abe6f3b3c8c",
|
|
38
37
|
"@types/chai": "4.1.7",
|
|
39
38
|
"@types/mocha": "5.2.5",
|
|
40
|
-
"@types/node": "
|
|
39
|
+
"@types/node": "12.20.45",
|
|
41
40
|
"@types/sinon": "5.0.5",
|
|
42
41
|
"chai": "4.2.0",
|
|
43
42
|
"check-node-version": "4.0.2",
|
|
44
43
|
"coveralls": "3.0.9",
|
|
45
44
|
"cz-conventional-changelog": "3.1.0",
|
|
45
|
+
"eslint": "6.8.0",
|
|
46
46
|
"grunt": "1.0.4",
|
|
47
47
|
"grunt-cli": "1.3.2",
|
|
48
48
|
"grunt-concurrent": "2.3.1",
|
|
49
49
|
"grunt-contrib-clean": "2.0.0",
|
|
50
50
|
"grunt-contrib-watch": "1.1.0",
|
|
51
|
-
"grunt-eslint": "
|
|
51
|
+
"grunt-eslint": "24.0.0",
|
|
52
52
|
"grunt-exec": "3.0.0",
|
|
53
53
|
"mocha": "5.2.0",
|
|
54
54
|
"nyc": "13.1.0",
|
|
@@ -57,7 +57,7 @@
|
|
|
57
57
|
"standard-version": "5.0.2",
|
|
58
58
|
"ts-node": "7.0.1",
|
|
59
59
|
"tslib": "1.9.3",
|
|
60
|
-
"typescript": "3.
|
|
60
|
+
"typescript": "3.9.5"
|
|
61
61
|
},
|
|
62
62
|
"dependencies": {},
|
|
63
63
|
"config": {
|
package/src/index.ts
CHANGED
|
@@ -22,8 +22,13 @@ export * from './utils/is-promise';
|
|
|
22
22
|
export * from './utils/is-promise-like';
|
|
23
23
|
export * from './utils/is-string';
|
|
24
24
|
export * from './utils/is-undefined';
|
|
25
|
+
export * from './utils/is-null';
|
|
26
|
+
export * from './utils/is-not-null-or-undefined';
|
|
25
27
|
|
|
26
28
|
export * from './utils/chunk';
|
|
27
29
|
export * from './utils/flatten';
|
|
28
30
|
export * from './utils/pluck';
|
|
29
31
|
export * from './utils/delay';
|
|
32
|
+
export * from './utils/get';
|
|
33
|
+
export * from './utils/escape-html';
|
|
34
|
+
export * from './utils/make-template';
|
package/src/utils/chunk.ts
CHANGED