@straylightagency/utils 1.1.4 → 1.1.6

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 (55) hide show
  1. package/package.json +36 -36
  2. package/src/array/index.js +4 -3
  3. package/src/array/initial.js +10 -10
  4. package/src/array/last.js +11 -11
  5. package/src/array/remove.js +16 -16
  6. package/src/array/replace.js +17 -0
  7. package/src/date/clone.js +9 -9
  8. package/src/date/getWeekNumber.js +17 -17
  9. package/src/date/index.js +2 -2
  10. package/src/date/reviver.js +12 -12
  11. package/src/dom/addEventListeners.js +21 -21
  12. package/src/dom/closestElement.js +31 -31
  13. package/src/dom/delegate.js +19 -19
  14. package/src/dom/getElementSizing.js +77 -77
  15. package/src/dom/getFieldsValues.js +17 -17
  16. package/src/dom/index.js +10 -10
  17. package/src/dom/onEachElements.js +34 -34
  18. package/src/dom/stringToHtml.js +18 -18
  19. package/src/dom/unlessElementExists.js +34 -34
  20. package/src/dom/whenReady.js +9 -9
  21. package/src/dom/whenResize.js +31 -26
  22. package/src/dom/whenScroll.js +31 -26
  23. package/src/index.js +52 -50
  24. package/src/misc/attempt.js +20 -20
  25. package/src/misc/base64.js +47 -47
  26. package/src/misc/clipboard.js +24 -24
  27. package/src/misc/debounce.js +25 -25
  28. package/src/misc/index.js +23 -22
  29. package/src/misc/is.js +31 -31
  30. package/src/misc/match.js +33 -0
  31. package/src/misc/milliseconds.js +8 -8
  32. package/src/misc/nextTick.js +12 -12
  33. package/src/misc/replacer.js +9 -9
  34. package/src/misc/restoreBooleanAfter.js +16 -16
  35. package/src/misc/retry.js +42 -42
  36. package/src/misc/reviver.js +12 -12
  37. package/src/misc/seconds.js +10 -10
  38. package/src/misc/throttle.js +28 -28
  39. package/src/number/format.js +10 -10
  40. package/src/number/index.js +2 -2
  41. package/src/number/random.js +8 -8
  42. package/src/object/filter.js +10 -10
  43. package/src/object/get.js +13 -13
  44. package/src/object/has.js +12 -12
  45. package/src/object/index.js +7 -7
  46. package/src/object/map.js +12 -12
  47. package/src/object/only.js +16 -16
  48. package/src/object/serialize.js +13 -13
  49. package/src/object/set.js +29 -29
  50. package/src/object/unserialize.js +29 -29
  51. package/src/string/capitalFirst.js +14 -14
  52. package/src/string/capitalWords.js +20 -20
  53. package/src/string/index.js +3 -3
  54. package/src/string/interpolate.js +15 -15
  55. package/src/string/slugify.js +28 -28
@@ -1,14 +1,14 @@
1
- import replacer from "../misc/replacer.js";
2
-
3
- /**
4
- * Serialize an object into a string, transforms functions into string.
5
- *
6
- * @example serialize({foo: {bar: {doe: "Bob", {smith: "John"}}}})
7
- * => {"foo":{"bar":{"doe":"Bob","smith":"John"}}}
8
- *
9
- * @param {{}} object
10
- * @returns {String}
11
- */
12
- export default function serialize(object) {
13
- return JSON.stringify( object, replacer );
1
+ import replacer from "../misc/replacer.js";
2
+
3
+ /**
4
+ * Serialize an object into a string, transforms functions into string.
5
+ *
6
+ * @example serialize({foo: {bar: {doe: "Bob", {smith: "John"}}}})
7
+ * => {"foo":{"bar":{"doe":"Bob","smith":"John"}}}
8
+ *
9
+ * @param {{}} object
10
+ * @returns {String}
11
+ */
12
+ export default function serialize(object) {
13
+ return JSON.stringify( object, replacer );
14
14
  }
package/src/object/set.js CHANGED
@@ -1,29 +1,29 @@
1
- /**
2
- * Set a value using a dot-notated key string.
3
- *
4
- * @example set({foo: {bar: {doe: "Bob"}}}, "foo.bar.smith", "John");
5
- * => {foo: {bar: {doe: "Bob", {smith: "John"}}}}
6
- *
7
- * @param {{}} object
8
- * @param {string} keys
9
- * @param {*} value
10
- * @returns {*}
11
- */
12
- export default function (object, keys, value) {
13
- const arrKeys = keys.split('.');
14
- let source = object;
15
-
16
- arrKeys.map( ( key, i ) => {
17
- if ( i === arrKeys.length - 1 ) {
18
- source[ key ] = value;
19
- }
20
-
21
- if ( source[ key ] === undefined ) {
22
- source[ key ] = {};
23
- }
24
-
25
- source = source[ key ];
26
- } );
27
-
28
- return object;
29
- }
1
+ /**
2
+ * Set a value using a dot-notated key string.
3
+ *
4
+ * @example set({foo: {bar: {doe: "Bob"}}}, "foo.bar.smith", "John");
5
+ * => {foo: {bar: {doe: "Bob", {smith: "John"}}}}
6
+ *
7
+ * @param {{}} object
8
+ * @param {string} keys
9
+ * @param {*} value
10
+ * @returns {*}
11
+ */
12
+ export default function (object, keys, value) {
13
+ const arrKeys = keys.split('.');
14
+ let source = object;
15
+
16
+ arrKeys.map( ( key, i ) => {
17
+ if ( i === arrKeys.length - 1 ) {
18
+ source[ key ] = value;
19
+ }
20
+
21
+ if ( source[ key ] === undefined ) {
22
+ source[ key ] = {};
23
+ }
24
+
25
+ source = source[ key ];
26
+ } );
27
+
28
+ return object;
29
+ }
@@ -1,30 +1,30 @@
1
- import dateReviver from '../date/reviver.js'
2
- import functionReviver from '../misc/reviver.js'
3
-
4
- /**
5
- * Serialize an object into a string, handling functions and Date objects.
6
- *
7
- * @example serialize("{"foo":{"bar":{"doe":"Bob","smith":"John"}}}")
8
- * => {"foo":{"bar":{"doe":"Bob","smith":"John"}}}
9
- *
10
- * @param {string} object
11
- * @returns {{}}
12
- */
13
- export default function unserialize(object) {
14
- return JSON.parse( object, (key, value) => {
15
- const revivers = [
16
- dateReviver,
17
- functionReviver
18
- ];
19
-
20
- let revivedValue = undefined;
21
-
22
- for ( const reviver of revivers ) {
23
- if ( ( revivedValue = reviver( value ) ) !== undefined ) {
24
- return revivedValue;
25
- }
26
- }
27
-
28
- return value;
29
- } );
1
+ import dateReviver from '../date/reviver.js'
2
+ import functionReviver from '../misc/reviver.js'
3
+
4
+ /**
5
+ * Serialize an object into a string, handling functions and Date objects.
6
+ *
7
+ * @example serialize("{"foo":{"bar":{"doe":"Bob","smith":"John"}}}")
8
+ * => {"foo":{"bar":{"doe":"Bob","smith":"John"}}}
9
+ *
10
+ * @param {string} object
11
+ * @returns {{}}
12
+ */
13
+ export default function unserialize(object) {
14
+ return JSON.parse( object, (key, value) => {
15
+ const revivers = [
16
+ dateReviver,
17
+ functionReviver
18
+ ];
19
+
20
+ let revivedValue = undefined;
21
+
22
+ for ( const reviver of revivers ) {
23
+ if ( ( revivedValue = reviver( value ) ) !== undefined ) {
24
+ return revivedValue;
25
+ }
26
+ }
27
+
28
+ return value;
29
+ } );
30
30
  }
@@ -1,14 +1,14 @@
1
- /**
2
- * Capitalize the first letter of a string.
3
- *
4
- * @example capitalFirst("lazy dog")
5
- * => "Lazy dog"
6
- *
7
- * @param {string} string
8
- * @returns {string}
9
- */
10
- export default function capitalFirst(string) {
11
- string = string.toString();
12
-
13
- return string.charAt( 0 ).toUpperCase() + string.slice( 1 );
14
- }
1
+ /**
2
+ * Capitalize the first letter of a string.
3
+ *
4
+ * @example capitalFirst("lazy dog")
5
+ * => "Lazy dog"
6
+ *
7
+ * @param {string} string
8
+ * @returns {string}
9
+ */
10
+ export default function capitalFirst(string) {
11
+ string = string.toString();
12
+
13
+ return string.charAt( 0 ).toUpperCase() + string.slice( 1 );
14
+ }
@@ -1,20 +1,20 @@
1
- import capitalFirst from "./capitalFirst.js";
2
-
3
- /**
4
- * Capitalize every word of a string.
5
- *
6
- * @example capitalWords("The quick brown fox jumps over the lazy dog")
7
- * => "The Quick Brown Fox Jumps Over The Lazy Dog"
8
- *
9
- * @param {string} string
10
- * @returns {string}
11
- */
12
- export default function capitalWords(string) {
13
- const str_arr = string.split(' ');
14
-
15
- for( let i = 0; i < str_arr.length; i++ ) {
16
- str_arr[ i ] = capitalFirst( str_arr[ i ] );
17
- }
18
-
19
- return str_arr.join(' ');
20
- }
1
+ import capitalFirst from "./capitalFirst.js";
2
+
3
+ /**
4
+ * Capitalize every word of a string.
5
+ *
6
+ * @example capitalWords("The quick brown fox jumps over the lazy dog")
7
+ * => "The Quick Brown Fox Jumps Over The Lazy Dog"
8
+ *
9
+ * @param {string} string
10
+ * @returns {string}
11
+ */
12
+ export default function capitalWords(string) {
13
+ const str_arr = string.split(' ');
14
+
15
+ for( let i = 0; i < str_arr.length; i++ ) {
16
+ str_arr[ i ] = capitalFirst( str_arr[ i ] );
17
+ }
18
+
19
+ return str_arr.join(' ');
20
+ }
@@ -1,4 +1,4 @@
1
- export { default as capitalFirst } from "./capitalFirst.js";
2
- export { default as capitalWords } from "./capitalWords.js";
3
- export { default as slugify } from "./slugify.js";
1
+ export { default as capitalFirst } from "./capitalFirst.js";
2
+ export { default as capitalWords } from "./capitalWords.js";
3
+ export { default as slugify } from "./slugify.js";
4
4
  export { default as interpolate } from "./interpolate.js";
@@ -1,15 +1,15 @@
1
- /**
2
- * Interpolate a string with data.
3
- *
4
- * @example interpolate("The quick :color fox jumps over :who", {color: "brown", who: "the lazy dog"});
5
- * => "The quick brown fox jumps over the lazy dog"
6
- *
7
- * @param {string} string
8
- * @param {object} replace
9
- * @returns {string}
10
- */
11
- export default function interpolate(string, replace = {}) {
12
- return string.replace( /:(\w+)/g, ( match, p1 ) =>
13
- replace[ p1 ] !== undefined ? replace[ p1 ] : ':' + p1
14
- );
15
- }
1
+ /**
2
+ * Interpolate a string with data.
3
+ *
4
+ * @example interpolate("The quick :color fox jumps over :who", {color: "brown", who: "the lazy dog"});
5
+ * => "The quick brown fox jumps over the lazy dog"
6
+ *
7
+ * @param {string} string
8
+ * @param {object} replace
9
+ * @returns {string}
10
+ */
11
+ export default function interpolate(string, replace = {}) {
12
+ return string.replace( /:(\w+)/g, ( match, p1 ) =>
13
+ replace[ p1 ] !== undefined ? replace[ p1 ] : ':' + p1
14
+ );
15
+ }
@@ -1,28 +1,28 @@
1
- /**
2
- * Slugify a string. Second parameter allows you to choose the separator.
3
- *
4
- * @example slugify("The quick brown fox jumps over the lazy dog")
5
- * => "the-quick-brown-fox-jumps-over-the-lazy-dog"
6
- *
7
- * @param {string} string
8
- * @param {string} separator
9
- * @returns {string}
10
- */
11
- export default function slugify(string, separator = '-') {
12
- string = string.trim().toLowerCase();
13
-
14
- /** replaces specials characters with hyphens */
15
- const from = "ãàáäâẽèéëêìíïîõòóöôøùúüûñç·/_,:;.";
16
- const to = "aaaaaeeeeeiiiioooooouuuunc-------";
17
-
18
- for ( let i = 0, l = from.length; i < l; i++ ) {
19
- string = string.replace( from.charAt( i ), to.charAt( i ) );
20
- }
21
-
22
- string = string.normalize('NFD').replace(/[\u0300-\u036f]/g, '');
23
-
24
- return string
25
- .replace(/[^a-z0-9 -]/g, '') /** remove any non-alphanumeric characters */
26
- .replace(/\s+/g, separator ) /** replace spaces with hyphens */
27
- .replace(/-+/g, separator ); /** remove consecutive hyphens */
28
- }
1
+ /**
2
+ * Slugify a string. Second parameter allows you to choose the separator.
3
+ *
4
+ * @example slugify("The quick brown fox jumps over the lazy dog")
5
+ * => "the-quick-brown-fox-jumps-over-the-lazy-dog"
6
+ *
7
+ * @param {string} string
8
+ * @param {string} separator
9
+ * @returns {string}
10
+ */
11
+ export default function slugify(string, separator = '-') {
12
+ string = string.trim().toLowerCase();
13
+
14
+ /** replaces specials characters with hyphens */
15
+ const from = "ãàáäâẽèéëêìíïîõòóöôøùúüûñç·/_,:;.";
16
+ const to = "aaaaaeeeeeiiiioooooouuuunc-------";
17
+
18
+ for ( let i = 0, l = from.length; i < l; i++ ) {
19
+ string = string.replace( from.charAt( i ), to.charAt( i ) );
20
+ }
21
+
22
+ string = string.normalize('NFD').replace(/[\u0300-\u036f]/g, '');
23
+
24
+ return string
25
+ .replace(/[^a-z0-9 -]/g, '') /** remove any non-alphanumeric characters */
26
+ .replace(/\s+/g, separator ) /** replace spaces with hyphens */
27
+ .replace(/-+/g, separator ); /** remove consecutive hyphens */
28
+ }