@instructure/ui-utils 11.7.8 → 11.7.9-pr-snapshot-1792147648392

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.
Files changed (48) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/es/camelize.js +2 -44
  3. package/es/capitalizeFirstLetter.js +2 -34
  4. package/es/cloneArray.js +9 -42
  5. package/es/combineDataCid.js +4 -34
  6. package/es/convertCase.js +1 -25
  7. package/es/createChainedFunction.js +26 -75
  8. package/es/deepEqual.js +1 -25
  9. package/es/generateId.js +8 -50
  10. package/es/getBrowser.js +40 -71
  11. package/es/hash.js +40 -65
  12. package/es/index.js +1 -24
  13. package/es/isBaseTheme.js +22 -42
  14. package/es/isEmpty.js +6 -29
  15. package/es/mergeDeep.js +48 -74
  16. package/es/ms.js +12 -53
  17. package/es/parseUnit.js +7 -48
  18. package/es/pascalize.js +2 -44
  19. package/es/px.js +14 -56
  20. package/es/safeHref.js +64 -96
  21. package/es/safeLinkProps.js +9 -50
  22. package/es/shallowEqual.js +22 -72
  23. package/es/within.js +2 -39
  24. package/package.json +8 -11
  25. package/tsconfig.build.json +0 -3
  26. package/lib/camelize.js +0 -53
  27. package/lib/capitalizeFirstLetter.js +0 -43
  28. package/lib/cloneArray.js +0 -52
  29. package/lib/combineDataCid.js +0 -41
  30. package/lib/convertCase.js +0 -19
  31. package/lib/createChainedFunction.js +0 -86
  32. package/lib/deepEqual.js +0 -38
  33. package/lib/generateId.js +0 -58
  34. package/lib/getBrowser.js +0 -85
  35. package/lib/hash.js +0 -82
  36. package/lib/index.js +0 -187
  37. package/lib/isBaseTheme.js +0 -50
  38. package/lib/isEmpty.js +0 -39
  39. package/lib/mergeDeep.js +0 -89
  40. package/lib/ms.js +0 -62
  41. package/lib/package.json +0 -1
  42. package/lib/parseUnit.js +0 -57
  43. package/lib/pascalize.js +0 -55
  44. package/lib/px.js +0 -68
  45. package/lib/safeHref.js +0 -115
  46. package/lib/safeLinkProps.js +0 -59
  47. package/lib/shallowEqual.js +0 -85
  48. package/lib/within.js +0 -48
package/lib/mergeDeep.js DELETED
@@ -1,89 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
- exports.mergeDeep = mergeDeep;
8
- /*
9
- * The MIT License (MIT)
10
- *
11
- * Copyright (c) 2015 - present Instructure, Inc.
12
- *
13
- * Permission is hereby granted, free of charge, to any person obtaining a copy
14
- * of this software and associated documentation files (the "Software"), to deal
15
- * in the Software without restriction, including without limitation the rights
16
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
17
- * copies of the Software, and to permit persons to whom the Software is
18
- * furnished to do so, subject to the following conditions:
19
- *
20
- * The above copyright notice and this permission notice shall be included in all
21
- * copies or substantial portions of the Software.
22
- *
23
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
24
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
26
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
28
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
29
- * SOFTWARE.
30
- */
31
-
32
- /**
33
- * ---
34
- * category: utilities/Misc
35
- * ---
36
- * Deep merge N objects into a single result object.
37
- * Merging creates a new object, so that none of the arguments are modified.
38
- *
39
- * @module mergeDeep
40
- *
41
- * @param {Object} args objects to merge
42
- * @returns {Object} a new object with items from all arguments
43
- */
44
- function mergeDeep(...args) {
45
- // note: This could be typed as the union of its args, but since
46
- // its barely used its not worth the effort currently
47
- let target = {};
48
- args.forEach(arg => {
49
- target = mergeSourceIntoTarget(target, arg);
50
- });
51
- return target;
52
- }
53
- function mergeSourceIntoTarget(target, source) {
54
- if (isObject(source)) {
55
- const keys = [...Object.keys(source), ...Object.getOwnPropertySymbols(source)];
56
- const merged = {
57
- ...target
58
- };
59
- keys.forEach(key => {
60
- // Block prototype-pollution payloads. These keys can arrive via
61
- // JSON.parse or other deserialization in consumer-supplied
62
- // themeOverride props.
63
- if (key === '__proto__' || key === 'prototype' || key === 'constructor') {
64
- return;
65
- }
66
- if (isObject(target[key]) && isObject(source[key])) {
67
- merged[key] = mergeSourceIntoTarget(target[key], source[key]);
68
- } else if (isArray(source[key]) && isArray(target[key])) {
69
- merged[key] = [...new Set([...target[key], ...source[key]])];
70
- } else if (isArray(target[key])) {
71
- merged[key] = [...new Set([...target[key], ...[source[key]]])];
72
- } else {
73
- merged[key] = source[key];
74
- }
75
- });
76
- return merged;
77
- } else {
78
- return {
79
- ...target
80
- };
81
- }
82
- }
83
- function isObject(item) {
84
- return item && (typeof item === 'object' || typeof item === 'function') && !Array.isArray(item);
85
- }
86
- function isArray(item) {
87
- return Array.isArray(item);
88
- }
89
- var _default = exports.default = mergeDeep;
package/lib/ms.js DELETED
@@ -1,62 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
- exports.ms = ms;
8
- var _parseUnit = require("./parseUnit.js");
9
- /*
10
- * The MIT License (MIT)
11
- *
12
- * Copyright (c) 2015 - present Instructure, Inc.
13
- *
14
- * Permission is hereby granted, free of charge, to any person obtaining a copy
15
- * of this software and associated documentation files (the "Software"), to deal
16
- * in the Software without restriction, including without limitation the rights
17
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
18
- * copies of the Software, and to permit persons to whom the Software is
19
- * furnished to do so, subject to the following conditions:
20
- *
21
- * The above copyright notice and this permission notice shall be included in all
22
- * copies or substantial portions of the Software.
23
- *
24
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
25
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
26
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
27
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
28
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
29
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30
- * SOFTWARE.
31
- */
32
-
33
- /**
34
- * ---
35
- * category: utilities/Misc
36
- * ---
37
- * Converts a unit value time combination (s, ms) to a number representing ms
38
- *
39
- * @module ms
40
- *
41
- * Example inputs:
42
- * - '100s'
43
- * - '20ms'
44
- *
45
- * @param {String|Number} val
46
- * @returns {Number} Returns numerical representation of milliseconds
47
- */
48
- function ms(val) {
49
- // TODO: throw an error if val is not number or string
50
- if (!val || typeof val === 'number') {
51
- return val;
52
- }
53
- const [num, unit] = (0, _parseUnit.parseUnit)(val);
54
- if (unit === 'ms') {
55
- return num;
56
- } else if (unit === 's') {
57
- return num * 1000;
58
- } else {
59
- return num;
60
- }
61
- }
62
- var _default = exports.default = ms;
package/lib/package.json DELETED
@@ -1 +0,0 @@
1
- {"type":"commonjs"}
package/lib/parseUnit.js DELETED
@@ -1,57 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
- exports.parseUnit = parseUnit;
8
- /*
9
- * The MIT License (MIT)
10
- *
11
- * Copyright (c) 2015 - present Instructure, Inc.
12
- *
13
- * Permission is hereby granted, free of charge, to any person obtaining a copy
14
- * of this software and associated documentation files (the "Software"), to deal
15
- * in the Software without restriction, including without limitation the rights
16
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
17
- * copies of the Software, and to permit persons to whom the Software is
18
- * furnished to do so, subject to the following conditions:
19
- *
20
- * The above copyright notice and this permission notice shall be included in all
21
- * copies or substantial portions of the Software.
22
- *
23
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
24
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
26
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
28
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
29
- * SOFTWARE.
30
- */
31
-
32
- /**
33
- * ---
34
- * category: utilities/Misc
35
- * ---
36
- * Converts a CSS unit value combination into an array of type [ value, unit ]
37
- *
38
- * @module parseUnit
39
- *
40
- * Example inputs:
41
- * - '100px'
42
- * - '20rem'
43
- * - '10vh'
44
- * - '400vmin'
45
- *
46
- * @param {string|number} str
47
- * @returns {Array} Returns array of shape [ value, unit ] Unit is '' if it could
48
- * not be parsed
49
- */
50
-
51
- function parseUnit(str) {
52
- const value = `${str}`;
53
- // eslint-disable-next-line no-useless-escape
54
- const match = value.match(/[\d.\-\+]*\s*(.*)/);
55
- return [parseFloat(value), match && match.length > 0 ? match[1] : ''];
56
- }
57
- var _default = exports.default = parseUnit;
package/lib/pascalize.js DELETED
@@ -1,55 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
- exports.pascalize = pascalize;
8
- var _capitalizeFirstLetter = require("./capitalizeFirstLetter.js");
9
- var _camelize = require("./camelize.js");
10
- /*
11
- * The MIT License (MIT)
12
- *
13
- * Copyright (c) 2015 - present Instructure, Inc.
14
- *
15
- * Permission is hereby granted, free of charge, to any person obtaining a copy
16
- * of this software and associated documentation files (the "Software"), to deal
17
- * in the Software without restriction, including without limitation the rights
18
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
19
- * copies of the Software, and to permit persons to whom the Software is
20
- * furnished to do so, subject to the following conditions:
21
- *
22
- * The above copyright notice and this permission notice shall be included in all
23
- * copies or substantial portions of the Software.
24
- *
25
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
26
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
27
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
28
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
29
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
30
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
31
- * SOFTWARE.
32
- */
33
-
34
- /**
35
- * ---
36
- * category: utilities/Misc
37
- * ---
38
- * Converts a hyphenated or camel cased string to pascal case
39
- *
40
- * Example inputs:
41
- * - 'foo-bar'
42
- * - 'baz-qux'
43
- *
44
- * Example outputs:
45
- * - 'FooBar'
46
- * - 'BazQux'
47
- *
48
- * @module pascalize
49
- * @param {String} str
50
- * @returns {String} Returns pascal cased string
51
- */
52
- function pascalize(str) {
53
- return (0, _capitalizeFirstLetter.capitalizeFirstLetter)((0, _camelize.camelize)(str));
54
- }
55
- var _default = exports.default = pascalize;
package/lib/px.js DELETED
@@ -1,68 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
- exports.px = px;
8
- var _canUseDOM = require("@instructure/ui-dom-utils/lib/canUseDOM.js");
9
- var _getFontSize = require("@instructure/ui-dom-utils/lib/getFontSize.js");
10
- var _parseUnit = require("./parseUnit.js");
11
- /*
12
- * The MIT License (MIT)
13
- *
14
- * Copyright (c) 2015 - present Instructure, Inc.
15
- *
16
- * Permission is hereby granted, free of charge, to any person obtaining a copy
17
- * of this software and associated documentation files (the "Software"), to deal
18
- * in the Software without restriction, including without limitation the rights
19
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
20
- * copies of the Software, and to permit persons to whom the Software is
21
- * furnished to do so, subject to the following conditions:
22
- *
23
- * The above copyright notice and this permission notice shall be included in all
24
- * copies or substantial portions of the Software.
25
- *
26
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
27
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
28
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
29
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
30
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
31
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
32
- * SOFTWARE.
33
- */
34
-
35
- /**
36
- * ---
37
- * category: utilities/Misc
38
- * ---
39
- * Converts a unit value size combination (em, rem, px) to a number representing px
40
- *
41
- * Example inputs:
42
- * - '100rem'
43
- * - '20em'
44
- * - '40px'
45
- *
46
- * @module px
47
- *
48
- * @param {String|number} val The value to look up. If it's a number its just returned as is.
49
- * @param {Document|Window|Node|React.ReactElement |React.Component|null} el - containing element, for context measure is em (defaults to `document.body`)
50
- * @returns {Number} Returns numerical representation of pixels
51
- */
52
- function px(val, el) {
53
- // TODO !val should not be needed
54
- if (!val || typeof val === 'number') {
55
- return val;
56
- }
57
- const [num, unit] = (0, _parseUnit.parseUnit)(val);
58
- if (unit === 'rem') {
59
- return num * (0, _getFontSize.getFontSize)();
60
- } else if (unit === 'em') {
61
- const doc = _canUseDOM.canUseDOM ? document.body : null;
62
- const container = el || doc;
63
- return num * (0, _getFontSize.getFontSize)(container);
64
- } else {
65
- return num;
66
- }
67
- }
68
- var _default = exports.default = px;
package/lib/safeHref.js DELETED
@@ -1,115 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
6
- });
7
- exports.default = void 0;
8
- exports.safeHref = safeHref;
9
- var _dompurify = _interopRequireDefault(require("dompurify"));
10
- /*
11
- * The MIT License (MIT)
12
- *
13
- * Copyright (c) 2015 - present Instructure, Inc.
14
- *
15
- * Permission is hereby granted, free of charge, to any person obtaining a copy
16
- * of this software and associated documentation files (the "Software"), to deal
17
- * in the Software without restriction, including without limitation the rights
18
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
19
- * copies of the Software, and to permit persons to whom the Software is
20
- * furnished to do so, subject to the following conditions:
21
- *
22
- * The above copyright notice and this permission notice shall be included in all
23
- * copies or substantial portions of the Software.
24
- *
25
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
26
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
27
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
28
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
29
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
30
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
31
- * SOFTWARE.
32
- */
33
-
34
- // Use a dedicated DOMPurify instance instead of the shared singleton so our
35
- // HTML profile never leaks onto the global instance other code relies on, and
36
- // our validation stays correct even if someone else mutates the singleton via
37
- // setConfig(). `window` is guarded for SSR; passing `undefined` yields an
38
- // unsupported instance, in which case we fall back to `ssrSafeHref`.
39
- const purify = (0, _dompurify.default)(typeof window === 'undefined' ? undefined : window);
40
- if (purify.isSupported) {
41
- purify.setConfig({
42
- USE_PROFILES: {
43
- html: true
44
- }
45
- });
46
- }
47
- const SAFE_SCHEMES = ['http:', 'https:', 'ftp:', 'ftps:', 'mailto:', 'tel:', 'sms:', 'callto:', 'cid:', 'xmpp:', 'matrix:', 'webcal:', 'feed:', 'geo:'];
48
-
49
- /**
50
- * Remove all control characters (e.g. line break, tab, escape) and trim the
51
- * string
52
- */
53
- function normalizeValue(value) {
54
- // eslint-disable-next-line no-control-regex
55
- return value.replace(/[\u0000-\u001F\u007F]/g, '').trim();
56
- }
57
-
58
- // Extract the scheme from a URL-ish value, or `null` if it has none.
59
- function extractScheme(value) {
60
- const schemeMatch = normalizeValue(value).match(/^([a-zA-Z][a-zA-Z0-9+.-]*):/);
61
- return schemeMatch ? schemeMatch[1].toLowerCase() + ':' : null;
62
- }
63
-
64
- // (tag, attr) pairs that may legitimately carry a `data:` URI — matches
65
- // DOMPurify's defaults so the SSR fallback doesn't reject inline images that
66
- // the browser path would allow.
67
- const DATA_URI_TAGS = [['img', 'src'], ['source', 'src'], ['source', 'srcset'], ['video', 'poster']];
68
-
69
- // SSR fallback: DOMPurify only operates when a DOM is available. When it
70
- // isn't, validate the scheme directly so server-rendered components don't
71
- // silently drop every href.
72
- function ssrSafeHref(value, tag, attr) {
73
- const normalized = normalizeValue(value);
74
- if (normalized === '') return true;
75
- const firstChar = normalized.charAt(0);
76
- if (firstChar === '#' || firstChar === '/' || firstChar === '?') return true;
77
- const scheme = extractScheme(normalized);
78
- if (!scheme) return true;
79
- if (SAFE_SCHEMES.includes(scheme)) return true;
80
- if (scheme === 'data:' && DATA_URI_TAGS.some(([t, a]) => t === tag && a === attr)) {
81
- return true;
82
- }
83
- return false;
84
- }
85
-
86
- /**
87
- * ---
88
- * category: utilities/utils
89
- * ---
90
- * Validates an attribute value and returns it only when the value is safe to
91
- * render. Delegates to `DOMPurify.isValidAttribute` in the browser; falls back
92
- * to a minimal scheme allow-list under SSR.
93
- *
94
- * @module safeHref
95
- *
96
- * @param href The value to validate
97
- * @param tag Element name the value will be applied to (e.g. `'a'`, `'img'`)
98
- * @param attr Attribute name (e.g. `'href'`, `'src'`)
99
- * @returns The original value if safe, `undefined` if blocked
100
- */
101
- function safeHref(href, tag, attr) {
102
- if (href == null || typeof href === 'undefined') return undefined;
103
- const value = String(href);
104
-
105
- // Pre-check our scheme allowlist before DOMPurify, since DOMPurify's default
106
- // ALLOWED_URI_REGEXP rejects schemes like `webcal:` that we treat as safe.
107
- const scheme = extractScheme(value);
108
- if (scheme && SAFE_SCHEMES.includes(scheme)) return href;
109
- const isSafe = purify.isSupported ? purify.isValidAttribute(tag, attr, value) : ssrSafeHref(value, tag, attr);
110
- if (!isSafe) {
111
- return undefined;
112
- }
113
- return href;
114
- }
115
- var _default = exports.default = safeHref;
@@ -1,59 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
- exports.safeLinkProps = safeLinkProps;
8
- var _safeHref = require("./safeHref.js");
9
- /*
10
- * The MIT License (MIT)
11
- *
12
- * Copyright (c) 2015 - present Instructure, Inc.
13
- *
14
- * Permission is hereby granted, free of charge, to any person obtaining a copy
15
- * of this software and associated documentation files (the "Software"), to deal
16
- * in the Software without restriction, including without limitation the rights
17
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
18
- * copies of the Software, and to permit persons to whom the Software is
19
- * furnished to do so, subject to the following conditions:
20
- *
21
- * The above copyright notice and this permission notice shall be included in all
22
- * copies or substantial portions of the Software.
23
- *
24
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
25
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
26
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
27
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
28
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
29
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30
- * SOFTWARE.
31
- */
32
-
33
- /**
34
- * ---
35
- * category: utilities/utils
36
- * ---
37
- * Centralizes the security-related normalization for link-rendering
38
- * components: validates `href`, and supplies a safe default `rel` when
39
- * `target="_blank"` is in use.
40
- *
41
- * @module safeLinkProps
42
- */
43
-
44
- function safeLinkProps(input) {
45
- const {
46
- target,
47
- rel,
48
- tag,
49
- attr
50
- } = input;
51
- const href = (0, _safeHref.safeHref)(input.href, tag, attr);
52
- const finalRel = target === '_blank' && rel == null ? 'noopener noreferrer' : rel;
53
- return {
54
- href,
55
- target,
56
- rel: finalRel
57
- };
58
- }
59
- var _default = exports.default = safeLinkProps;
@@ -1,85 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
- exports.shallowEqual = shallowEqual;
8
- /*
9
- * The MIT License (MIT)
10
- *
11
- * Copyright (c) 2015 - present Instructure, Inc.
12
- *
13
- * Permission is hereby granted, free of charge, to any person obtaining a copy
14
- * of this software and associated documentation files (the "Software"), to deal
15
- * in the Software without restriction, including without limitation the rights
16
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
17
- * copies of the Software, and to permit persons to whom the Software is
18
- * furnished to do so, subject to the following conditions:
19
- *
20
- * The above copyright notice and this permission notice shall be included in all
21
- * copies or substantial portions of the Software.
22
- *
23
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
24
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
26
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
28
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
29
- * SOFTWARE.
30
- */
31
-
32
- // https://github.com/facebook/fbjs/blob/master/packages/fbjs/src/core/shallowEqual.js
33
- const hasOwnProperty = Object.prototype.hasOwnProperty;
34
-
35
- /**
36
- * ---
37
- * category: utilities/Misc
38
- * ---
39
- * Performs equality by iterating through keys on an object and returning false
40
- * when any key has values which are not strictly equal between the arguments.
41
- *
42
- * @module shallowEqual
43
- *
44
- * @param {Object} objA
45
- * @param {Object} objB
46
- * @returns {Boolean} Returns true when the values of all keys are strictly equal
47
- */
48
- function shallowEqual(objA, objB) {
49
- if (is(objA, objB)) {
50
- return true;
51
- }
52
- if (typeof objA !== 'object' || objA === null || typeof objB !== 'object' || objB === null) {
53
- return false;
54
- }
55
- const keysA = Object.keys(objA);
56
- const keysB = Object.keys(objB);
57
- if (keysA.length !== keysB.length) {
58
- return false;
59
- }
60
-
61
- // Test for A's keys different from B.
62
- for (let i = 0; i < keysA.length; i++) {
63
- if (!hasOwnProperty.call(objB, keysA[i]) || !is(objA[keysA[i]], objB[keysA[i]])) {
64
- return false;
65
- }
66
- }
67
- return true;
68
- }
69
-
70
- /*
71
- * inlined Object.is polyfill to avoid requiring consumers ship their own
72
- * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is
73
- */
74
- function is(x, y) {
75
- // SameValue algorithm
76
- if (x === y) {
77
- // Steps 1-5, 7-10
78
- // Steps 6.b-6.e: +0 != -0
79
- return x !== 0 || y !== 0 || 1 / x === 1 / y;
80
- } else {
81
- // Step 6.a: NaN == NaN
82
- return x !== x && y !== y;
83
- }
84
- }
85
- var _default = exports.default = shallowEqual;
package/lib/within.js DELETED
@@ -1,48 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
- exports.within = within;
8
- /*
9
- * The MIT License (MIT)
10
- *
11
- * Copyright (c) 2015 - present Instructure, Inc.
12
- *
13
- * Permission is hereby granted, free of charge, to any person obtaining a copy
14
- * of this software and associated documentation files (the "Software"), to deal
15
- * in the Software without restriction, including without limitation the rights
16
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
17
- * copies of the Software, and to permit persons to whom the Software is
18
- * furnished to do so, subject to the following conditions:
19
- *
20
- * The above copyright notice and this permission notice shall be included in all
21
- * copies or substantial portions of the Software.
22
- *
23
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
24
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
26
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
28
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
29
- * SOFTWARE.
30
- */
31
-
32
- /**
33
- * ---
34
- * category: utilities/Misc
35
- * ---
36
- * Determines if one numerical value (a) is within a designated range (diff) of another (b)
37
- *
38
- * @module within
39
- *
40
- * @param {number} a
41
- * @param {number} b
42
- * @param {number} [diff=1]
43
- * @returns {Boolean} Returns true if a is within the diff range of b
44
- */
45
- function within(a, b, diff = 1) {
46
- return a + diff >= b && b >= a - diff;
47
- }
48
- var _default = exports.default = within;