@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/CHANGELOG.md CHANGED
@@ -3,6 +3,19 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## [11.7.9-pr-snapshot-1792147648392](https://github.com/instructure/instructure-ui/compare/v11.7.8...v11.7.9-pr-snapshot-1792147648392) (2026-10-16)
7
+
8
+ ### Build System
9
+
10
+ * **many:** replace babel with swc ([7e36c54](https://github.com/instructure/instructure-ui/commit/7e36c54d240b4fa483801c03ab18e7f860f561e2))
11
+
12
+ ### BREAKING CHANGES
13
+
14
+ * **many:** `@instructure/ui-babel-preset` and
15
+ `@instructure/browserslist-config-instui` are removed and will no longer be
16
+ published. Packages depend on `@swc/helpers` instead of `@babel/runtime`.
17
+
18
+
6
19
  ## [11.7.8](https://github.com/instructure/instructure-ui/compare/v11.7.7...v11.7.8) (2026-10-02)
7
20
 
8
21
  **Note:** Version bump only for package @instructure/ui-utils
package/es/camelize.js CHANGED
@@ -1,47 +1,5 @@
1
- /*
2
- * The MIT License (MIT)
3
- *
4
- * Copyright (c) 2015 - present Instructure, Inc.
5
- *
6
- * Permission is hereby granted, free of charge, to any person obtaining a copy
7
- * of this software and associated documentation files (the "Software"), to deal
8
- * in the Software without restriction, including without limitation the rights
9
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
- * copies of the Software, and to permit persons to whom the Software is
11
- * furnished to do so, subject to the following conditions:
12
- *
13
- * The above copyright notice and this permission notice shall be included in all
14
- * copies or substantial portions of the Software.
15
- *
16
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
- * SOFTWARE.
23
- */
24
-
25
- /**
26
- * ---
27
- * category: utilities/Misc
28
- * ---
29
- * Converts a hyphenated string to camel case
30
- *
31
- * Example inputs:
32
- * - 'foo-bar'
33
- * - 'baz-qux'
34
- *
35
- * Example outputs:
36
- * - 'fooBar'
37
- * - 'bazQux'
38
- *
39
- * @module camelize
40
- * @param {String} str
41
- * @returns {String} Returns camel cased string
42
- */
43
1
  function camelize(str) {
44
- return str.replace(/-([a-z])/g, g => g[1].toUpperCase());
2
+ return str.replace(/-([a-z])/g, (g)=>g[1].toUpperCase());
45
3
  }
46
4
  export default camelize;
47
- export { camelize };
5
+ export { camelize };
@@ -1,37 +1,5 @@
1
- /*
2
- * The MIT License (MIT)
3
- *
4
- * Copyright (c) 2015 - present Instructure, Inc.
5
- *
6
- * Permission is hereby granted, free of charge, to any person obtaining a copy
7
- * of this software and associated documentation files (the "Software"), to deal
8
- * in the Software without restriction, including without limitation the rights
9
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
- * copies of the Software, and to permit persons to whom the Software is
11
- * furnished to do so, subject to the following conditions:
12
- *
13
- * The above copyright notice and this permission notice shall be included in all
14
- * copies or substantial portions of the Software.
15
- *
16
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
- * SOFTWARE.
23
- */
24
-
25
- /**
26
- * ---
27
- * category: utilities/Misc
28
- * ---
29
- * Capitalize the first letter in a string
30
- * @module capitalizeFirstLetter
31
- * @param {String} str
32
- */
33
1
  function capitalizeFirstLetter(str) {
34
- return str ? str.charAt(0).toUpperCase() + str.slice(1) : str;
2
+ return str ? str.charAt(0).toUpperCase() + str.slice(1) : str;
35
3
  }
36
4
  export default capitalizeFirstLetter;
37
- export { capitalizeFirstLetter };
5
+ export { capitalizeFirstLetter };
package/es/cloneArray.js CHANGED
@@ -1,46 +1,13 @@
1
- /*
2
- * The MIT License (MIT)
3
- *
4
- * Copyright (c) 2015 - present Instructure, Inc.
5
- *
6
- * Permission is hereby granted, free of charge, to any person obtaining a copy
7
- * of this software and associated documentation files (the "Software"), to deal
8
- * in the Software without restriction, including without limitation the rights
9
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
- * copies of the Software, and to permit persons to whom the Software is
11
- * furnished to do so, subject to the following conditions:
12
- *
13
- * The above copyright notice and this permission notice shall be included in all
14
- * copies or substantial portions of the Software.
15
- *
16
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
- * SOFTWARE.
23
- */
24
-
25
- /**
26
- * ---
27
- * category: utilities/Misc
28
- * ---
29
- * Deep clones an array with sub arrays
30
- * @module cloneArray
31
- * @param {Array} arr
32
- * @returns {Array} Returns a copy of the array
33
- */
34
1
  function cloneArray(arr) {
35
- if (Array.isArray(arr)) {
36
- const copy = arr.slice(0);
37
- for (let i = 0; i < copy.length; i++) {
38
- copy[i] = cloneArray(copy[i]);
2
+ if (Array.isArray(arr)) {
3
+ const copy = arr.slice(0);
4
+ for(let i = 0; i < copy.length; i++){
5
+ copy[i] = cloneArray(copy[i]);
6
+ }
7
+ return copy;
8
+ } else {
9
+ return arr;
39
10
  }
40
- return copy;
41
- } else {
42
- return arr;
43
- }
44
11
  }
45
12
  export default cloneArray;
46
- export { cloneArray };
13
+ export { cloneArray };
@@ -1,35 +1,5 @@
1
- /*
2
- * The MIT License (MIT)
3
- *
4
- * Copyright (c) 2015 - present Instructure, Inc.
5
- *
6
- * Permission is hereby granted, free of charge, to any person obtaining a copy
7
- * of this software and associated documentation files (the "Software"), to deal
8
- * in the Software without restriction, including without limitation the rights
9
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
- * copies of the Software, and to permit persons to whom the Software is
11
- * furnished to do so, subject to the following conditions:
12
- *
13
- * The above copyright notice and this permission notice shall be included in all
14
- * copies or substantial portions of the Software.
15
- *
16
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
- * SOFTWARE.
23
- */
24
-
25
- /**
26
- * Combines a component's default data-cid with a data-cid from props
27
- * @param dataCid - The default data-cid for the component
28
- * @param props - The component props object that may contain a data-cid
29
- * @returns A combined data-cid string, trimmed of extra whitespace
30
- */
31
- const combineDataCid = (dataCid, props) => {
32
- const dataCidFromProps = props['data-cid'] || '';
33
- return `${dataCid} ${dataCidFromProps}`.trim();
1
+ const combineDataCid = (dataCid, props)=>{
2
+ const dataCidFromProps = props['data-cid'] || '';
3
+ return `${dataCid} ${dataCidFromProps}`.trim();
34
4
  };
35
- export { combineDataCid };
5
+ export { combineDataCid };
package/es/convertCase.js CHANGED
@@ -1,27 +1,3 @@
1
- /*
2
- * The MIT License (MIT)
3
- *
4
- * Copyright (c) 2015 - present Instructure, Inc.
5
- *
6
- * Permission is hereby granted, free of charge, to any person obtaining a copy
7
- * of this software and associated documentation files (the "Software"), to deal
8
- * in the Software without restriction, including without limitation the rights
9
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
- * copies of the Software, and to permit persons to whom the Software is
11
- * furnished to do so, subject to the following conditions:
12
- *
13
- * The above copyright notice and this permission notice shall be included in all
14
- * copies or substantial portions of the Software.
15
- *
16
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
- * SOFTWARE.
23
- */
24
-
25
1
  import { camelize } from './camelize.js';
26
2
  import { pascalize } from './pascalize.js';
27
- export { camelize, pascalize };
3
+ export { camelize, pascalize };
@@ -1,80 +1,31 @@
1
- /*
2
- * The MIT License (MIT)
3
- *
4
- * Copyright (c) 2015 - present Instructure, Inc.
5
- *
6
- * Permission is hereby granted, free of charge, to any person obtaining a copy
7
- * of this software and associated documentation files (the "Software"), to deal
8
- * in the Software without restriction, including without limitation the rights
9
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
- * copies of the Software, and to permit persons to whom the Software is
11
- * furnished to do so, subject to the following conditions:
12
- *
13
- * The above copyright notice and this permission notice shall be included in all
14
- * copies or substantial portions of the Software.
15
- *
16
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
- * SOFTWARE.
23
- */
24
-
25
- /**
26
- * ---
27
- * category: utilities/react
28
- * ---
29
- * Safe chained functions
30
- *
31
- * Will only create a new function if needed,
32
- * otherwise will pass back existing functions or null.
33
- *
34
- * Forked from: https://github.com/react-bootstrap/react-overlays/blob/master/src/utils/createChainedFunction.js
35
- * @module createChainedFunction
36
- * @param funcs Functions to chain. It can be null/undefined
37
- * @returns the functions chained after each other
38
- */
39
-
40
1
  function createChainedFunction(...funcs) {
41
- return funcs.filter((f, i) => {
42
- if (f == null) {
43
- return false;
44
- }
45
- // Only allow the first of identical functions
46
- const indexes = getAllIndexes(funcs, f);
47
- return indexes.length === 1 || i === indexes[0];
48
- }).reduce((acc, f) => {
49
- if (typeof f !== 'function') {
50
- throw new Error('Invalid Argument Type, must only provide functions, undefined, or null.');
51
- }
52
- if (acc === null) {
53
- return f;
54
- }
55
- return function chainedFunction(...args) {
56
- acc.apply(this, args);
57
- f.apply(this, args);
58
- };
59
- // TODO I think it can return null too
60
- }, null);
2
+ return funcs.filter((f, i)=>{
3
+ if (f == null) {
4
+ return false;
5
+ }
6
+ const indexes = getAllIndexes(funcs, f);
7
+ return indexes.length === 1 || i === indexes[0];
8
+ }).reduce((acc, f)=>{
9
+ if (typeof f !== 'function') {
10
+ throw new Error('Invalid Argument Type, must only provide functions, undefined, or null.');
11
+ }
12
+ if (acc === null) {
13
+ return f;
14
+ }
15
+ return function chainedFunction(...args) {
16
+ acc.apply(this, args);
17
+ f.apply(this, args);
18
+ };
19
+ }, null);
61
20
  }
62
-
63
- /**
64
- * Find all indexes for a value in an Array
65
- *
66
- * @param {array} arr The Array to search for val
67
- * @param {*} val The value to find indexes for
68
- * @return {array} All the indexes of the Array matching val
69
- */
70
21
  function getAllIndexes(arr, val) {
71
- const indexes = [];
72
- arr.forEach((e, i) => {
73
- if (e === val) {
74
- indexes.push(i);
75
- }
76
- });
77
- return indexes;
22
+ const indexes = [];
23
+ arr.forEach((e, i)=>{
24
+ if (e === val) {
25
+ indexes.push(i);
26
+ }
27
+ });
28
+ return indexes;
78
29
  }
79
30
  export default createChainedFunction;
80
- export { createChainedFunction };
31
+ export { createChainedFunction };
package/es/deepEqual.js CHANGED
@@ -1,27 +1,3 @@
1
- /*
2
- * The MIT License (MIT)
3
- *
4
- * Copyright (c) 2015 - present Instructure, Inc.
5
- *
6
- * Permission is hereby granted, free of charge, to any person obtaining a copy
7
- * of this software and associated documentation files (the "Software"), to deal
8
- * in the Software without restriction, including without limitation the rights
9
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
- * copies of the Software, and to permit persons to whom the Software is
11
- * furnished to do so, subject to the following conditions:
12
- *
13
- * The above copyright notice and this permission notice shall be included in all
14
- * copies or substantial portions of the Software.
15
- *
16
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
- * SOFTWARE.
23
- */
24
-
25
1
  import deepEqual from 'fast-deep-equal';
26
2
  export default deepEqual;
27
- export { deepEqual };
3
+ export { deepEqual };
package/es/generateId.js CHANGED
@@ -1,52 +1,10 @@
1
- /*
2
- * The MIT License (MIT)
3
- *
4
- * Copyright (c) 2015 - present Instructure, Inc.
5
- *
6
- * Permission is hereby granted, free of charge, to any person obtaining a copy
7
- * of this software and associated documentation files (the "Software"), to deal
8
- * in the Software without restriction, including without limitation the rights
9
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
- * copies of the Software, and to permit persons to whom the Software is
11
- * furnished to do so, subject to the following conditions:
12
- *
13
- * The above copyright notice and this permission notice shall be included in all
14
- * copies or substantial portions of the Software.
15
- *
16
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
- * SOFTWARE.
23
- */
24
-
25
- /**
26
- * Generates unique css safe ids for elements.
27
- *
28
- * @deprecated Use `useDeterministicId` (function components) or the
29
- * `withDeterministicId` decorator (class components) from
30
- * `@instructure/ui-react-utils` instead. Both are backed by React's `useId`, so
31
- * they produce the same id on the server and the client. This counter-based
32
- * helper depends on render order: the count advances once per render pass, so a
33
- * server render and the subsequent client render disagree, and the id changes on
34
- * every re-render. It is no longer used anywhere in InstUI and will be removed
35
- * in the next major version.
36
- *
37
- * @param instanceName - the name of the element/instance to keep track of
38
- * @param map - a Map<string, counter>, which counts how many times the given element/instance was rendered
39
- * @returns a string in a format `instanceName_intanceRenderedCount`: `Alert_4`
40
- */
41
- const generateId = (instanceName, map) => {
42
- if (!map.has(instanceName)) {
43
- map.set(instanceName, 0);
44
- } else {
45
- map.set(instanceName, map.get(instanceName) + 1);
46
- }
47
- // Do not rename '___' to '_' it will cause name clash with InstUI v10.14.0
48
- // or older
49
- return `${instanceName}___${map.get(instanceName)}`;
1
+ const generateId = (instanceName, map)=>{
2
+ if (!map.has(instanceName)) {
3
+ map.set(instanceName, 0);
4
+ } else {
5
+ map.set(instanceName, map.get(instanceName) + 1);
6
+ }
7
+ return `${instanceName}___${map.get(instanceName)}`;
50
8
  };
51
9
  export default generateId;
52
- export { generateId };
10
+ export { generateId };
package/es/getBrowser.js CHANGED
@@ -1,72 +1,41 @@
1
- /*
2
- * The MIT License (MIT)
3
- *
4
- * Copyright (c) 2015 - present Instructure, Inc.
5
- *
6
- * Permission is hereby granted, free of charge, to any person obtaining a copy
7
- * of this software and associated documentation files (the "Software"), to deal
8
- * in the Software without restriction, including without limitation the rights
9
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
- * copies of the Software, and to permit persons to whom the Software is
11
- * furnished to do so, subject to the following conditions:
12
- *
13
- * The above copyright notice and this permission notice shall be included in all
14
- * copies or substantial portions of the Software.
15
- *
16
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
- * SOFTWARE.
23
- */
24
-
25
1
  import UAParser from 'ua-parser-js';
26
-
27
- /**
28
- * ---
29
- * category: utilities/Misc
30
- * ---
31
- * A utility module using the 1.x [ua-parser-js](https://www.npmjs.com/package/ua-parser-js)
32
- * browser detection library.
33
- *
34
- * @module getBrowser
35
- */
36
- const getBrowser = () => {
37
- const parser = new UAParser();
38
- const {
39
- browser
40
- } = parser.getResult();
41
- return browser;
42
- };
43
- const isSafari = () => {
44
- return getBrowser().name === 'Safari';
45
- };
46
- const isEdge = () => {
47
- return getBrowser().name === 'Edge';
48
- };
49
- const isIE = () => {
50
- return getBrowser().name === 'IE';
51
- };
52
- const isChromium = () => {
53
- const chromiumBasedBrowsers = ['Chrome', 'Chromium', 'Opera', 'Edge'];
54
- return chromiumBasedBrowsers.some(browser => {
55
- return getBrowser().name?.includes(browser);
56
- });
57
- };
58
- const isFirefox = () => {
59
- return getBrowser().name === 'Firefox';
60
- };
61
- const isAndroidOrIOS = () => {
62
- const parser = new UAParser();
63
- const result = parser.getResult();
64
- const device = parser.getDevice();
65
- return result.os.name === 'Android' || device.model === 'iPhone' || device.model === 'iPad' ? true : false;
66
- };
67
- const isMac = () => {
68
- const parser = new UAParser();
69
- const result = parser.getResult();
70
- return result.os.name === 'Mac OS';
71
- };
72
- export { getBrowser, isSafari, isEdge, isIE, isFirefox, isChromium, isAndroidOrIOS, isMac };
2
+ const getBrowser = ()=>{
3
+ const parser = new UAParser();
4
+ const { browser } = parser.getResult();
5
+ return browser;
6
+ };
7
+ const isSafari = ()=>{
8
+ return getBrowser().name === 'Safari';
9
+ };
10
+ const isEdge = ()=>{
11
+ return getBrowser().name === 'Edge';
12
+ };
13
+ const isIE = ()=>{
14
+ return getBrowser().name === 'IE';
15
+ };
16
+ const isChromium = ()=>{
17
+ const chromiumBasedBrowsers = [
18
+ 'Chrome',
19
+ 'Chromium',
20
+ 'Opera',
21
+ 'Edge'
22
+ ];
23
+ return chromiumBasedBrowsers.some((browser)=>{
24
+ return getBrowser().name?.includes(browser);
25
+ });
26
+ };
27
+ const isFirefox = ()=>{
28
+ return getBrowser().name === 'Firefox';
29
+ };
30
+ const isAndroidOrIOS = ()=>{
31
+ const parser = new UAParser();
32
+ const result = parser.getResult();
33
+ const device = parser.getDevice();
34
+ return result.os.name === 'Android' || device.model === 'iPhone' || device.model === 'iPad' ? true : false;
35
+ };
36
+ const isMac = ()=>{
37
+ const parser = new UAParser();
38
+ const result = parser.getResult();
39
+ return result.os.name === 'Mac OS';
40
+ };
41
+ export { getBrowser, isSafari, isEdge, isIE, isFirefox, isChromium, isAndroidOrIOS, isMac };
package/es/hash.js CHANGED
@@ -1,75 +1,50 @@
1
- /*
2
- * The MIT License (MIT)
3
- *
4
- * Copyright (c) 2015 - present Instructure, Inc.
5
- *
6
- * Permission is hereby granted, free of charge, to any person obtaining a copy
7
- * of this software and associated documentation files (the "Software"), to deal
8
- * in the Software without restriction, including without limitation the rights
9
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
- * copies of the Software, and to permit persons to whom the Software is
11
- * furnished to do so, subject to the following conditions:
12
- *
13
- * The above copyright notice and this permission notice shall be included in all
14
- * copies or substantial portions of the Software.
15
- *
16
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
- * SOFTWARE.
23
- */
24
-
25
1
  import stringify from 'json-stable-stringify';
26
2
  function toBase64(input) {
27
- const tab = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
28
- let output = '';
29
- const length = input.length;
30
- let triplet;
31
- const b64pad = '=';
32
- for (let i = 0; i < length; i += 3) {
33
- triplet = input.charCodeAt(i) << 16 | (i + 1 < length ? input.charCodeAt(i + 1) << 8 : 0) | (i + 2 < length ? input.charCodeAt(i + 2) : 0);
34
- for (let j = 0; j < 4; j += 1) {
35
- if (i * 8 + j * 6 > input.length * 8) {
36
- output += b64pad;
37
- } else {
38
- output += tab.charAt(triplet >>> 6 * (3 - j) & 0x3f);
39
- }
3
+ const tab = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
4
+ let output = '';
5
+ const length = input.length;
6
+ let triplet;
7
+ const b64pad = '=';
8
+ for(let i = 0; i < length; i += 3){
9
+ triplet = input.charCodeAt(i) << 16 | (i + 1 < length ? input.charCodeAt(i + 1) << 8 : 0) | (i + 2 < length ? input.charCodeAt(i + 2) : 0);
10
+ for(let j = 0; j < 4; j += 1){
11
+ if (i * 8 + j * 6 > input.length * 8) {
12
+ output += b64pad;
13
+ } else {
14
+ output += tab.charAt(triplet >>> 6 * (3 - j) & 0x3f);
15
+ }
16
+ }
40
17
  }
41
- }
42
- return output;
18
+ return output;
43
19
  }
44
20
  function executeHash(input) {
45
- let hash = 0;
46
- if (input.length === 0) return '0';
47
- for (let i = 0; i < input.length; i++) {
48
- const c = input.charCodeAt(i);
49
- hash = (hash << 5) - hash + c;
50
- hash |= 0; // Convert to 32bit integer
51
- }
52
- return toBase64(String(hash));
21
+ let hash = 0;
22
+ if (input.length === 0) return '0';
23
+ for(let i = 0; i < input.length; i++){
24
+ const c = input.charCodeAt(i);
25
+ hash = (hash << 5) - hash + c;
26
+ hash |= 0;
27
+ }
28
+ return toBase64(String(hash));
53
29
  }
54
30
  function hash(value, maxLength = 0) {
55
- if (typeof value === 'undefined') {
56
- throw new Error('Cannot hash a value which is undefined');
57
- }
58
- let hashedValue = '';
59
- let valueToHash = value;
60
- if (typeof value !== 'string') {
61
- if (typeof value === 'object') {
62
- // Ensure we are robust to things like objects that are identical, but with keys in diff orders
63
- valueToHash = stringify(value);
64
- } else {
65
- valueToHash = value.toString();
31
+ if (typeof value === 'undefined') {
32
+ throw new Error('Cannot hash a value which is undefined');
33
+ }
34
+ let hashedValue = '';
35
+ let valueToHash = value;
36
+ if (typeof value !== 'string') {
37
+ if (typeof value === 'object') {
38
+ valueToHash = stringify(value);
39
+ } else {
40
+ valueToHash = value.toString();
41
+ }
42
+ }
43
+ hashedValue = executeHash(valueToHash);
44
+ if (maxLength) {
45
+ hashedValue = hashedValue.slice(0, maxLength);
66
46
  }
67
- }
68
- hashedValue = executeHash(valueToHash);
69
- if (maxLength) {
70
- hashedValue = hashedValue.slice(0, maxLength);
71
- }
72
- return hashedValue;
47
+ return hashedValue;
73
48
  }
74
49
  export default hash;
75
- export { hash };
50
+ export { hash };