@straylightagency/utils 1.1.6 → 1.1.8

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 +3 -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 +16 -16
  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 +29 -31
  22. package/src/dom/whenScroll.js +29 -31
  23. package/src/index.js +52 -52
  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 -23
  29. package/src/misc/is.js +31 -31
  30. package/src/misc/match.js +32 -32
  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
package/package.json CHANGED
@@ -1,36 +1,36 @@
1
- {
2
- "name": "@straylightagency/utils",
3
- "version": "1.1.6",
4
- "description": "Some JavaScript utilities functions",
5
- "type": "module",
6
- "main": "src/index.js",
7
- "exports": {
8
- ".": "./src/index.js",
9
- "./array": "./src/array/index.js",
10
- "./date": "./src/date/index.js",
11
- "./dom": "./src/dom/index.js",
12
- "./misc": "./src/misc/index.js",
13
- "./object": "./src/object/index.js",
14
- "./string": "./src/string/index.js"
15
- },
16
- "files": [
17
- "src"
18
- ],
19
- "scripts": {
20
- "test": "echo \"Error: no test specified\" && exit 1"
21
- },
22
- "private": false,
23
- "dependencies": {},
24
- "devDependencies": {},
25
- "keywords": [],
26
- "author": "Anthony Pauwels (anthony@straylightagency.be)",
27
- "license": "MIT",
28
- "repository": {
29
- "type": "git",
30
- "url": "git+https://github.com/straylightagency/js-utils.git"
31
- },
32
- "bugs": {
33
- "url": "https://github.com/straylightagency/js-utils/issues"
34
- },
35
- "homepage": "https://github.com/straylightagency/js-utils#readme"
36
- }
1
+ {
2
+ "name": "@straylightagency/utils",
3
+ "version": "1.1.8",
4
+ "description": "Some JavaScript utilities functions",
5
+ "type": "module",
6
+ "main": "src/index.js",
7
+ "exports": {
8
+ ".": "./src/index.js",
9
+ "./array": "./src/array/index.js",
10
+ "./date": "./src/date/index.js",
11
+ "./dom": "./src/dom/index.js",
12
+ "./misc": "./src/misc/index.js",
13
+ "./object": "./src/object/index.js",
14
+ "./string": "./src/string/index.js"
15
+ },
16
+ "files": [
17
+ "src"
18
+ ],
19
+ "scripts": {
20
+ "test": "echo \"Error: no test specified\" && exit 1"
21
+ },
22
+ "private": false,
23
+ "dependencies": {},
24
+ "devDependencies": {},
25
+ "keywords": [],
26
+ "author": "Anthony Pauwels (anthony@straylightagency.be)",
27
+ "license": "MIT",
28
+ "repository": {
29
+ "type": "git",
30
+ "url": "git+https://github.com/straylightagency/js-utils.git"
31
+ },
32
+ "bugs": {
33
+ "url": "https://github.com/straylightagency/js-utils/issues"
34
+ },
35
+ "homepage": "https://github.com/straylightagency/js-utils#readme"
36
+ }
@@ -1,4 +1,4 @@
1
- export { default as last } from "./last.js";
2
- export { default as initial } from "./initial.js";
3
- export { default as remove } from "./remove.js";
1
+ export { default as last } from "./last.js";
2
+ export { default as initial } from "./initial.js";
3
+ export { default as remove } from "./remove.js";
4
4
  export { default as replace } from "./replace.js";
@@ -1,10 +1,10 @@
1
- /**
2
- * Return the array without the last element.
3
- *
4
- * @param array {[]}
5
- * @returns {array}
6
- */
7
- export default function initial(array) {
8
- const length = array == null ? 0 : array.length
9
- return length ? array.slice( 0, -1 ) : []
10
- }
1
+ /**
2
+ * Return the array without the last element.
3
+ *
4
+ * @param array {[]}
5
+ * @returns {array}
6
+ */
7
+ export default function initial(array) {
8
+ const length = array == null ? 0 : array.length
9
+ return length ? array.slice( 0, -1 ) : []
10
+ }
package/src/array/last.js CHANGED
@@ -1,11 +1,11 @@
1
- /**
2
- * Return the last element of an array.
3
- *
4
- * @param {[]} array
5
- * @returns {*|undefined}
6
- */
7
- export default function last(array) {
8
- const length = array == null ? 0 : array.length
9
-
10
- return length ? array[ length - 1 ] : undefined
11
- }
1
+ /**
2
+ * Return the last element of an array.
3
+ *
4
+ * @param {[]} array
5
+ * @returns {*|undefined}
6
+ */
7
+ export default function last(array) {
8
+ const length = array == null ? 0 : array.length
9
+
10
+ return length ? array[ length - 1 ] : undefined
11
+ }
@@ -1,16 +1,16 @@
1
- /**
2
- * Remove a value from the given array, returning a copy.
3
- *
4
- * @param {[]} array
5
- * @param {*} value
6
- * @returns {*}
7
- */
8
- export default function remove(array, value) {
9
- const index = array.indexOf( value );
10
-
11
- if ( index > -1 ) {
12
- array.splice( index, 1 );
13
- }
14
-
15
- return array;
16
- }
1
+ /**
2
+ * Remove a value from the given array, returning a copy.
3
+ *
4
+ * @param {[]} array
5
+ * @param {*} value
6
+ * @returns {*}
7
+ */
8
+ export default function remove(array, value) {
9
+ const index = array.indexOf( value );
10
+
11
+ if ( index > -1 ) {
12
+ array.splice( index, 1 );
13
+ }
14
+
15
+ return array;
16
+ }
@@ -1,17 +1,17 @@
1
- /**
2
- * Replace a value from the given array by another one using a callback to find the index
3
- *
4
- * @param {[]} array
5
- * @param {*} callback
6
- * @param {*} value
7
- * @returns {[]}
8
- */
9
- export default function replace(array, callback, value) {
10
- const index = array.findIndex( callback );
11
-
12
- if ( index !== -1 ) {
13
- array[ index ] = value;
14
- }
15
-
16
- return array;
1
+ /**
2
+ * Replace a value from the given array by another one using a callback to find the index
3
+ *
4
+ * @param {[]} array
5
+ * @param {*} callback
6
+ * @param {*} value
7
+ * @returns {[]}
8
+ */
9
+ export default function replace(array, callback, value) {
10
+ const index = array.findIndex( callback );
11
+
12
+ if ( index !== -1 ) {
13
+ array[ index ] = value;
14
+ }
15
+
16
+ return array;
17
17
  }
package/src/date/clone.js CHANGED
@@ -1,9 +1,9 @@
1
- /**
2
- * Clone a Date object.
3
- *
4
- * @param {Date} date
5
- * @returns {Date}
6
- */
7
- export default function clone(date) {
8
- return new Date( date.getTime() );
9
- }
1
+ /**
2
+ * Clone a Date object.
3
+ *
4
+ * @param {Date} date
5
+ * @returns {Date}
6
+ */
7
+ export default function clone(date) {
8
+ return new Date( date.getTime() );
9
+ }
@@ -1,17 +1,17 @@
1
- /**
2
- * Get the week number of a Date object from the start of the year.
3
- *
4
- * @example getWeekNumber( new Date('Mon Mar 16 2026') )
5
- * => 12
6
- *
7
- * @param {Date} date
8
- * @returns {number}
9
- */
10
- export default function getWeekNumber(date) {
11
- date.setHours(0, 0, 0, 0);
12
- date.setDate( date.getDate() + 3 - ( date.getDay() + 6 ) % 7 );
13
-
14
- const first_week = new Date( date.getUTCFullYear(), 0, 4 );
15
-
16
- return 1 + Math.round(( ( date.getTime() - first_week.getTime() ) / 86400000 - 3 + ( first_week.getDay() + 6 ) % 7 ) / 7 );
17
- }
1
+ /**
2
+ * Get the week number of a Date object from the start of the year.
3
+ *
4
+ * @example getWeekNumber( new Date('Mon Mar 16 2026') )
5
+ * => 12
6
+ *
7
+ * @param {Date} date
8
+ * @returns {number}
9
+ */
10
+ export default function getWeekNumber(date) {
11
+ date.setHours(0, 0, 0, 0);
12
+ date.setDate( date.getDate() + 3 - ( date.getDay() + 6 ) % 7 );
13
+
14
+ const first_week = new Date( date.getUTCFullYear(), 0, 4 );
15
+
16
+ return 1 + Math.round(( ( date.getTime() - first_week.getTime() ) / 86400000 - 3 + ( first_week.getDay() + 6 ) % 7 ) / 7 );
17
+ }
package/src/date/index.js CHANGED
@@ -1,3 +1,3 @@
1
- export { default as getWeekNumber } from "./getWeekNumber.js";
2
- export { default as clone } from "./clone.js";
1
+ export { default as getWeekNumber } from "./getWeekNumber.js";
2
+ export { default as clone } from "./clone.js";
3
3
  export { default as reviver } from "./reviver.js";
@@ -1,13 +1,13 @@
1
- /**
2
- * Function that can be used with JSON.parse to revive Date objects.
3
- *
4
- * @param {*} value
5
- * @returns {Date|*}
6
- */
7
- export default function reviver(value) {
8
- if ( typeof value === 'string' && /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d{3}Z$/.test( value ) ) {
9
- return new Date( value );
10
- }
11
-
12
- return value;
1
+ /**
2
+ * Function that can be used with JSON.parse to revive Date objects.
3
+ *
4
+ * @param {*} value
5
+ * @returns {Date|*}
6
+ */
7
+ export default function reviver(value) {
8
+ if ( typeof value === 'string' && /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d{3}Z$/.test( value ) ) {
9
+ return new Date( value );
10
+ }
11
+
12
+ return value;
13
13
  }
@@ -1,22 +1,22 @@
1
- /**
2
- * Define event listeners on an element and returns an object with a callback for removing these listeners on each event.
3
- *
4
- * @example const removeListeners = addEventListeners(button, {
5
- * click: (event) => {...},
6
- * mouseover: (event) => {...},
7
- * } );
8
- * removeListeners.click();
9
- * => click event has been removed from the button
10
- *
11
- * @param {HTMLElement} element
12
- * @param {{}} listeners
13
- */
14
- export default function addEventListeners(element, listeners) {
15
- return Object.fromEntries(
16
- Object.entries( listeners ).map( ([event, callbackFn]) => {
17
- element.addEventListener( event, callbackFn );
18
-
19
- return [ event, () => element.removeEventListener( event, callbackFn ) ];
20
- } )
21
- );
1
+ /**
2
+ * Define event listeners on an element and returns an object with a callback for removing these listeners on each event.
3
+ *
4
+ * @example const removeListeners = addEventListeners(button, {
5
+ * click: (event) => {...},
6
+ * mouseover: (event) => {...},
7
+ * } );
8
+ * removeListeners.click();
9
+ * => click event has been removed from the button
10
+ *
11
+ * @param {HTMLElement} element
12
+ * @param {{}} listeners
13
+ */
14
+ export default function addEventListeners(element, listeners) {
15
+ return Object.fromEntries(
16
+ Object.entries( listeners ).map( ([event, callbackFn]) => {
17
+ element.addEventListener( event, callbackFn );
18
+
19
+ return [ event, () => element.removeEventListener( event, callbackFn ) ];
20
+ } )
21
+ );
22
22
  };
@@ -1,32 +1,32 @@
1
- /**
2
- * Select the closest element from another.
3
- *
4
- * @param {HTMLElement} element
5
- * @param {string} selector
6
- * @returns {HTMLAnchorElement|HTMLElement|HTMLAreaElement|HTMLAudioElement|HTMLBaseElement|HTMLQuoteElement|HTMLBodyElement|HTMLBRElement|HTMLButtonElement|HTMLCanvasElement|HTMLTableCaptionElement|HTMLTableColElement|HTMLDataElement|HTMLDataListElement|HTMLModElement|HTMLDetailsElement|HTMLDialogElement|HTMLDivElement|HTMLDListElement|HTMLEmbedElement|HTMLFieldSetElement|HTMLFormElement|HTMLHeadingElement|HTMLHeadElement|HTMLHRElement|HTMLHtmlElement|HTMLIFrameElement|HTMLImageElement|HTMLInputElement|HTMLLabelElement|HTMLLegendElement|HTMLLIElement|HTMLLinkElement|HTMLMapElement|HTMLMenuElement|HTMLMetaElement|HTMLMeterElement|HTMLObjectElement|HTMLOListElement|HTMLOptGroupElement|HTMLOptionElement|HTMLOutputElement|HTMLParagraphElement|HTMLPictureElement|HTMLPreElement|HTMLProgressElement|HTMLScriptElement|HTMLSelectElement|HTMLSlotElement|HTMLSourceElement|HTMLSpanElement|HTMLStyleElement|HTMLTableElement|HTMLTableSectionElement|HTMLTableCellElement|HTMLTemplateElement|HTMLTextAreaElement|HTMLTimeElement|HTMLTitleElement|HTMLTableRowElement|HTMLTrackElement|HTMLUListElement|HTMLVideoElement|*}
7
- */
8
- export default function closestElement(element, selector) {
9
- const recurse = parent => {
10
- parent = parent.parentNode;
11
-
12
- if ( !parent ) {
13
- return;
14
- }
15
-
16
- const sibling = parent.nextElementSibling;
17
-
18
- if ( sibling ) {
19
- const closestSibling = sibling.closest( selector );
20
-
21
- if ( closestSibling ) {
22
- return closestSibling;
23
- }
24
-
25
- return recurse( sibling );
26
- }
27
-
28
- return recurse( parent );
29
- };
30
-
31
- return recurse( element );
1
+ /**
2
+ * Select the closest element from another.
3
+ *
4
+ * @param {HTMLElement} element
5
+ * @param {string} selector
6
+ * @returns {HTMLAnchorElement|HTMLElement|HTMLAreaElement|HTMLAudioElement|HTMLBaseElement|HTMLQuoteElement|HTMLBodyElement|HTMLBRElement|HTMLButtonElement|HTMLCanvasElement|HTMLTableCaptionElement|HTMLTableColElement|HTMLDataElement|HTMLDataListElement|HTMLModElement|HTMLDetailsElement|HTMLDialogElement|HTMLDivElement|HTMLDListElement|HTMLEmbedElement|HTMLFieldSetElement|HTMLFormElement|HTMLHeadingElement|HTMLHeadElement|HTMLHRElement|HTMLHtmlElement|HTMLIFrameElement|HTMLImageElement|HTMLInputElement|HTMLLabelElement|HTMLLegendElement|HTMLLIElement|HTMLLinkElement|HTMLMapElement|HTMLMenuElement|HTMLMetaElement|HTMLMeterElement|HTMLObjectElement|HTMLOListElement|HTMLOptGroupElement|HTMLOptionElement|HTMLOutputElement|HTMLParagraphElement|HTMLPictureElement|HTMLPreElement|HTMLProgressElement|HTMLScriptElement|HTMLSelectElement|HTMLSlotElement|HTMLSourceElement|HTMLSpanElement|HTMLStyleElement|HTMLTableElement|HTMLTableSectionElement|HTMLTableCellElement|HTMLTemplateElement|HTMLTextAreaElement|HTMLTimeElement|HTMLTitleElement|HTMLTableRowElement|HTMLTrackElement|HTMLUListElement|HTMLVideoElement|*}
7
+ */
8
+ export default function closestElement(element, selector) {
9
+ const recurse = parent => {
10
+ parent = parent.parentNode;
11
+
12
+ if ( !parent ) {
13
+ return;
14
+ }
15
+
16
+ const sibling = parent.nextElementSibling;
17
+
18
+ if ( sibling ) {
19
+ const closestSibling = sibling.closest( selector );
20
+
21
+ if ( closestSibling ) {
22
+ return closestSibling;
23
+ }
24
+
25
+ return recurse( sibling );
26
+ }
27
+
28
+ return recurse( parent );
29
+ };
30
+
31
+ return recurse( element );
32
32
  }
@@ -1,20 +1,20 @@
1
- /**
2
- * Delegate an event through the Document to a selected element. Useful to define an event on an element which is not already created.
3
- * Returns a callback function that can be used to remove the event listener from the Document.
4
- *
5
- * @param {string} selector
6
- * @param {string} event
7
- * @param {Function} handler
8
- * @returns {function(): any}
9
- */
10
- export default function delegate(selector, event, handler) {
11
- const callback = function (event) {
12
- const matchingElement = event.target.closest( selector );
13
-
14
- return matchingElement !== null ? handler.call( matchingElement, event ) : false;
15
- };
16
-
17
- Element.prototype.addEventListener.call( document, event, callback, true );
18
-
19
- return () => Element.prototype.removeEventListener.call( document, event, callback, true );
1
+ /**
2
+ * Delegate an event through the Document to a selected element. Useful to define an event on an element which is not already created.
3
+ * Returns a callback function that can be used to remove the event listener from the Document.
4
+ *
5
+ * @param {string} selector
6
+ * @param {string} event
7
+ * @param {Function} handler
8
+ * @returns {function(): any}
9
+ */
10
+ export default function delegate(selector, event, handler) {
11
+ const callback = function (event) {
12
+ const matchingElement = event.target.closest( selector );
13
+
14
+ return matchingElement !== null ? handler.call( matchingElement, event ) : false;
15
+ };
16
+
17
+ Element.prototype.addEventListener.call( document, event, callback, true );
18
+
19
+ return () => Element.prototype.removeEventListener.call( document, event, callback, true );
20
20
  };
@@ -1,78 +1,78 @@
1
- /**
2
- * Get an object with every sizing values of an HTMLElement. Tricks the browser to get values if the element is hidden.
3
- *
4
- * @param {HTMLElement} element
5
- * @returns {{width: *, height: *, offsetWidth: *, offsetHeight: *, top: number, left: number, bottom: number, right: number,
6
- * x: number, y: number, marginLeft: number, marginTop: number, marginBottom: number, marginRight: number,
7
- * paddingLeft: number, paddingTop: number, paddingBottom: number, paddingRight: number}}
8
- */
9
- export default function getElementSizing(element) {
10
- const style = window.getComputedStyle( element );
11
- const display = style.display;
12
- const position = style.position;
13
- const visibility = style.visibility;
14
- const max_height = style.maxHeight.replace('px', '').replace('%', '');
15
-
16
- /** if it's not hidden we just return normal height */
17
- if ( display !== 'none' && max_height !== '0' ) {
18
- return getSizing( element, style );
19
- }
20
-
21
- /** the element is hidden, so we are making the element block, so we can measure its height but still be hidden */
22
- element.style.position = 'absolute';
23
- element.style.visibility = 'hidden';
24
- element.style.display = 'block';
25
-
26
- const sizing = getSizing( element, style );
27
-
28
- /** reverting to the original values */
29
- element.style.display = display;
30
- element.style.position = position === 'static' ? null : position;
31
- element.style.visibility = visibility === 'visible' ? null : visibility;
32
-
33
- return sizing;
34
- }
35
-
36
- /**
37
- * @param element {HTMLElement}
38
- * @param style {CSSStyleDeclaration}
39
- * @returns {{width: *, height: *, offsetWidth: *, offsetHeight: *, top: number, left: number, bottom: number, right: number,
40
- * x: number, y: number, marginLeft: number, marginTop: number, marginBottom: number, marginRight: number,
41
- * paddingLeft: number, paddingTop: number, paddingBottom: number, paddingRight: number}}
42
- */
43
- function getSizing(element, style) {
44
- const rect = element.getBoundingClientRect();
45
-
46
- const marginX = parseInt( style.marginLeft, 10 ) + parseInt( style.marginRight, 10 );
47
- const marginY = parseInt( style.marginTop, 10 ) + parseInt( style.marginBottom, 10 );
48
- const paddingX = parseInt( style.paddingLeft, 10 ) + parseInt( style.paddingRight, 10 );
49
- const paddingY = parseInt( style.paddingTop, 10 ) + parseInt( style.paddingBottom, 10 );
50
-
51
- const width = element.offsetWidth + marginX;
52
- const height = element.offsetHeight + marginY;
53
-
54
- return {
55
- width,
56
- height,
57
- offsetWidth: element.offsetWidth,
58
- offsetHeight: element.offsetHeight,
59
- top: rect.top,
60
- left: rect.left,
61
- bottom: rect.bottom,
62
- right: rect.right,
63
- x: rect.x,
64
- y: rect.y,
65
- marginLeft: parseInt( style.marginLeft ),
66
- marginTop: parseInt( style.marginTop ),
67
- marginBottom: parseInt( style.marginBottom ),
68
- marginRight: parseInt( style.marginRight ),
69
- marginX,
70
- marginY,
71
- paddingLeft: parseInt( style.paddingLeft ),
72
- paddingTop: parseInt( style.paddingTop ),
73
- paddingBottom: parseInt( style.paddingBottom ),
74
- paddingRight: parseInt( style.paddingRight ),
75
- paddingX,
76
- paddingY,
77
- };
1
+ /**
2
+ * Get an object with every sizing values of an HTMLElement. Tricks the browser to get values if the element is hidden.
3
+ *
4
+ * @param {HTMLElement} element
5
+ * @returns {{width: *, height: *, offsetWidth: *, offsetHeight: *, top: number, left: number, bottom: number, right: number,
6
+ * x: number, y: number, marginLeft: number, marginTop: number, marginBottom: number, marginRight: number,
7
+ * paddingLeft: number, paddingTop: number, paddingBottom: number, paddingRight: number}}
8
+ */
9
+ export default function getElementSizing(element) {
10
+ const style = window.getComputedStyle( element );
11
+ const display = style.display;
12
+ const position = style.position;
13
+ const visibility = style.visibility;
14
+ const max_height = style.maxHeight.replace('px', '').replace('%', '');
15
+
16
+ /** if it's not hidden we just return normal height */
17
+ if ( display !== 'none' && max_height !== '0' ) {
18
+ return getSizing( element, style );
19
+ }
20
+
21
+ /** the element is hidden, so we are making the element block, so we can measure its height but still be hidden */
22
+ element.style.position = 'absolute';
23
+ element.style.visibility = 'hidden';
24
+ element.style.display = 'block';
25
+
26
+ const sizing = getSizing( element, style );
27
+
28
+ /** reverting to the original values */
29
+ element.style.display = display;
30
+ element.style.position = position === 'static' ? null : position;
31
+ element.style.visibility = visibility === 'visible' ? null : visibility;
32
+
33
+ return sizing;
34
+ }
35
+
36
+ /**
37
+ * @param element {HTMLElement}
38
+ * @param style {CSSStyleDeclaration}
39
+ * @returns {{width: *, height: *, offsetWidth: *, offsetHeight: *, top: number, left: number, bottom: number, right: number,
40
+ * x: number, y: number, marginLeft: number, marginTop: number, marginBottom: number, marginRight: number,
41
+ * paddingLeft: number, paddingTop: number, paddingBottom: number, paddingRight: number}}
42
+ */
43
+ function getSizing(element, style) {
44
+ const rect = element.getBoundingClientRect();
45
+
46
+ const marginX = parseInt( style.marginLeft, 10 ) + parseInt( style.marginRight, 10 );
47
+ const marginY = parseInt( style.marginTop, 10 ) + parseInt( style.marginBottom, 10 );
48
+ const paddingX = parseInt( style.paddingLeft, 10 ) + parseInt( style.paddingRight, 10 );
49
+ const paddingY = parseInt( style.paddingTop, 10 ) + parseInt( style.paddingBottom, 10 );
50
+
51
+ const width = element.offsetWidth + marginX;
52
+ const height = element.offsetHeight + marginY;
53
+
54
+ return {
55
+ width,
56
+ height,
57
+ offsetWidth: element.offsetWidth,
58
+ offsetHeight: element.offsetHeight,
59
+ top: rect.top,
60
+ left: rect.left,
61
+ bottom: rect.bottom,
62
+ right: rect.right,
63
+ x: rect.x,
64
+ y: rect.y,
65
+ marginLeft: parseInt( style.marginLeft ),
66
+ marginTop: parseInt( style.marginTop ),
67
+ marginBottom: parseInt( style.marginBottom ),
68
+ marginRight: parseInt( style.marginRight ),
69
+ marginX,
70
+ marginY,
71
+ paddingLeft: parseInt( style.paddingLeft ),
72
+ paddingTop: parseInt( style.paddingTop ),
73
+ paddingBottom: parseInt( style.paddingBottom ),
74
+ paddingRight: parseInt( style.paddingRight ),
75
+ paddingX,
76
+ paddingY,
77
+ };
78
78
  }
@@ -1,17 +1,17 @@
1
- /**
2
- * Get an array of the fields value of an HTMLFormElement.
3
- *
4
- * @param {HTMLFormElement} form
5
- * @returns {{[p: string]: *}}
6
- */
7
- export default function (form) {
8
- return Object.fromEntries(
9
- [ ...form.elements ]
10
- .map( item => {
11
- const value = item.type === 'checkbox' ? item.checked : item.value;
12
-
13
- return [ item.name, value ];
14
- } )
15
- .filter( ( [ key ] ) => key.length > 0 )
16
- );
17
- }
1
+ /**
2
+ * Get an array of the fields value of an HTMLFormElement.
3
+ *
4
+ * @param {HTMLFormElement} form
5
+ * @returns {{[p: string]: *}}
6
+ */
7
+ export default function (form) {
8
+ return Object.fromEntries(
9
+ [ ...form.elements ]
10
+ .map( item => {
11
+ const value = item.type === 'checkbox' ? item.checked : item.value;
12
+
13
+ return [ item.name, value ];
14
+ } )
15
+ .filter( ( [ key ] ) => key.length > 0 )
16
+ );
17
+ }
package/src/dom/index.js CHANGED
@@ -1,11 +1,11 @@
1
- export { default as addEventListeners } from "./addEventListeners.js";
2
- export { default as closestElement } from "./closestElement.js";
3
- export { default as delegate } from "./delegate.js";
4
- export { default as getElementSizing } from "./getElementSizing.js";
5
- export { default as getFieldsValues } from "./getFieldsValues.js";
6
- export { default as onEachElements } from "./onEachElements.js";
7
- export { default as stringToHtml } from "./stringToHtml.js";
8
- export { default as unlessElementExists } from "./unlessElementExists.js";
9
- export { default as whenReady } from "./whenReady.js";
10
- export { default as whenResize } from "./whenResize.js";
1
+ export { default as addEventListeners } from "./addEventListeners.js";
2
+ export { default as closestElement } from "./closestElement.js";
3
+ export { default as delegate } from "./delegate.js";
4
+ export { default as getElementSizing } from "./getElementSizing.js";
5
+ export { default as getFieldsValues } from "./getFieldsValues.js";
6
+ export { default as onEachElements } from "./onEachElements.js";
7
+ export { default as stringToHtml } from "./stringToHtml.js";
8
+ export { default as unlessElementExists } from "./unlessElementExists.js";
9
+ export { default as whenReady } from "./whenReady.js";
10
+ export { default as whenResize } from "./whenResize.js";
11
11
  export { default as whenScroll } from "./whenScroll.js";