@takeshape/util 9.80.4 → 9.81.3
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/arrays.js +0 -10
- package/dist/async-noop.js +0 -2
- package/dist/billing.js +8 -4
- package/dist/browser.js +0 -2
- package/dist/clone.js +0 -1
- package/dist/common.js +0 -50
- package/dist/delay.js +3 -6
- package/dist/draftjs-templates.js +1 -11
- package/dist/draftjs.js +37 -196
- package/dist/encryption.js +2 -11
- package/dist/get-image-url.js +2 -3
- package/dist/gzip.js +0 -4
- package/dist/highlight-code.js +1 -19
- package/dist/http.js +0 -6
- package/dist/index.js +0 -8
- package/dist/map.js +0 -1
- package/dist/merge.js +3 -20
- package/dist/mime.js +4 -12
- package/dist/predicate.js +0 -3
- package/dist/search-params.js +0 -6
- package/dist/set-in.js +0 -2
- package/dist/sets.js +0 -5
- package/dist/sleep.js +0 -1
- package/dist/sort-object.js +4 -4
- package/dist/strings.js +4 -21
- package/dist/templates.js +1 -25
- package/dist/timezone.js +2 -4
- package/dist/types.js +8 -10
- package/dist/unix-to-iso.js +0 -2
- package/dist/value.js +0 -2
- package/dist/visit.js +1 -15
- package/es/arrays.js +0 -4
- package/es/billing.js +10 -0
- package/es/delay.js +3 -4
- package/es/draftjs-templates.js +1 -1
- package/es/draftjs.js +39 -173
- package/es/encryption.js +2 -3
- package/es/get-image-url.js +2 -1
- package/es/highlight-code.js +0 -1
- package/es/http.js +0 -4
- package/es/index.js +2 -2
- package/es/merge.js +4 -8
- package/es/mime.js +4 -5
- package/es/search-params.js +0 -2
- package/es/set-in.js +1 -1
- package/es/sets.js +0 -3
- package/es/sort-object.js +4 -2
- package/es/strings.js +4 -8
- package/es/templates.js +0 -14
- package/es/timezone.js +2 -2
- package/es/types.js +8 -3
- package/es/visit.js +1 -12
- package/package.json +3 -3
package/dist/encryption.js
CHANGED
|
@@ -4,13 +4,9 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.encrypt = exports.decrypt = void 0;
|
|
7
|
-
|
|
8
7
|
var _crypto = _interopRequireDefault(require("crypto"));
|
|
9
|
-
|
|
10
8
|
var _curry = _interopRequireDefault(require("lodash/curry"));
|
|
11
|
-
|
|
12
9
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
|
-
|
|
14
10
|
const CIPHER_ALGORITHM = 'aes-256-ctr';
|
|
15
11
|
const IV_LENGTH = 16;
|
|
16
12
|
const KEY_ENCODING = 'base64';
|
|
@@ -19,25 +15,20 @@ const CONTENT_ENCODING = 'utf8';
|
|
|
19
15
|
const encrypt = (0, _curry.default)((key, plaintext) => {
|
|
20
16
|
// Initialization Vector
|
|
21
17
|
const iv = _crypto.default.randomBytes(IV_LENGTH);
|
|
22
|
-
|
|
23
18
|
const cipher = _crypto.default.createCipheriv(CIPHER_ALGORITHM, Buffer.from(key, KEY_ENCODING), iv);
|
|
24
|
-
|
|
25
19
|
const cipherText = cipher.update(Buffer.from(plaintext, CONTENT_ENCODING));
|
|
26
20
|
return Buffer.concat([iv, cipherText, cipher.final()]).toString(CIPHER_TEXT_ENCODING);
|
|
27
21
|
});
|
|
28
22
|
exports.encrypt = encrypt;
|
|
29
23
|
const decrypt = (0, _curry.default)((key, encrypted) => {
|
|
30
24
|
const input = Buffer.from(encrypted, CIPHER_TEXT_ENCODING);
|
|
31
|
-
|
|
32
25
|
if (input.length < IV_LENGTH + 1) {
|
|
33
26
|
throw new TypeError('Provided "encrypted" must decrypt to a non-empty string');
|
|
34
|
-
}
|
|
35
|
-
|
|
27
|
+
}
|
|
36
28
|
|
|
29
|
+
// Initialization Vector
|
|
37
30
|
const iv = input.slice(0, IV_LENGTH);
|
|
38
|
-
|
|
39
31
|
const decipher = _crypto.default.createDecipheriv(CIPHER_ALGORITHM, Buffer.from(key, KEY_ENCODING), iv);
|
|
40
|
-
|
|
41
32
|
const cipherText = input.slice(IV_LENGTH);
|
|
42
33
|
return Buffer.concat([decipher.update(cipherText), decipher.final()]).toString(CONTENT_ENCODING);
|
|
43
34
|
});
|
package/dist/get-image-url.js
CHANGED
|
@@ -4,11 +4,10 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.getImageUrl = getImageUrl;
|
|
7
|
-
|
|
8
7
|
var _routing = require("@takeshape/routing");
|
|
9
|
-
|
|
10
8
|
function getImageUrl(path, defaultImageConfig, imageBaseUrl, config) {
|
|
11
|
-
return (0, _routing.getImageUrl)(path, {
|
|
9
|
+
return (0, _routing.getImageUrl)(path, {
|
|
10
|
+
...defaultImageConfig,
|
|
12
11
|
...config
|
|
13
12
|
}, {
|
|
14
13
|
baseUrl: imageBaseUrl
|
package/dist/gzip.js
CHANGED
|
@@ -4,13 +4,9 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.gzip = exports.gunzip = void 0;
|
|
7
|
-
|
|
8
7
|
var _pify = _interopRequireDefault(require("pify"));
|
|
9
|
-
|
|
10
8
|
var _zlib = _interopRequireDefault(require("zlib"));
|
|
11
|
-
|
|
12
9
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
|
-
|
|
14
10
|
const gzip = (0, _pify.default)(_zlib.default.gzip);
|
|
15
11
|
exports.gzip = gzip;
|
|
16
12
|
const gunzip = (0, _pify.default)(_zlib.default.gunzip);
|
package/dist/highlight-code.js
CHANGED
|
@@ -4,50 +4,32 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.highlightCode = void 0;
|
|
7
|
-
|
|
8
7
|
var _prismjs = _interopRequireDefault(require("prismjs"));
|
|
9
|
-
|
|
10
8
|
require("prismjs/components/prism-javascript");
|
|
11
|
-
|
|
12
9
|
require("prismjs/components/prism-markup");
|
|
13
|
-
|
|
14
10
|
require("prismjs/components/prism-markup-templating");
|
|
15
|
-
|
|
16
11
|
require("prismjs/components/prism-css");
|
|
17
|
-
|
|
18
12
|
require("prismjs/components/prism-bash");
|
|
19
|
-
|
|
20
13
|
require("prismjs/components/prism-django");
|
|
21
|
-
|
|
22
14
|
require("prismjs/components/prism-twig");
|
|
23
|
-
|
|
24
15
|
require("prismjs/components/prism-yaml");
|
|
25
|
-
|
|
26
16
|
require("prismjs/components/prism-graphql");
|
|
27
|
-
|
|
28
17
|
require("prismjs/components/prism-sass");
|
|
29
|
-
|
|
30
18
|
require("prismjs/components/prism-scss");
|
|
31
|
-
|
|
32
19
|
require("prismjs/components/prism-markdown");
|
|
33
|
-
|
|
34
20
|
require("prismjs/components/prism-json");
|
|
35
|
-
|
|
36
21
|
var _escape = _interopRequireDefault(require("lodash/escape"));
|
|
37
|
-
|
|
38
22
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
39
|
-
|
|
40
23
|
/*
|
|
41
24
|
* The intention is to move all this to the client package in the end, but right now it's here
|
|
42
25
|
* to be shared between the draftjs / mdx implementations, which span the client / server differently.
|
|
43
26
|
*/
|
|
27
|
+
|
|
44
28
|
const highlightCode = (code, lang) => {
|
|
45
29
|
if (lang) {
|
|
46
30
|
const syntax = _prismjs.default.languages[lang];
|
|
47
31
|
return _prismjs.default.highlight(code, syntax, lang);
|
|
48
32
|
}
|
|
49
|
-
|
|
50
33
|
return (0, _escape.default)(code);
|
|
51
34
|
};
|
|
52
|
-
|
|
53
35
|
exports.highlightCode = highlightCode;
|
package/dist/http.js
CHANGED
|
@@ -4,21 +4,15 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.getBasicAuthString = void 0;
|
|
7
|
-
|
|
8
7
|
const getBasicAuthString = basicAuth => {
|
|
9
8
|
let authString = '';
|
|
10
|
-
|
|
11
9
|
if (basicAuth.username) {
|
|
12
10
|
authString += basicAuth.username;
|
|
13
11
|
}
|
|
14
|
-
|
|
15
12
|
authString += ':';
|
|
16
|
-
|
|
17
13
|
if (basicAuth.password) {
|
|
18
14
|
authString += basicAuth.password;
|
|
19
15
|
}
|
|
20
|
-
|
|
21
16
|
return Buffer.from(authString).toString('base64');
|
|
22
17
|
};
|
|
23
|
-
|
|
24
18
|
exports.getBasicAuthString = getBasicAuthString;
|
package/dist/index.js
CHANGED
|
@@ -3,9 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
|
|
7
6
|
var _common = require("./common");
|
|
8
|
-
|
|
9
7
|
Object.keys(_common).forEach(function (key) {
|
|
10
8
|
if (key === "default" || key === "__esModule") return;
|
|
11
9
|
if (key in exports && exports[key] === _common[key]) return;
|
|
@@ -16,9 +14,7 @@ Object.keys(_common).forEach(function (key) {
|
|
|
16
14
|
}
|
|
17
15
|
});
|
|
18
16
|
});
|
|
19
|
-
|
|
20
17
|
var _encryption = require("./encryption");
|
|
21
|
-
|
|
22
18
|
Object.keys(_encryption).forEach(function (key) {
|
|
23
19
|
if (key === "default" || key === "__esModule") return;
|
|
24
20
|
if (key in exports && exports[key] === _encryption[key]) return;
|
|
@@ -29,9 +25,7 @@ Object.keys(_encryption).forEach(function (key) {
|
|
|
29
25
|
}
|
|
30
26
|
});
|
|
31
27
|
});
|
|
32
|
-
|
|
33
28
|
var _gzip = require("./gzip");
|
|
34
|
-
|
|
35
29
|
Object.keys(_gzip).forEach(function (key) {
|
|
36
30
|
if (key === "default" || key === "__esModule") return;
|
|
37
31
|
if (key in exports && exports[key] === _gzip[key]) return;
|
|
@@ -42,9 +36,7 @@ Object.keys(_gzip).forEach(function (key) {
|
|
|
42
36
|
}
|
|
43
37
|
});
|
|
44
38
|
});
|
|
45
|
-
|
|
46
39
|
var _searchParams = require("./search-params");
|
|
47
|
-
|
|
48
40
|
Object.keys(_searchParams).forEach(function (key) {
|
|
49
41
|
if (key === "default" || key === "__esModule") return;
|
|
50
42
|
if (key in exports && exports[key] === _searchParams[key]) return;
|
package/dist/map.js
CHANGED
package/dist/merge.js
CHANGED
|
@@ -7,25 +7,15 @@ exports.mergeWithArrayConcat = mergeWithArrayConcat;
|
|
|
7
7
|
exports.mergeWithArrayMerge = mergeWithArrayMerge;
|
|
8
8
|
exports.rebaseArray = rebaseArray;
|
|
9
9
|
exports.rebaseObject = rebaseObject;
|
|
10
|
-
|
|
11
10
|
var _isArray = _interopRequireDefault(require("lodash/isArray"));
|
|
12
|
-
|
|
13
11
|
var _mergeWith = _interopRequireDefault(require("lodash/mergeWith"));
|
|
14
|
-
|
|
15
12
|
var _merge = _interopRequireDefault(require("lodash/merge"));
|
|
16
|
-
|
|
17
13
|
var _isNull = _interopRequireDefault(require("lodash/isNull"));
|
|
18
|
-
|
|
19
14
|
var _difference = _interopRequireDefault(require("lodash/difference"));
|
|
20
|
-
|
|
21
15
|
var _omit = _interopRequireDefault(require("lodash/omit"));
|
|
22
|
-
|
|
23
16
|
var _isEqual = _interopRequireDefault(require("lodash/isEqual"));
|
|
24
|
-
|
|
25
17
|
var _union = _interopRequireDefault(require("lodash/union"));
|
|
26
|
-
|
|
27
18
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
28
|
-
|
|
29
19
|
/**
|
|
30
20
|
* Lodash `mergeWith` customizer to concat arrays
|
|
31
21
|
*/
|
|
@@ -34,49 +24,42 @@ const arrayConcatCustomizer = (value, srcValue) => {
|
|
|
34
24
|
return value.concat(srcValue);
|
|
35
25
|
}
|
|
36
26
|
};
|
|
27
|
+
|
|
37
28
|
/**
|
|
38
29
|
* Lodash `mergeWith` loaded with a customizer that concatenates arrays for a
|
|
39
30
|
* deeper merge.
|
|
40
31
|
*/
|
|
41
|
-
|
|
42
|
-
|
|
43
32
|
function mergeWithArrayConcat(object, source) {
|
|
44
33
|
return (0, _mergeWith.default)(object, source, arrayConcatCustomizer);
|
|
45
34
|
}
|
|
35
|
+
|
|
46
36
|
/**
|
|
47
37
|
* Lodash `mergeWith` customizer to merge arrays
|
|
48
38
|
*/
|
|
49
|
-
|
|
50
|
-
|
|
51
39
|
const arrayMergeCustomizer = (value, srcValue) => {
|
|
52
40
|
if ((0, _isArray.default)(value) && (0, _isArray.default)(srcValue)) {
|
|
53
41
|
return (0, _merge.default)(value, srcValue).filter(val => !(0, _isNull.default)(val));
|
|
54
42
|
}
|
|
55
43
|
};
|
|
44
|
+
|
|
56
45
|
/**
|
|
57
46
|
* Lodash `mergeWith` loaded with a customizer that merges arrays at the same
|
|
58
47
|
* object path. Array items set to `null` will be removed.
|
|
59
48
|
*/
|
|
60
|
-
|
|
61
|
-
|
|
62
49
|
function mergeWithArrayMerge(object, source) {
|
|
63
50
|
return (0, _mergeWith.default)(object, source, arrayMergeCustomizer);
|
|
64
51
|
}
|
|
65
|
-
|
|
66
52
|
function rebaseObject(to, base, from) {
|
|
67
53
|
const fromKeys = Object.keys(from);
|
|
68
54
|
const removedKeys = (0, _difference.default)(Object.keys(base), fromKeys);
|
|
69
55
|
const newObj = (0, _omit.default)(to, removedKeys);
|
|
70
|
-
|
|
71
56
|
for (const key of fromKeys) {
|
|
72
57
|
if (!(0, _isEqual.default)(base[key], from[key])) {
|
|
73
58
|
newObj[key] = from[key];
|
|
74
59
|
}
|
|
75
60
|
}
|
|
76
|
-
|
|
77
61
|
return newObj;
|
|
78
62
|
}
|
|
79
|
-
|
|
80
63
|
function rebaseArray(to, base, from) {
|
|
81
64
|
const removed = (0, _difference.default)(base, from);
|
|
82
65
|
const added = (0, _difference.default)(from, base);
|
package/dist/mime.js
CHANGED
|
@@ -5,41 +5,33 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.contentType = contentType;
|
|
7
7
|
exports.shouldCompress = shouldCompress;
|
|
8
|
-
|
|
9
8
|
var _mimeTypes = _interopRequireDefault(require("mime-types"));
|
|
10
|
-
|
|
11
9
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
10
|
+
const compressedMimeTypes = new Set(['application/atom+xml', 'application/javascript', 'application/json', 'application/ld+json', 'application/manifest+json', 'application/rdf+xml', 'application/rss+xml', 'application/schema+json', 'application/vnd.geo+json', 'application/vnd.ms-fontobject', 'application/x-font-ttf', 'application/x-javascript', 'application/x-web-app-manifest+json', 'application/xhtml+xml', 'application/xml', 'font/eot', 'font/otf', 'font/opentype', 'image/bmp', 'image/svg+xml', 'image/vnd.microsoft.icon', 'image/x-icon', 'text/cache-manifest', 'text/css', 'text/html', 'text/javascript', 'text/plain', 'text/vcard', 'text/vnd.rim.location.xloc', 'text/vtt', 'text/x-component', 'text/x-cross-domain-policy', 'text/xml']);
|
|
12
11
|
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
// Application/octetstream
|
|
15
13
|
const DEFAULT_TYPE = _mimeTypes.default.lookup('bin');
|
|
14
|
+
|
|
16
15
|
/**
|
|
17
16
|
* Gets the content type of the file, based on it's extension.
|
|
18
17
|
* @param {String} src Path to file fow which content type should be evaluated.
|
|
19
18
|
* @return {String} Returns string with content type and charset.
|
|
20
19
|
*/
|
|
21
|
-
|
|
22
|
-
|
|
23
20
|
function contentType(src) {
|
|
24
21
|
let type = (_mimeTypes.default.lookup(src) || DEFAULT_TYPE).replace('-', '');
|
|
25
|
-
|
|
26
22
|
const charset = _mimeTypes.default.charset(type);
|
|
27
|
-
|
|
28
23
|
if (charset) {
|
|
29
24
|
type += '; charset=' + charset;
|
|
30
25
|
}
|
|
31
|
-
|
|
32
26
|
return type;
|
|
33
27
|
}
|
|
28
|
+
|
|
34
29
|
/**
|
|
35
30
|
* Determines whether we should compress based on file extension
|
|
36
31
|
* @param {String} src Path to file fow which content type should be evaluated.
|
|
37
32
|
* @return {Boolean} Returns true if we should compress
|
|
38
33
|
*/
|
|
39
|
-
|
|
40
|
-
|
|
41
34
|
function shouldCompress(src) {
|
|
42
35
|
const mimeType = _mimeTypes.default.lookup(src);
|
|
43
|
-
|
|
44
36
|
return Boolean(mimeType && compressedMimeTypes.has(mimeType));
|
|
45
37
|
}
|
package/dist/predicate.js
CHANGED
|
@@ -6,15 +6,12 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.equals = equals;
|
|
7
7
|
exports.falsy = falsy;
|
|
8
8
|
exports.not = not;
|
|
9
|
-
|
|
10
9
|
function not(predicate) {
|
|
11
10
|
return value => !predicate(value);
|
|
12
11
|
}
|
|
13
|
-
|
|
14
12
|
function equals(a) {
|
|
15
13
|
return b => a === b;
|
|
16
14
|
}
|
|
17
|
-
|
|
18
15
|
function falsy(obj) {
|
|
19
16
|
return !obj;
|
|
20
17
|
}
|
package/dist/search-params.js
CHANGED
|
@@ -6,25 +6,19 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.concatURLSearchParams = concatURLSearchParams;
|
|
7
7
|
exports.toSearchParamsEntries = toSearchParamsEntries;
|
|
8
8
|
exports.toSearchParamsRecord = toSearchParamsRecord;
|
|
9
|
-
|
|
10
9
|
var _url = require("url");
|
|
11
|
-
|
|
12
10
|
function toSearchParamsEntries(obj) {
|
|
13
11
|
if (obj instanceof _url.URLSearchParams) {
|
|
14
12
|
return [...obj.entries()];
|
|
15
13
|
}
|
|
16
|
-
|
|
17
14
|
if (typeof obj === 'object' && !Array.isArray(obj)) {
|
|
18
15
|
return Object.entries(obj).map(([k, v]) => [k, (v === null || v === void 0 ? void 0 : v.toString()) ?? '']);
|
|
19
16
|
}
|
|
20
|
-
|
|
21
17
|
return [...new _url.URLSearchParams(obj).entries()];
|
|
22
18
|
}
|
|
23
|
-
|
|
24
19
|
function toSearchParamsRecord(obj) {
|
|
25
20
|
return Object.fromEntries(toSearchParamsEntries(obj));
|
|
26
21
|
}
|
|
27
|
-
|
|
28
22
|
function concatURLSearchParams(...searchParamsInput) {
|
|
29
23
|
const entries = searchParamsInput.flatMap(item => item ? toSearchParamsEntries(item) : []);
|
|
30
24
|
return new _url.URLSearchParams(entries);
|
package/dist/set-in.js
CHANGED
package/dist/sets.js
CHANGED
|
@@ -5,22 +5,17 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.addAll = addAll;
|
|
7
7
|
exports.mapSet = mapSet;
|
|
8
|
-
|
|
9
8
|
function addAll(set, iterable) {
|
|
10
9
|
for (const value of iterable) {
|
|
11
10
|
set.add(value);
|
|
12
11
|
}
|
|
13
|
-
|
|
14
12
|
return set;
|
|
15
13
|
}
|
|
16
|
-
|
|
17
14
|
function mapSet(set, fn) {
|
|
18
15
|
const result = new Array(set.size);
|
|
19
16
|
let i = 0;
|
|
20
|
-
|
|
21
17
|
for (const value of set) {
|
|
22
18
|
result[i++] = fn(value);
|
|
23
19
|
}
|
|
24
|
-
|
|
25
20
|
return result;
|
|
26
21
|
}
|
package/dist/sleep.js
CHANGED
package/dist/sort-object.js
CHANGED
|
@@ -4,18 +4,18 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.sortObject = void 0;
|
|
7
|
-
|
|
8
7
|
/**
|
|
9
8
|
* Object key order is not guarenteed. This can be useful
|
|
10
9
|
* but should not be depended upon.
|
|
11
10
|
*/
|
|
12
11
|
const sortObject = obj => {
|
|
13
12
|
// Convert object to array of key-value pairs
|
|
14
|
-
const arr = Object.entries(obj);
|
|
13
|
+
const arr = Object.entries(obj);
|
|
15
14
|
|
|
16
|
-
|
|
15
|
+
// Sort array by key
|
|
16
|
+
arr.sort(([key1], [key2]) => key1.localeCompare(key2));
|
|
17
17
|
|
|
18
|
+
// Convert array back to object
|
|
18
19
|
return Object.fromEntries(arr);
|
|
19
20
|
};
|
|
20
|
-
|
|
21
21
|
exports.sortObject = sortObject;
|
package/dist/strings.js
CHANGED
|
@@ -9,77 +9,60 @@ exports.isEmptyString = isEmptyString;
|
|
|
9
9
|
exports.isIntegerLike = isIntegerLike;
|
|
10
10
|
exports.isUuid = isUuid;
|
|
11
11
|
exports.pascalCase = pascalCase;
|
|
12
|
-
|
|
13
12
|
var _upperFirst = _interopRequireDefault(require("lodash/upperFirst"));
|
|
14
|
-
|
|
15
13
|
var _camelCase2 = _interopRequireDefault(require("lodash/camelCase"));
|
|
16
|
-
|
|
17
14
|
var _isEmpty = _interopRequireDefault(require("lodash/isEmpty"));
|
|
18
|
-
|
|
19
15
|
var _isString = _interopRequireDefault(require("lodash/isString"));
|
|
20
|
-
|
|
21
16
|
var _arrays = require("./arrays");
|
|
22
|
-
|
|
23
17
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
24
|
-
|
|
25
18
|
const camelCase = _camelCase2.default;
|
|
19
|
+
|
|
26
20
|
/**
|
|
27
21
|
* Special function for preserving namespace case when pascal-casing.
|
|
28
22
|
*/
|
|
29
|
-
|
|
30
23
|
exports.camelCase = camelCase;
|
|
31
|
-
|
|
32
24
|
function formatShapeName(str, options) {
|
|
33
25
|
const strings = (0, _arrays.ensureArray)(str);
|
|
34
26
|
const shapeNameIndex = (options === null || options === void 0 ? void 0 : options.shapeNameIndex) ?? 0;
|
|
35
|
-
const shapeName = strings.at(shapeNameIndex);
|
|
27
|
+
const shapeName = strings.at(shapeNameIndex);
|
|
36
28
|
|
|
29
|
+
// If the shapeNameIndex is incorrect, behave as normal
|
|
37
30
|
if (!shapeName) {
|
|
38
31
|
throw new Error(`Could not find a ShapeName at index '${shapeNameIndex}'`);
|
|
39
32
|
}
|
|
40
|
-
|
|
41
33
|
const prefix = strings.slice(0, Math.max(shapeNameIndex, 0));
|
|
42
34
|
const suffix = strings.slice(shapeNameIndex + 1);
|
|
43
35
|
let arr = [];
|
|
44
|
-
|
|
45
36
|
if (prefix) {
|
|
46
37
|
arr = [...arr, pascalCase(prefix)];
|
|
47
38
|
}
|
|
48
|
-
|
|
49
39
|
if (shapeName.length > 2 && shapeName.startsWith('TS') && shapeName.charAt(2) === shapeName.charAt(2).toUpperCase()) {
|
|
50
40
|
// Built-in shape, prefixed with `TS`
|
|
51
41
|
arr = [...arr, shapeName];
|
|
52
42
|
} else {
|
|
53
43
|
arr = [...arr, pascalCase(shapeName)];
|
|
54
44
|
}
|
|
55
|
-
|
|
56
45
|
if (suffix) {
|
|
57
46
|
arr = [...arr, pascalCase(suffix)];
|
|
58
47
|
}
|
|
59
|
-
|
|
60
48
|
return arr.join('');
|
|
61
49
|
}
|
|
50
|
+
|
|
62
51
|
/**
|
|
63
52
|
* Optional config triggers a namespace-preserving behavior for built-in shapes starting with `TS`.
|
|
64
53
|
*/
|
|
65
|
-
|
|
66
|
-
|
|
67
54
|
function pascalCase(str) {
|
|
68
55
|
return (0, _upperFirst.default)(camelCase(str));
|
|
69
56
|
}
|
|
70
|
-
|
|
71
57
|
function isUuid(str) {
|
|
72
58
|
return Boolean(/\w{8,}(-\w{4,}){3,}-\w{12,}/.exec(str));
|
|
73
59
|
}
|
|
74
|
-
|
|
75
60
|
function isEmptyString(str) {
|
|
76
61
|
return (0, _isString.default)(str) && (0, _isEmpty.default)(str);
|
|
77
62
|
}
|
|
78
|
-
|
|
79
63
|
function isIntegerLike(value) {
|
|
80
64
|
if (typeof value === 'number') {
|
|
81
65
|
return true;
|
|
82
66
|
}
|
|
83
|
-
|
|
84
67
|
return /^\d+$/.test(value);
|
|
85
68
|
}
|
package/dist/templates.js
CHANGED
|
@@ -10,44 +10,33 @@ exports.imageTemplate = imageTemplate;
|
|
|
10
10
|
exports.imageTemplateMdx = imageTemplateMdx;
|
|
11
11
|
exports.oembedTemplate = oembedTemplate;
|
|
12
12
|
exports.oembedTemplateMdx = oembedTemplateMdx;
|
|
13
|
-
|
|
14
13
|
var _classnames = _interopRequireDefault(require("classnames"));
|
|
15
|
-
|
|
16
14
|
var _highlightCode = require("./highlight-code");
|
|
17
|
-
|
|
18
15
|
var _escape = _interopRequireDefault(require("lodash/escape"));
|
|
19
|
-
|
|
20
16
|
var _routing = require("@takeshape/routing");
|
|
21
|
-
|
|
22
17
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
23
|
-
|
|
24
18
|
/*
|
|
25
19
|
* The intention is to move all this to the client package in the end, but right now it's here
|
|
26
20
|
* to be shared between the draftjs / mdx implementations, which span the client / server differently.
|
|
27
21
|
*/
|
|
22
|
+
|
|
28
23
|
function getApplyPrefix(prefix) {
|
|
29
24
|
return className => className ? prefix + className : '';
|
|
30
25
|
}
|
|
31
|
-
|
|
32
26
|
function attrs(obj) {
|
|
33
27
|
const attrStrings = [];
|
|
34
28
|
const attrNames = Object.keys(obj);
|
|
35
29
|
attrNames.sort();
|
|
36
|
-
|
|
37
30
|
for (const attrName of attrNames) {
|
|
38
31
|
const value = obj[attrName];
|
|
39
|
-
|
|
40
32
|
if (value) {
|
|
41
33
|
attrStrings.push(`${attrName}="${(0, _escape.default)(value)}"`);
|
|
42
34
|
}
|
|
43
35
|
}
|
|
44
|
-
|
|
45
36
|
return attrStrings.length ? ' ' + attrStrings.join(' ') : '';
|
|
46
37
|
}
|
|
47
|
-
|
|
48
38
|
function imageTemplate(applyPrefix, data) {
|
|
49
39
|
var _data$link;
|
|
50
|
-
|
|
51
40
|
const {
|
|
52
41
|
caption,
|
|
53
42
|
credit,
|
|
@@ -56,20 +45,16 @@ function imageTemplate(applyPrefix, data) {
|
|
|
56
45
|
asset,
|
|
57
46
|
imageParams
|
|
58
47
|
} = data;
|
|
59
|
-
|
|
60
48
|
if (!asset) {
|
|
61
49
|
return '';
|
|
62
50
|
}
|
|
63
|
-
|
|
64
51
|
const imageUrl = (0, _routing.getImageUrl)(asset.path, imageParams);
|
|
65
52
|
let figCaption = '';
|
|
66
|
-
|
|
67
53
|
if (caption || credit) {
|
|
68
54
|
const htmlCaption = caption ? `<span class="${applyPrefix('caption')}">${caption}</span>` : '';
|
|
69
55
|
const htmlCredit = credit ? `<span class="${applyPrefix('credit')}">${credit}</span>` : '';
|
|
70
56
|
figCaption = `<figcaption>${htmlCaption} ${htmlCredit}</figcaption>`;
|
|
71
57
|
}
|
|
72
|
-
|
|
73
58
|
const classes = (0, _classnames.default)(applyPrefix(alignment), applyPrefix(size));
|
|
74
59
|
const classAttr = classes ? ` class="${classes}"` : '';
|
|
75
60
|
const imgAttrs = attrs({
|
|
@@ -77,39 +62,30 @@ function imageTemplate(applyPrefix, data) {
|
|
|
77
62
|
title: asset.title
|
|
78
63
|
});
|
|
79
64
|
let image = `<img${imgAttrs} src="${imageUrl}"/>`;
|
|
80
|
-
|
|
81
65
|
if ((_data$link = data.link) !== null && _data$link !== void 0 && _data$link.url) {
|
|
82
66
|
const target = data.link.external ? ' target="blank" rel="noopener noreferrer"' : '';
|
|
83
67
|
image = `<a href="${data.link.url}"${target}>${image}</a>`;
|
|
84
68
|
}
|
|
85
|
-
|
|
86
69
|
return `<figure${classAttr}>${image}${figCaption}</figure>`;
|
|
87
70
|
}
|
|
88
|
-
|
|
89
71
|
function renderMdx(tag, attributes, data, children) {
|
|
90
72
|
const tagWithAttributes = `${tag} ${attributes.map(attr => `${attr}="${(0, _escape.default)(data[attr])}"`).join(' ')}`;
|
|
91
|
-
|
|
92
73
|
if (children) {
|
|
93
74
|
return `<${tagWithAttributes}>
|
|
94
75
|
${children.replace(/[\n\r]+$/, '')}
|
|
95
76
|
</${tag}>`;
|
|
96
77
|
}
|
|
97
|
-
|
|
98
78
|
return `<${tagWithAttributes}/>`;
|
|
99
79
|
}
|
|
100
|
-
|
|
101
80
|
function imageTemplateMdx(applyPrefix, data) {
|
|
102
81
|
return renderMdx(applyPrefix('Image'), ['id', 'caption', 'credit', 'link', 'linkisexternal', 'alignment', 'size', 'src'], data);
|
|
103
82
|
}
|
|
104
|
-
|
|
105
83
|
function oembedTemplate(applyPrefix, data) {
|
|
106
84
|
return `<div class="${applyPrefix('oembed')}">${data.html}</div>`;
|
|
107
85
|
}
|
|
108
|
-
|
|
109
86
|
function oembedTemplateMdx(applyPrefix, data) {
|
|
110
87
|
return renderMdx(applyPrefix('Oembed'), ['url', 'author_name', 'author_url', 'width', 'height', 'type', 'cache_age', 'provider_name', 'version'], data, data.html);
|
|
111
88
|
}
|
|
112
|
-
|
|
113
89
|
function codeTemplate(applyPrefix, data) {
|
|
114
90
|
const {
|
|
115
91
|
text,
|