@blackbyte/sugar 1.0.0-beta.3 → 1.0.0-beta.5

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 (32) hide show
  1. package/dist/js/clipboard/_exports.d.ts +2 -1
  2. package/dist/js/clipboard/_exports.js +2 -1
  3. package/dist/js/clipboard/_exports.js.map +1 -1
  4. package/dist/js/clipboard/copyElement.d.ts +24 -0
  5. package/dist/js/clipboard/copyElement.js +43 -0
  6. package/dist/js/clipboard/copyElement.js.map +1 -0
  7. package/dist/js/clipboard/copyFile.d.ts +1 -1
  8. package/dist/js/clipboard/copyFile.js +1 -1
  9. package/dist/js/clipboard/copyText.d.ts +1 -1
  10. package/dist/js/clipboard/copyText.js +1 -1
  11. package/dist/js/clipboard/readFile.d.ts +1 -1
  12. package/dist/js/clipboard/readFile.js +1 -1
  13. package/dist/js/dom/event/viewportEvents.js +23 -0
  14. package/dist/js/dom/event/viewportEvents.js.map +1 -1
  15. package/dist/js/feature/sectionClasses.d.ts +10 -1
  16. package/dist/js/feature/sectionClasses.js +43 -6
  17. package/dist/js/feature/sectionClasses.js.map +1 -1
  18. package/dist/shared/currency/currencyStringToObject.d.ts +8 -9
  19. package/dist/shared/currency/currencyStringToObject.js.map +1 -1
  20. package/dist/shared/datetime/_exports.d.ts +4 -1
  21. package/dist/shared/datetime/_exports.js +4 -1
  22. package/dist/shared/datetime/_exports.js.map +1 -1
  23. package/dist/shared/datetime/diffBetweenDates.d.ts +39 -0
  24. package/dist/shared/datetime/diffBetweenDates.js +25 -0
  25. package/dist/shared/datetime/diffBetweenDates.js.map +1 -0
  26. package/dist/shared/datetime/parseDate.d.ts +38 -0
  27. package/dist/shared/datetime/parseDate.js +34 -0
  28. package/dist/shared/datetime/parseDate.js.map +1 -0
  29. package/dist/shared/datetime/toYyyyMmDd.d.ts +34 -0
  30. package/dist/shared/datetime/toYyyyMmDd.js +19 -0
  31. package/dist/shared/datetime/toYyyyMmDd.js.map +1 -0
  32. package/package.json +3 -1
@@ -1,5 +1,6 @@
1
+ import copyElement from './copyElement.js';
1
2
  import copyFile from './copyFile.js';
2
3
  import copyText from './copyText.js';
3
4
  import readFile from './readFile.js';
4
5
  import readText from './readText.js';
5
- export { copyFile as __copyFile, copyText as __copyText, readFile as __readFile, readText as __readText, copyFile, copyText, readFile, readText, };
6
+ export { copyElement as __copyElement, copyFile as __copyFile, copyText as __copyText, readFile as __readFile, readText as __readText, copyElement, copyFile, copyText, readFile, readText, };
@@ -1,6 +1,7 @@
1
+ import copyElement from './copyElement.js';
1
2
  import copyFile from './copyFile.js';
2
3
  import copyText from './copyText.js';
3
4
  import readFile from './readFile.js';
4
5
  import readText from './readText.js';
5
- export { copyFile as __copyFile, copyText as __copyText, readFile as __readFile, readText as __readText, copyFile, copyText, readFile, readText, };
6
+ export { copyElement as __copyElement, copyFile as __copyFile, copyText as __copyText, readFile as __readFile, readText as __readText, copyElement, copyFile, copyText, readFile, readText, };
6
7
  //# sourceMappingURL=_exports.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"_exports.js","sourceRoot":"","sources":["../../../src/js/clipboard/_exports.ts"],"names":[],"mappings":"AAAA,OAAO,QAAQ,MAAM,eAAe,CAAC;AACrC,OAAO,QAAQ,MAAM,eAAe,CAAC;AACrC,OAAO,QAAQ,MAAM,eAAe,CAAC;AACrC,OAAO,QAAQ,MAAM,eAAe,CAAC;AACrC,OAAO,EACL,QAAQ,IAAI,UAAU,EACtB,QAAQ,IAAI,UAAU,EACtB,QAAQ,IAAI,UAAU,EACtB,QAAQ,IAAI,UAAU,EACtB,QAAQ,EACR,QAAQ,EACR,QAAQ,EACR,QAAQ,GACT,CAAC"}
1
+ {"version":3,"file":"_exports.js","sourceRoot":"","sources":["../../../src/js/clipboard/_exports.ts"],"names":[],"mappings":"AAAA,OAAO,WAAW,MAAM,kBAAkB,CAAC;AAC3C,OAAO,QAAQ,MAAM,eAAe,CAAC;AACrC,OAAO,QAAQ,MAAM,eAAe,CAAC;AACrC,OAAO,QAAQ,MAAM,eAAe,CAAC;AACrC,OAAO,QAAQ,MAAM,eAAe,CAAC;AACrC,OAAO,EACL,WAAW,IAAI,aAAa,EAC5B,QAAQ,IAAI,UAAU,EACtB,QAAQ,IAAI,UAAU,EACtB,QAAQ,IAAI,UAAU,EACtB,QAAQ,IAAI,UAAU,EACtB,WAAW,EACX,QAAQ,EACR,QAAQ,EACR,QAAQ,EACR,QAAQ,GACT,CAAC"}
@@ -0,0 +1,24 @@
1
+ /**
2
+ * @name copyElement
3
+ * @namespace js.clipboard
4
+ * @type Function
5
+ * @platform js
6
+ * @async
7
+ * @status stable
8
+ *
9
+ * This function allows you to copy to the clipboard the passed dom node element with his style
10
+ *
11
+ * @param {HTMLElement} $elm The dom node element to copy to the clipboard
12
+ *
13
+ * @todo tests
14
+ *
15
+ * @snippet copyElement($1)
16
+ *
17
+ * @example js
18
+ * import { copyElement } from '@blackbyte/sugar/clipboard';
19
+ * copyElement($elm);
20
+ *
21
+ * @since 1.0.0
22
+ * @author Olivier Bossel <olivier.bossel@gmail.com> (https://blackbyte.space)
23
+ */
24
+ export default function copyElement($elm: HTMLElement): void;
@@ -0,0 +1,43 @@
1
+ // @ts-nocheck
2
+ /**
3
+ * @name copyElement
4
+ * @namespace js.clipboard
5
+ * @type Function
6
+ * @platform js
7
+ * @async
8
+ * @status stable
9
+ *
10
+ * This function allows you to copy to the clipboard the passed dom node element with his style
11
+ *
12
+ * @param {HTMLElement} $elm The dom node element to copy to the clipboard
13
+ *
14
+ * @todo tests
15
+ *
16
+ * @snippet copyElement($1)
17
+ *
18
+ * @example js
19
+ * import { copyElement } from '@blackbyte/sugar/clipboard';
20
+ * copyElement($elm);
21
+ *
22
+ * @since 1.0.0
23
+ * @author Olivier Bossel <olivier.bossel@gmail.com> (https://blackbyte.space)
24
+ */
25
+ export default function copyElement($elm) {
26
+ let range;
27
+ let selection;
28
+ if (document.body.createTextRange) {
29
+ range = document.body.createTextRange();
30
+ range.moveToElement($elm);
31
+ range.select();
32
+ }
33
+ else if (window.getSelection) {
34
+ selection = window.getSelection();
35
+ range = document.createRange();
36
+ range.selectNodeContents($elm);
37
+ selection.removeAllRanges();
38
+ selection.addRange(range);
39
+ }
40
+ document.execCommand('copy');
41
+ window.getSelection().removeAllRanges();
42
+ }
43
+ //# sourceMappingURL=copyElement.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"copyElement.js","sourceRoot":"","sources":["../../../src/js/clipboard/copyElement.ts"],"names":[],"mappings":"AAAA,cAAc;AAEd;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAM,CAAC,OAAO,UAAU,WAAW,CAAC,IAAiB;IACnD,IAAI,KAAK,CAAC;IACV,IAAI,SAAS,CAAC;IAEd,IAAI,QAAQ,CAAC,IAAI,CAAC,eAAe,EAAE,CAAC;QAClC,KAAK,GAAG,QAAQ,CAAC,IAAI,CAAC,eAAe,EAAE,CAAC;QACxC,KAAK,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC;QAC1B,KAAK,CAAC,MAAM,EAAE,CAAC;IACjB,CAAC;SAAM,IAAI,MAAM,CAAC,YAAY,EAAE,CAAC;QAC/B,SAAS,GAAG,MAAM,CAAC,YAAY,EAAE,CAAC;QAClC,KAAK,GAAG,QAAQ,CAAC,WAAW,EAAE,CAAC;QAC/B,KAAK,CAAC,kBAAkB,CAAC,IAAI,CAAC,CAAC;QAC/B,SAAS,CAAC,eAAe,EAAE,CAAC;QAC5B,SAAS,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;IAC5B,CAAC;IAED,QAAQ,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;IAC7B,MAAM,CAAC,YAAY,EAAE,CAAC,eAAe,EAAE,CAAC;AAC1C,CAAC"}
@@ -13,7 +13,7 @@
13
13
  *
14
14
  * @todo tests
15
15
  *
16
- * @snippet __copyFile($1)
16
+ * @snippet copyFile($1)
17
17
  *
18
18
  * @example js
19
19
  * import { copyFile } from '@blackbyte/sugar/clipboard';
@@ -22,7 +22,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
22
22
  *
23
23
  * @todo tests
24
24
  *
25
- * @snippet __copyFile($1)
25
+ * @snippet copyFile($1)
26
26
  *
27
27
  * @example js
28
28
  * import { copyFile } from '@blackbyte/sugar/clipboard';
@@ -13,7 +13,7 @@
13
13
  *
14
14
  * @todo tests
15
15
  *
16
- * @snippet __copy($1)
16
+ * @snippet copyText($1)
17
17
  *
18
18
  * @example js
19
19
  * import { copyText } from '@blackbyte/sugar/clipboard';
@@ -13,7 +13,7 @@
13
13
  *
14
14
  * @todo tests
15
15
  *
16
- * @snippet __copy($1)
16
+ * @snippet copyText($1)
17
17
  *
18
18
  * @example js
19
19
  * import { copyText } from '@blackbyte/sugar/clipboard';
@@ -12,7 +12,7 @@
12
12
  *
13
13
  * @todo tests
14
14
  *
15
- * @snippet __readFile($1)
15
+ * @snippet readFile($1)
16
16
  *
17
17
  * @example js
18
18
  * import { readFile } from '@blackbyte/sugar/clipboard';
@@ -21,7 +21,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
21
21
  *
22
22
  * @todo tests
23
23
  *
24
- * @snippet __readFile($1)
24
+ * @snippet readFile($1)
25
25
  *
26
26
  * @example js
27
27
  * import { readFile } from '@blackbyte/sugar/clipboard';
@@ -1,3 +1,4 @@
1
+ import { distanceFromElementTopToViewportTop } from '../_exports.js';
1
2
  const _viewportEventsInited = new WeakMap();
2
3
  export default function viewportEvents($elm, settings) {
3
4
  let observer, status = 'out';
@@ -16,6 +17,17 @@ export default function viewportEvents($elm, settings) {
16
17
  if (status === 'in') {
17
18
  return;
18
19
  }
20
+ const distanceToTop = distanceFromElementTopToViewportTop($elm);
21
+ if (distanceToTop < window.innerHeight * 0.5) {
22
+ $elm.dispatchEvent(new CustomEvent('viewport.enter.above', {
23
+ bubbles: true,
24
+ }));
25
+ }
26
+ else {
27
+ $elm.dispatchEvent(new CustomEvent('viewport.enter.below', {
28
+ bubbles: true,
29
+ }));
30
+ }
19
31
  status = 'in';
20
32
  $elm.dispatchEvent(new CustomEvent('viewport.enter', {
21
33
  bubbles: true,
@@ -31,6 +43,17 @@ export default function viewportEvents($elm, settings) {
31
43
  if (status === 'out') {
32
44
  return;
33
45
  }
46
+ const distanceToTop = distanceFromElementTopToViewportTop($elm);
47
+ if (distanceToTop < window.innerHeight * 0.5) {
48
+ $elm.dispatchEvent(new CustomEvent('viewport.leave.above', {
49
+ bubbles: true,
50
+ }));
51
+ }
52
+ else {
53
+ $elm.dispatchEvent(new CustomEvent('viewport.leave.below', {
54
+ bubbles: true,
55
+ }));
56
+ }
34
57
  status = 'out';
35
58
  $elm.dispatchEvent(new CustomEvent('viewport.leave', {
36
59
  bubbles: true,
@@ -1 +1 @@
1
- {"version":3,"file":"viewportEvents.js","sourceRoot":"","sources":["../../../../src/js/dom/event/viewportEvents.ts"],"names":[],"mappings":"AAgDA,MAAM,qBAAqB,GAAG,IAAI,OAAO,EAAE,CAAC;AAE5C,MAAM,CAAC,OAAO,UAAU,cAAc,CACpC,IAAiB,EACjB,QAA2C;IAE3C,IAAI,QAAQ,EACV,MAAM,GAAG,KAAK,CAAC;IAEjB,IAAI,qBAAqB,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC;QACpC,OAAO,IAAI,CAAC;IACd,CAAC;IACD,qBAAqB,CAAC,GAAG,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IAEtC,MAAM,aAAa,mBACjB,MAAM,EAAE,EAAE,EACV,IAAI,EAAE,KAAK,IACR,CAAC,QAAQ,aAAR,QAAQ,cAAR,QAAQ,GAAI,EAAE,CAAC,CACpB,CAAC;IAEF,QAAQ,GAAG,IAAI,oBAAoB,CACjC,CAAC,OAAO,EAAE,QAAQ,EAAE,EAAE;QACpB,IAAI,CAAC,OAAO,CAAC,MAAM;YAAE,OAAO;QAC5B,MAAM,KAAK,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC;QAC5B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d,CAAC,CACH,CAAC;QACJ,CAAC;IACH,CAAC,EACD;QACE,IAAI,EAAE,IAAI,EAAE,WAAW;QACvB,UAAU,EACR,OAAO,aAAa,CAAC,MAAM,KAAK,QAAQ;YACtC,CAAC,CAAC,aAAa,CAAC,MAAM;YACtB,CAAC,CAAC,GAAG,aAAa,CAAC,MAAM,IAAI;QACjC,SAAS,EAAE,CAAC,CAAC,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC,CAAC;KAC/D,CACF,CAAC;IAEF,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IAEvB,OAAO,IAAI,CAAC;AACd,CAAC"}
@@ -6,8 +6,12 @@
6
6
  * @status stable
7
7
  *
8
8
  *
9
- * This feature allows you to add some classes on your sections when they are in the viewport, near the viewport, etc...
9
+ * This feature allows you to add some classes on your sections when they are in the viewport, near the viewport, above, etc...
10
10
  * 1. `-in-viewport`: Added when the section is in the viewport
11
+ * 2. `-from-above`: Added when the section enters the viewport from above
12
+ * 3. `-from-below`: Added when the section enters the viewport from below
13
+ * 4. `-above-viewport`: Added when the section is above the viewport
14
+ * 5. `-below-viewport`: Added when the section is below the viewport
11
15
  *
12
16
  * @param {TSectionClassesSettings} [settings={}] The settings you want to override
13
17
  *
@@ -25,6 +29,11 @@
25
29
  */
26
30
  export type TSectionClassesSettings = {
27
31
  inClass: string;
32
+ fromAboveClass: string;
33
+ fromBelowClass: string;
34
+ aboveClass: string;
35
+ belowClass: string;
28
36
  offset: number;
37
+ once?: boolean;
29
38
  };
30
39
  export default function sectionClasses(settings?: Partial<TSectionClassesSettings>): void;
@@ -6,8 +6,12 @@
6
6
  * @status stable
7
7
  *
8
8
  *
9
- * This feature allows you to add some classes on your sections when they are in the viewport, near the viewport, etc...
9
+ * This feature allows you to add some classes on your sections when they are in the viewport, near the viewport, above, etc...
10
10
  * 1. `-in-viewport`: Added when the section is in the viewport
11
+ * 2. `-from-above`: Added when the section enters the viewport from above
12
+ * 3. `-from-below`: Added when the section enters the viewport from below
13
+ * 4. `-above-viewport`: Added when the section is above the viewport
14
+ * 5. `-below-viewport`: Added when the section is below the viewport
11
15
  *
12
16
  * @param {TSectionClassesSettings} [settings={}] The settings you want to override
13
17
  *
@@ -25,20 +29,53 @@
25
29
  */
26
30
  import { querySelectorLive, viewportEvents } from '@blackbyte/sugar/dom';
27
31
  export default function sectionClasses(settings) {
28
- const finalSettings = Object.assign({ inClass: '-in-viewport', offset: 25 }, settings);
32
+ const finalSettings = Object.assign({ inClass: '-in-viewport', fromAboveClass: '-from-above', fromBelowClass: '-from-below', aboveClass: '-above-viewport', belowClass: '-below-viewport', offset: 25 }, settings);
29
33
  querySelectorLive('section', ($section) => {
30
34
  // listen for enter/leave viewport
31
35
  viewportEvents($section, {
32
36
  offset: finalSettings.offset,
37
+ once: finalSettings.once,
33
38
  });
34
- $section.addEventListener('viewport.enter', () => {
39
+ const enterHandler = () => {
35
40
  // add the inClass on the section
36
41
  $section.classList.add(finalSettings.inClass);
37
- });
38
- $section.addEventListener('viewport.leave', () => {
42
+ // remove above/below classes
43
+ $section.classList.remove(finalSettings.aboveClass);
44
+ $section.classList.remove(finalSettings.belowClass);
45
+ // stop if "once" setting is enabled
46
+ if (finalSettings.once) {
47
+ $section.removeEventListener('viewport.enter', enterHandler);
48
+ $section.removeEventListener('viewport.leave', leaveHandler);
49
+ $section.removeEventListener('viewport.enter.above', enterAboveHandler);
50
+ $section.removeEventListener('viewport.enter.below', enterBelowHandler);
51
+ }
52
+ };
53
+ const leaveHandler = () => {
39
54
  // remove the inClass on the section
40
55
  $section.classList.remove(finalSettings.inClass);
41
- });
56
+ $section.classList.remove(finalSettings.fromAboveClass);
57
+ $section.classList.remove(finalSettings.fromBelowClass);
58
+ };
59
+ const enterBelowHandler = () => {
60
+ $section.classList.add(finalSettings.fromBelowClass);
61
+ };
62
+ const enterAboveHandler = () => {
63
+ // add the inClass on the section
64
+ $section.classList.add(finalSettings.fromAboveClass);
65
+ };
66
+ const leaveAboveHandler = () => {
67
+ // remove the inClass on the section
68
+ $section.classList.add(finalSettings.aboveClass);
69
+ };
70
+ const leaveBelowHandler = () => {
71
+ $section.classList.add(finalSettings.belowClass);
72
+ };
73
+ $section.addEventListener('viewport.enter.above', enterAboveHandler);
74
+ $section.addEventListener('viewport.enter.below', enterBelowHandler);
75
+ $section.addEventListener('viewport.leave.above', leaveAboveHandler);
76
+ $section.addEventListener('viewport.leave.below', leaveBelowHandler);
77
+ $section.addEventListener('viewport.enter', enterHandler);
78
+ $section.addEventListener('viewport.leave', leaveHandler);
42
79
  });
43
80
  }
44
81
  //# sourceMappingURL=sectionClasses.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"sectionClasses.js","sourceRoot":"","sources":["../../../src/js/feature/sectionClasses.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAEH,OAAO,EAAE,iBAAiB,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAOzE,MAAM,CAAC,OAAO,UAAU,cAAc,CACpC,QAA2C;IAE3C,MAAM,aAAa,mBACjB,OAAO,EAAE,cAAc,EACvB,MAAM,EAAE,EAAE,IACP,QAAQ,CACZ,CAAC;IAEF,iBAAiB,CAAC,SAAS,EAAE,CAAC,QAAQ,EAAE,EAAE;QACxC,kCAAkC;QAClC,cAAc,CAAC,QAAQ,EAAE;YACvB,MAAM,EAAE,aAAa,CAAC,MAAM;SAC7B,CAAC,CAAC;QACH,QAAQ,CAAC,gBAAgB,CAAC,gBAAgB,EAAE,GAAG,EAAE;YAC/C,iCAAiC;YACjC,QAAQ,CAAC,SAAS,CAAC,GAAG,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC;QAChD,CAAC,CAAC,CAAC;QACH,QAAQ,CAAC,gBAAgB,CAAC,gBAAgB,EAAE,GAAG,EAAE;YAC/C,oCAAoC;YACpC,QAA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rE,QAAQ,CAAC,gBAAgB,CAAC,sBAAsB,EAAE,iBAAiB,CAAC,CAAC;QACrE,QAAQ,CAAC,gBAAgB,CAAC,gBAAgB,EAAE,YAAY,CAAC,CAAC;QAC1D,QAAQ,CAAC,gBAAgB,CAAC,gBAAgB,EAAE,YAAY,CAAC,CAAC;IAC5D,CAAC,CAAC,CAAC;AACL,CAAC"}
@@ -7,12 +7,11 @@
7
7
  * @status stable
8
8
  *
9
9
  * This function take a currency string like "120 USD" and convert it to an object
10
- * like:
11
- * {
12
- * "amount": 120,
13
- * "code": "USD",
14
- * "symbol": "$"
15
- * }
10
+ * containing these properties:
11
+ *
12
+ * - `amount`: 120,
13
+ * - `code`: USD,
14
+ * - `symbol`: $
16
15
  *
17
16
  * @param {String} currency The currency string to convert
18
17
  * @return {TCurrencyToObject} The currency object
@@ -23,9 +22,9 @@
23
22
  * import { currencyStringToObject } from '@blackbyte/sugar/currency';
24
23
  * currencyStringToObject('120 $');
25
24
  * {
26
- * "amount": 120,
27
- * "code": "USD",
28
- * "symbol": "$"
25
+ * amount: 120,
26
+ * code: 'USD',
27
+ * symbol: '$'
29
28
  * }
30
29
  *
31
30
  * @see https://www.npmjs.com/package/currency-symbol-map
@@ -1 +1 @@
1
- {"version":3,"file":"currencyStringToObject.js","sourceRoot":"","sources":["../../../src/shared/currency/currencyStringToObject.ts"],"names":[],"mappings":"AAAA,OAAO,iBAAiB,MAAM,qBAAqB,CAAC;AA2CpD,MAAM,CAAC,OAAO,UAAU,sBAAsB,CAC5C,QAAgB;;IAEhB,iBAAiB;IACjB,MAAM,MAAM,GAAG,UAAU,CAAC,QAAQ,CAAC,CAAC;IAEpC,yBAAyB;IACzB,MAAM,YAAY,GAAW,QAAQ,CAAC,OAAO,CAAC,cAAc,EAAE,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC;IAEzE,aAAa;IACb,MAAM,SAAS,GAAG,iBAAiB,CAAC,iBAAwB,CAAC;IAE7D,kCAAkC;IAClC,IAAI,IAAI,GAAG,EAAE,EACX,MAAM,GAAG,EAAE,CAAC;IACd,IAAI,SAAS,CAAC,YAAY,CAAC,EAAE,CAAC;QAC5B,IAAI,GAAG,YAAY,CAAC;QACpB,MAAM,GAAG,SAAS,CAAC,YAAY,CAAC,CAAC;IACnC,CAAC;SAAM,CAAC;QACN,IAAI;YACF,MAAA,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,SAAS,CAAC,GAAG,CAAC,KAAK,YAAY,CAAC,mCACrE,EAAE,CAAC;QACL,MAAM,GAAG,YAAY,CAAC;IACxB,CAAC;IAED,OAAO;QACL,MAAM,EAAE,MAAM;QACd,IAAI;QACJ,MAAM;KACP,CAAC;AACJ,CAAC"}
1
+ {"version":3,"file":"currencyStringToObject.js","sourceRoot":"","sources":["../../../src/shared/currency/currencyStringToObject.ts"],"names":[],"mappings":"AAAA,OAAO,iBAAiB,MAAM,qBAAqB,CAAC;AA0CpD,MAAM,CAAC,OAAO,UAAU,sBAAsB,CAC5C,QAAgB;;IAEhB,iBAAiB;IACjB,MAAM,MAAM,GAAG,UAAU,CAAC,QAAQ,CAAC,CAAC;IAEpC,yBAAyB;IACzB,MAAM,YAAY,GAAW,QAAQ,CAAC,OAAO,CAAC,cAAc,EAAE,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC;IAEzE,aAAa;IACb,MAAM,SAAS,GAAG,iBAAiB,CAAC,iBAAwB,CAAC;IAE7D,kCAAkC;IAClC,IAAI,IAAI,GAAG,EAAE,EACX,MAAM,GAAG,EAAE,CAAC;IACd,IAAI,SAAS,CAAC,YAAY,CAAC,EAAE,CAAC;QAC5B,IAAI,GAAG,YAAY,CAAC;QACpB,MAAM,GAAG,SAAS,CAAC,YAAY,CAAC,CAAC;IACnC,CAAC;SAAM,CAAC;QACN,IAAI;YACF,MAAA,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,SAAS,CAAC,GAAG,CAAC,KAAK,YAAY,CAAC,mCACrE,EAAE,CAAC;QACL,MAAM,GAAG,YAAY,CAAC;IACxB,CAAC;IAED,OAAO;QACL,MAAM,EAAE,MAAM;QACd,IAAI;QACJ,MAAM;KACP,CAAC;AACJ,CAAC"}
@@ -1,7 +1,10 @@
1
+ import diffBetweenDates from './diffBetweenDates.js';
1
2
  import formatDuration from './formatDuration.js';
3
+ import parseDate from './parseDate.js';
2
4
  import sleep from './sleep.js';
3
5
  import timeAgo from './timeAgo.js';
6
+ import toYyyyMmDd from './toYyyyMmDd.js';
4
7
  import utcTime from './utcTime.js';
5
8
  import wait from './wait.js';
6
9
  export * from './convertTime.js';
7
- export { formatDuration as __formatDuration, sleep as __sleep, timeAgo as __timeAgo, utcTime as __utcTime, wait as __wait, formatDuration, sleep, timeAgo, utcTime, wait, };
10
+ export { diffBetweenDates as __diffBetweenDates, formatDuration as __formatDuration, parseDate as __parseDate, sleep as __sleep, timeAgo as __timeAgo, toYyyyMmDd as __toYyyyMmDd, utcTime as __utcTime, wait as __wait, diffBetweenDates, formatDuration, parseDate, sleep, timeAgo, toYyyyMmDd, utcTime, wait, };
@@ -1,8 +1,11 @@
1
+ import diffBetweenDates from './diffBetweenDates.js';
1
2
  import formatDuration from './formatDuration.js';
3
+ import parseDate from './parseDate.js';
2
4
  import sleep from './sleep.js';
3
5
  import timeAgo from './timeAgo.js';
6
+ import toYyyyMmDd from './toYyyyMmDd.js';
4
7
  import utcTime from './utcTime.js';
5
8
  import wait from './wait.js';
6
9
  export * from './convertTime.js';
7
- export { formatDuration as __formatDuration, sleep as __sleep, timeAgo as __timeAgo, utcTime as __utcTime, wait as __wait, formatDuration, sleep, timeAgo, utcTime, wait, };
10
+ export { diffBetweenDates as __diffBetweenDates, formatDuration as __formatDuration, parseDate as __parseDate, sleep as __sleep, timeAgo as __timeAgo, toYyyyMmDd as __toYyyyMmDd, utcTime as __utcTime, wait as __wait, diffBetweenDates, formatDuration, parseDate, sleep, timeAgo, toYyyyMmDd, utcTime, wait, };
8
11
  //# sourceMappingURL=_exports.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"_exports.js","sourceRoot":"","sources":["../../../src/shared/datetime/_exports.ts"],"names":[],"mappings":"AAAA,OAAO,cAAc,MAAM,qBAAqB,CAAC;AACjD,OAAO,KAAK,MAAM,YAAY,CAAC;AAC/B,OAAO,OAAO,MAAM,cAAc,CAAC;AACnC,OAAO,OAAO,MAAM,cAAc,CAAC;AACnC,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,cAAc,kBAAkB,CAAC;AACjC,OAAO,EACL,cAAc,IAAI,gBAAgB,EAClC,KAAK,IAAI,OAAO,EAChB,OAAO,IAAI,SAAS,EACpB,OAAO,IAAI,SAAS,EACpB,IAAI,IAAI,MAAM,EACd,cAAc,EACd,KAAK,EACL,OAAO,EACP,OAAO,EACP,IAAI,GACL,CAAC"}
1
+ {"version":3,"file":"_exports.js","sourceRoot":"","sources":["../../../src/shared/datetime/_exports.ts"],"names":[],"mappings":"AAAA,OAAO,gBAAgB,MAAM,uBAAuB,CAAC;AACrD,OAAO,cAAc,MAAM,qBAAqB,CAAC;AACjD,OAAO,SAAS,MAAM,gBAAgB,CAAC;AACvC,OAAO,KAAK,MAAM,YAAY,CAAC;AAC/B,OAAO,OAAO,MAAM,cAAc,CAAC;AACnC,OAAO,UAAU,MAAM,iBAAiB,CAAC;AACzC,OAAO,OAAO,MAAM,cAAc,CAAC;AACnC,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,cAAc,kBAAkB,CAAC;AACjC,OAAO,EACL,gBAAgB,IAAI,kBAAkB,EACtC,cAAc,IAAI,gBAAgB,EAClC,SAAS,IAAI,WAAW,EACxB,KAAK,IAAI,OAAO,EAChB,OAAO,IAAI,SAAS,EACpB,UAAU,IAAI,YAAY,EAC1B,OAAO,IAAI,SAAS,EACpB,IAAI,IAAI,MAAM,EACd,gBAAgB,EAChB,cAAc,EACd,SAAS,EACT,KAAK,EACL,OAAO,EACP,UAAU,EACV,OAAO,EACP,IAAI,GACL,CAAC"}
@@ -0,0 +1,39 @@
1
+ /**
2
+ * @name diffBetweenDates
3
+ * @namespace shared.datetime
4
+ * @type Function
5
+ * @platform js
6
+ * @platform node
7
+ * @status stable
8
+ *
9
+ * This function allows you to get the difference between two date strings.
10
+ * It will returns you an object with the difference represented with these properties (years, months, days, hours, minutes, seconds).
11
+ * Under the hood, it make uses of the wonderful [Luxon](https://moment.github.io/luxon) library.
12
+ *
13
+ * @param {String} date The date string to parse
14
+ * @param {TDiffBetweenDatesSettings} [settings={}] Some settings to configure your parsing
15
+ * @return {Date} The `Date` instance representing your date string
16
+ *
17
+ * @setting {String} [format=''] If you know the format of your date string, you can pass it here. This will make the parsing faster and more reliable. See [Luxon documentation](https://moment.github.io/luxon/#/parsing?id=table-of-tokens) for the list of supported tokens.
18
+ *
19
+ * @snippet diffBetweenDates($1, $2, $3)
20
+ *
21
+ * @example js
22
+ * import { diffBetweenDates } from '@blackbyte/sugar/datetime';
23
+ * diffBetweenDates('1945-10-12', '2025-10-15');
24
+ *
25
+ * @see https://moment.github.io/luxon
26
+ * @since 1.0.0
27
+ * @author Olivier Bossel <olivier.bossel@gmail.com> (https://blackbyte.space)
28
+ */
29
+ export type TDiffBetweenDatesSettings = {
30
+ format: string;
31
+ };
32
+ export default function diffBetweenDates(date1: string | Date, date2: string | Date, settings?: Partial<TDiffBetweenDatesSettings>): {
33
+ years?: number;
34
+ months?: number;
35
+ days?: number;
36
+ hours?: number;
37
+ minutes?: number;
38
+ seconds?: number;
39
+ } | null;
@@ -0,0 +1,25 @@
1
+ import { DateTime } from 'luxon';
2
+ import parseDate from './parseDate.js';
3
+ export default function diffBetweenDates(date1, date2, settings) {
4
+ const finalSettings = Object.assign({ format: '' }, (settings !== null && settings !== void 0 ? settings : {}));
5
+ // prse the passed date
6
+ const jsDate1 = parseDate(date1, finalSettings);
7
+ const jsDate2 = parseDate(date2, finalSettings);
8
+ if (!jsDate1 || !jsDate2) {
9
+ return null;
10
+ }
11
+ const luxonDate1 = DateTime.fromJSDate(jsDate1);
12
+ const luxonDate2 = DateTime.fromJSDate(jsDate2);
13
+ const diff = luxonDate2
14
+ .diff(luxonDate1, [
15
+ 'years',
16
+ 'months',
17
+ 'days',
18
+ 'hours',
19
+ 'minutes',
20
+ 'seconds',
21
+ ])
22
+ .toObject();
23
+ return diff;
24
+ }
25
+ //# sourceMappingURL=diffBetweenDates.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"diffBetweenDates.js","sourceRoot":"","sources":["../../../src/shared/datetime/diffBetweenDates.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACjC,OAAO,SAAS,MAAM,gBAAgB,CAAC;AAmCvC,MAAM,CAAC,OAAO,UAAU,gBAAgB,CACtC,KAAoB,EACpB,KAAoB,EACpB,QAA6C;IAS7C,MAAM,aAAa,mBACjB,MAAM,EAAE,EAAE,IACP,CAAC,QAAQ,aAAR,QAAQ,cAAR,QAAQ,GAAI,EAAE,CAAC,CACpB,CAAC;IAEF,uBAAuB;IACvB,MAAM,OAAO,GAAG,SAAS,CAAC,KAAK,EAAE,aAAa,CAAC,CAAC;IAChD,MAAM,OAAO,GAAG,SAAS,CAAC,KAAK,EAAE,aAAa,CAAC,CAAC;IAEhD,IAAI,CAAC,OAAO,IAAI,CAAC,OAAO,EAAE,CAAC;QACzB,OAAO,IAAI,CAAC;IACd,CAAC;IAED,MAAM,UAAU,GAAG,QAAQ,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;IAChD,MAAM,UAAU,GAAG,QAAQ,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;IAEhD,MAAM,IAAI,GAAG,UAAU;SACpB,IAAI,CAAC,UAAU,EAAE;QAChB,OAAO;QACP,QAAQ;QACR,MAAM;QACN,OAAO;QACP,SAAS;QACT,SAAS;KACV,CAAC;SACD,QAAQ,EAAE,CAAC;IAEd,OAAO,IAAI,CAAC;AACd,CAAC"}
@@ -0,0 +1,38 @@
1
+ /**
2
+ * @name parseDate
3
+ * @namespace shared.datetime
4
+ * @type Function
5
+ * @platform js
6
+ * @platform node
7
+ * @status stable
8
+ *
9
+ * This function allows you to parse a date string. It will returns the `Date` instance for this date.
10
+ * Under the hood, it make uses of the wonderful [Luxon](https://moment.github.io/luxon) library.
11
+ * Make sure to use the library if you need more control over your dates.
12
+ * Luxon support these date formats:
13
+ *
14
+ * - ISO 8601
15
+ * - RFC2822
16
+ * - HTTP (header)
17
+ *
18
+ * @param {String} date The date string to parse
19
+ * @param {TParseDateSettings} [settings={}] Some settings to configure your parsing
20
+ * @return {Date} The `Date` instance representing your date string
21
+ *
22
+ * @setting {String} [format=''] If you know the format of your date string, you can pass it here. This will make the parsing faster and more reliable. See [Luxon documentation](https://moment.github.io/luxon/#/parsing?id=table-of-tokens) for the list of supported tokens.
23
+ *
24
+ * @snippet parseDate($1, $2)
25
+ *
26
+ * @example js
27
+ * import { parseDate } from '@blackbyte/sugar/datetime';
28
+ * parseDate('2025-10-12');
29
+ * parseDate('2024-10-15T10:30:00Z');
30
+ *
31
+ * @see https://moment.github.io/luxon
32
+ * @since 1.0.0
33
+ * @author Olivier Bossel <olivier.bossel@gmail.com> (https://blackbyte.space)
34
+ */
35
+ export type TParseDateSettings = {
36
+ format: string;
37
+ };
38
+ export default function parseDate(date: string | Date, settings?: Partial<TParseDateSettings>): Date | null;
@@ -0,0 +1,34 @@
1
+ import { DateTime } from 'luxon';
2
+ export default function parseDate(date, settings) {
3
+ const finalSettings = Object.assign({ format: '' }, (settings !== null && settings !== void 0 ? settings : {}));
4
+ let luxonDate;
5
+ // if it is already a date, we just return it
6
+ if (date instanceof Date) {
7
+ return date;
8
+ }
9
+ // if a format is passed, we check this.
10
+ // if it's invalid, we return null
11
+ if (finalSettings.format) {
12
+ luxonDate = DateTime.fromFormat(date, finalSettings.format);
13
+ }
14
+ if (luxonDate === null || luxonDate === void 0 ? void 0 : luxonDate.invalid) {
15
+ return null;
16
+ }
17
+ // otherwise we try to parse the date string
18
+ // using all the format supported by luxon
19
+ luxonDate = DateTime.fromISO(date);
20
+ if (!(luxonDate === null || luxonDate === void 0 ? void 0 : luxonDate.invalid)) {
21
+ return luxonDate.toJSDate();
22
+ }
23
+ luxonDate = DateTime.fromRFC2822(date);
24
+ if (!(luxonDate === null || luxonDate === void 0 ? void 0 : luxonDate.invalid)) {
25
+ return luxonDate.toJSDate();
26
+ }
27
+ luxonDate = DateTime.fromHTTP(date);
28
+ if (!(luxonDate === null || luxonDate === void 0 ? void 0 : luxonDate.invalid)) {
29
+ return luxonDate.toJSDate();
30
+ }
31
+ // nothing worked...
32
+ return null;
33
+ }
34
+ //# sourceMappingURL=parseDate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parseDate.js","sourceRoot":"","sources":["../../../src/shared/datetime/parseDate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAyCjC,MAAM,CAAC,OAAO,UAAU,SAAS,CAC/B,IAAmB,EACnB,QAAsC;IAEtC,MAAM,aAAa,mBACjB,MAAM,EAAE,EAAE,IACP,CAAC,QAAQ,aAAR,QAAQ,cAAR,QAAQ,GAAI,EAAE,CAAC,CACpB,CAAC;IACF,IAAI,SAAS,CAAC;IAEd,6CAA6C;IAC7C,IAAI,IAAI,YAAY,IAAI,EAAE,CAAC;QACzB,OAAO,IAAI,CAAC;IACd,CAAC;IAED,wCAAwC;IACxC,kCAAkC;IAClC,IAAI,aAAa,CAAC,MAAM,EAAE,CAAC;QACzB,SAAS,GAAG,QAAQ,CAAC,UAAU,CAAC,IAAI,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC;IAC9D,CAAC;IACD,IAAI,SAAS,aAAT,SAAS,uBAAT,SAAS,CAAE,OAAO,EAAE,CAAC;QACvB,OAAO,IAAI,CAAC;IACd,CAAC;IAED,4CAA4C;IAC5C,0CAA0C;IAC1C,SAAS,GAAG,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IACnC,IAAI,CAAC,CAAA,SAAS,aAAT,SAAS,uBAAT,SAAS,CAAE,OAAO,CAAA,EAAE,CAAC;QACxB,OAAO,SAAS,CAAC,QAAQ,EAAE,CAAC;IAC9B,CAAC;IAED,SAAS,GAAG,QAAQ,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;IACvC,IAAI,CAAC,CAAA,SAAS,aAAT,SAAS,uBAAT,SAAS,CAAE,OAAO,CAAA,EAAE,CAAC;QACxB,OAAO,SAAS,CAAC,QAAQ,EAAE,CAAC;IAC9B,CAAC;IAED,SAAS,GAAG,QAAQ,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;IACpC,IAAI,CAAC,CAAA,SAAS,aAAT,SAAS,uBAAT,SAAS,CAAE,OAAO,CAAA,EAAE,CAAC;QACxB,OAAO,SAAS,CAAC,QAAQ,EAAE,CAAC;IAC9B,CAAC;IAED,oBAAoB;IACpB,OAAO,IAAI,CAAC;AACd,CAAC"}
@@ -0,0 +1,34 @@
1
+ /**
2
+ * @name toYyyyMmDd
3
+ * @namespace shared.datetime
4
+ * @type Function
5
+ * @platform js
6
+ * @platform node
7
+ * @status stable
8
+ *
9
+ * This function allows you to pass any date string or Date instance and get back this
10
+ * one formatted as `YYYY-MM-DD`.
11
+ * This format is useful when you need to store dates in a database, set a date input value, etc...
12
+ * Under the hood, it make uses of the wonderful [Luxon](https://moment.github.io/luxon) library.
13
+ *
14
+ * @param {String} date The date (string) to convert to `YYYY-MM-DD`
15
+ * @param {TtoYyyyMmDdSettings} [settings={}] Some settings to configure your parsing
16
+ * @return {String} The date formatted as `YYYY-MM-DD`
17
+ *
18
+ * @setting {String} [format=''] If you know the format of your date string, you can pass it here. This will make the parsing faster and more reliable. See [Luxon documentation](https://moment.github.io/luxon/#/parsing?id=table-of-tokens) for the list of supported tokens.
19
+ *
20
+ * @snippet toYyyyMmDd($1, $2, $3)
21
+ *
22
+ * @example js
23
+ * import { toYyyyMmDd } from '@blackbyte/sugar/datetime';
24
+ * toYyyyMmDd('2025-10-15T14:30:00+02:00'); // '2025-10-15'
25
+ *
26
+ * @see https://moment.github.io/luxon
27
+ * @since 1.0.0
28
+ * @author Olivier Bossel <olivier.bossel@gmail.com> (https://blackbyte.space)
29
+ */
30
+ export type TtoYyyyMmDdSettings = {
31
+ format: string;
32
+ separator: string;
33
+ };
34
+ export default function toYyyyMmDd(date: string | Date, settings?: Partial<TtoYyyyMmDdSettings>): string | null;
@@ -0,0 +1,19 @@
1
+ import parseDate from './parseDate.js';
2
+ export default function toYyyyMmDd(date, settings) {
3
+ const finalSettings = Object.assign({ format: '', separator: '-' }, (settings !== null && settings !== void 0 ? settings : {}));
4
+ if (typeof date === 'string' && date.match(/^\d{4}-\d{2}-\d{2}$/)) {
5
+ // already in the correct format
6
+ return date;
7
+ }
8
+ // prse the passed date
9
+ const jsDate = parseDate(date, finalSettings);
10
+ if (!jsDate) {
11
+ return null;
12
+ }
13
+ const dateStr = jsDate
14
+ .toISOString()
15
+ .split('T')[0]
16
+ .replace('-', finalSettings.separator);
17
+ return dateStr;
18
+ }
19
+ //# sourceMappingURL=toYyyyMmDd.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"toYyyyMmDd.js","sourceRoot":"","sources":["../../../src/shared/datetime/toYyyyMmDd.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,gBAAgB,CAAC;AAqCvC,MAAM,CAAC,OAAO,UAAU,UAAU,CAChC,IAAmB,EACnB,QAAuC;IAEvC,MAAM,aAAa,mBACjB,MAAM,EAAE,EAAE,EACV,SAAS,EAAE,GAAG,IACX,CAAC,QAAQ,aAAR,QAAQ,cAAR,QAAQ,GAAI,EAAE,CAAC,CACpB,CAAC;IAEF,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,IAAI,CAAC,KAAK,CAAC,qBAAqB,CAAC,EAAE,CAAC;QAClE,gCAAgC;QAChC,OAAO,IAAI,CAAC;IACd,CAAC;IAED,uBAAuB;IACvB,MAAM,MAAM,GAAG,SAAS,CAAC,IAAI,EAAE,aAAa,CAAC,CAAC;IAC9C,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,OAAO,IAAI,CAAC;IACd,CAAC;IACD,MAAM,OAAO,GAAG,MAAM;SACnB,WAAW,EAAE;SACb,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;SACb,OAAO,CAAC,GAAG,EAAE,aAAa,CAAC,SAAS,CAAC,CAAC;IACzC,OAAO,OAAO,CAAC;AACjB,CAAC"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@blackbyte/sugar",
3
3
  "description": "The toolkit that you missed... like a sugar in your coffee!",
4
- "version": "1.0.0-beta.3",
4
+ "version": "1.0.0-beta.5",
5
5
  "keywords": [
6
6
  "javascript",
7
7
  "typescript",
@@ -203,6 +203,7 @@
203
203
  },
204
204
  "dependencies": {
205
205
  "@faker-js/faker": "^8.4.1",
206
+ "@types/luxon": "^3.7.1",
206
207
  "aggregation": "^1.2.7",
207
208
  "atob": "^2.1.2",
208
209
  "blueimp-md5": "^2.19.0",
@@ -238,6 +239,7 @@
238
239
  "json-cyclic": "^1.0.2",
239
240
  "lodash.clone": "^4.5.0",
240
241
  "lodash.clonedeep": "^4.5.0",
242
+ "luxon": "^3.7.2",
241
243
  "mark.js": "^8.11.1",
242
244
  "memoizee": "^0.4.15",
243
245
  "micromatch": "^4.0.5",