tool-shack 0.0.7 → 0.0.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 (61) hide show
  1. package/dist/dom/addClickOutsideListener.d.ts +8 -0
  2. package/dist/dom/addClickOutsideListener.js +16 -0
  3. package/dist/dom/addClickOutsideListener.js.map +1 -0
  4. package/dist/dom/index.d.ts +1 -0
  5. package/dist/dom/index.js +1 -0
  6. package/dist/dom/index.js.map +1 -1
  7. package/dist/general/index.d.ts +3 -0
  8. package/dist/general/index.js +4 -0
  9. package/dist/general/index.js.map +1 -0
  10. package/dist/general/isEmpty.d.ts +7 -0
  11. package/dist/general/isEmpty.js +18 -0
  12. package/dist/general/isEmpty.js.map +1 -0
  13. package/dist/general/isNil.d.ts +7 -0
  14. package/dist/general/isNil.js +8 -0
  15. package/dist/general/isNil.js.map +1 -0
  16. package/dist/general/isValidJson.d.ts +7 -0
  17. package/dist/general/isValidJson.js +16 -0
  18. package/dist/general/isValidJson.js.map +1 -0
  19. package/dist/index.d.ts +1 -0
  20. package/dist/index.js +1 -0
  21. package/dist/index.js.map +1 -1
  22. package/dist/schedule/index.d.ts +1 -0
  23. package/dist/schedule/index.js +1 -0
  24. package/dist/schedule/index.js.map +1 -1
  25. package/dist/schedule/runAnimation.d.ts +11 -0
  26. package/dist/schedule/runAnimation.js +40 -0
  27. package/dist/schedule/runAnimation.js.map +1 -0
  28. package/dist/string/index.d.ts +1 -0
  29. package/dist/string/index.js +1 -0
  30. package/dist/string/index.js.map +1 -1
  31. package/dist/string/truncate.d.ts +9 -0
  32. package/dist/string/truncate.js +17 -0
  33. package/dist/string/truncate.js.map +1 -0
  34. package/docs/.nojekyll +0 -0
  35. package/docs/assets/highlight.css +22 -22
  36. package/docs/assets/icons.css +1043 -1043
  37. package/docs/assets/main.js +52 -52
  38. package/docs/assets/search.js +1 -1
  39. package/docs/assets/style.css +1388 -1388
  40. package/docs/index.html +1 -1
  41. package/docs/interfaces/dateTime.IDuration.html +1 -1
  42. package/docs/interfaces/dom.IExtendingElementProps.html +1 -1
  43. package/docs/modules/browser.html +7 -7
  44. package/docs/modules/dateTime.html +3 -3
  45. package/docs/modules/dom.html +14 -7
  46. package/docs/modules/general.html +16 -0
  47. package/docs/modules/schedule.html +9 -2
  48. package/docs/modules/string.html +11 -2
  49. package/docs/modules.html +1 -1
  50. package/package.json +1 -1
  51. package/src/dom/addClickOutsideListener.ts +16 -0
  52. package/src/dom/index.ts +1 -0
  53. package/src/general/index.ts +3 -0
  54. package/src/general/isEmpty.ts +21 -0
  55. package/src/general/isNil.ts +7 -0
  56. package/src/general/isValidJson.ts +15 -0
  57. package/src/index.ts +3 -2
  58. package/src/schedule/index.ts +1 -0
  59. package/src/schedule/runAnimation.ts +51 -0
  60. package/src/string/index.ts +1 -0
  61. package/src/string/truncate.ts +21 -0
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Add event listener to listen to clicks outside of given element
3
+ *
4
+ * @param element Node element outside which to listen to clicks
5
+ * @param fn Function to trigger when clicked outside
6
+ * @returns void
7
+ */
8
+ export declare const addClickOutsideListener: (element: HTMLElement, fn: () => any) => void;
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Add event listener to listen to clicks outside of given element
3
+ *
4
+ * @param element Node element outside which to listen to clicks
5
+ * @param fn Function to trigger when clicked outside
6
+ * @returns void
7
+ */
8
+ export const addClickOutsideListener = (element, fn) => {
9
+ document.addEventListener('click', (event) => {
10
+ const target = event.target;
11
+ if (!!target && !element.contains(target)) {
12
+ fn.call(this);
13
+ }
14
+ });
15
+ };
16
+ //# sourceMappingURL=addClickOutsideListener.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"addClickOutsideListener.js","sourceRoot":"","sources":["../../src/dom/addClickOutsideListener.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAG,CAAC,OAAoB,EAAE,EAAa,EAAQ,EAAE;IACnF,QAAQ,CAAC,gBAAgB,CAAC,OAAO,EAAE,CAAC,KAAY,EAAE,EAAE;QAClD,MAAM,MAAM,GAAG,KAAK,CAAC,MAAqB,CAAC;QAE3C,IAAI,CAAC,CAAC,MAAM,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE;YACzC,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;SACf;IACH,CAAC,CAAC,CAAC;AACL,CAAC,CAAC"}
@@ -1,5 +1,6 @@
1
1
  export * from './interfaces';
2
2
  export * from './addAsyncEventListener';
3
+ export * from './addClickOutsideListener';
3
4
  export * from './addEventListener';
4
5
  export * from './appendAfter';
5
6
  export * from './appendBefore';
package/dist/dom/index.js CHANGED
@@ -1,5 +1,6 @@
1
1
  export * from './interfaces';
2
2
  export * from './addAsyncEventListener';
3
+ export * from './addClickOutsideListener';
3
4
  export * from './addEventListener';
4
5
  export * from './appendAfter';
5
6
  export * from './appendBefore';
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/dom/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAE7B,cAAc,yBAAyB,CAAC;AACxC,cAAc,oBAAoB,CAAC;AACnC,cAAc,eAAe,CAAC;AAC9B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,iBAAiB,CAAC;AAChC,cAAc,aAAa,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/dom/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAE7B,cAAc,yBAAyB,CAAC;AACxC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,oBAAoB,CAAC;AACnC,cAAc,eAAe,CAAC;AAC9B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,iBAAiB,CAAC;AAChC,cAAc,aAAa,CAAC"}
@@ -0,0 +1,3 @@
1
+ export * from './isEmpty';
2
+ export * from './isNil';
3
+ export * from './isValidJson';
@@ -0,0 +1,4 @@
1
+ export * from './isEmpty';
2
+ export * from './isNil';
3
+ export * from './isValidJson';
4
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/general/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,SAAS,CAAC;AACxB,cAAc,eAAe,CAAC"}
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Check if given value is empty
3
+ *
4
+ * @param value Value to be checked
5
+ * @returns Boolean indicating if given value is empty
6
+ */
7
+ export declare const isEmpty: (value: any) => boolean;
@@ -0,0 +1,18 @@
1
+ import { isNil } from './isNil';
2
+ /**
3
+ * Check if given value is empty
4
+ *
5
+ * @param value Value to be checked
6
+ * @returns Boolean indicating if given value is empty
7
+ */
8
+ export const isEmpty = (value) => {
9
+ if (value instanceof Function) {
10
+ return false;
11
+ }
12
+ return (isNil(value) ||
13
+ (value instanceof Object &&
14
+ !Object.keys(value).length &&
15
+ Object.getPrototypeOf(value) === Object.prototype) ||
16
+ !value.valueOf().toString().length);
17
+ };
18
+ //# sourceMappingURL=isEmpty.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"isEmpty.js","sourceRoot":"","sources":["../../src/general/isEmpty.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAEhC;;;;;GAKG;AACH,MAAM,CAAC,MAAM,OAAO,GAAG,CAAC,KAAU,EAAW,EAAE;IAC7C,IAAI,KAAK,YAAY,QAAQ,EAAE;QAC7B,OAAO,KAAK,CAAC;KACd;IAED,OAAO,CACL,KAAK,CAAC,KAAK,CAAC;QACZ,CAAC,KAAK,YAAY,MAAM;YACtB,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,MAAM;YAC1B,MAAM,CAAC,cAAc,CAAC,KAAK,CAAC,KAAK,MAAM,CAAC,SAAS,CAAC;QACpD,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC,QAAQ,EAAE,CAAC,MAAM,CACnC,CAAC;AACJ,CAAC,CAAC"}
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Check if value is equal to null or undefined
3
+ *
4
+ * @param value Value to be checked
5
+ * @returns Boolean indicating if value is equal to null or undefined
6
+ */
7
+ export declare const isNil: (value: any) => boolean;
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Check if value is equal to null or undefined
3
+ *
4
+ * @param value Value to be checked
5
+ * @returns Boolean indicating if value is equal to null or undefined
6
+ */
7
+ export const isNil = (value) => value === undefined || value === null;
8
+ //# sourceMappingURL=isNil.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"isNil.js","sourceRoot":"","sources":["../../src/general/isNil.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,CAAC,MAAM,KAAK,GAAG,CAAC,KAAU,EAAW,EAAE,CAAC,KAAK,KAAK,SAAS,IAAI,KAAK,KAAK,IAAI,CAAC"}
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Check if string is valid JSON
3
+ *
4
+ * @param value String value to be checked
5
+ * @returns Boolean indicating if string value is a valid JSON
6
+ */
7
+ export declare const isValidJson: (value: string) => boolean;
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Check if string is valid JSON
3
+ *
4
+ * @param value String value to be checked
5
+ * @returns Boolean indicating if string value is a valid JSON
6
+ */
7
+ export const isValidJson = (value) => {
8
+ try {
9
+ JSON.parse(value);
10
+ }
11
+ catch (error) {
12
+ return false;
13
+ }
14
+ return true;
15
+ };
16
+ //# sourceMappingURL=isValidJson.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"isValidJson.js","sourceRoot":"","sources":["../../src/general/isValidJson.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,KAAa,EAAW,EAAE;IACpD,IAAI;QACF,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;KACnB;IAAC,OAAO,KAAU,EAAE;QACnB,OAAO,KAAK,CAAC;KACd;IAED,OAAO,IAAI,CAAC;AACd,CAAC,CAAC"}
package/dist/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  export * from './browser';
2
2
  export * from './dateTime';
3
3
  export * from './dom';
4
+ export * from './general';
4
5
  export * from './schedule';
5
6
  export * from './string';
package/dist/index.js CHANGED
@@ -1,6 +1,7 @@
1
1
  export * from './browser';
2
2
  export * from './dateTime';
3
3
  export * from './dom';
4
+ export * from './general';
4
5
  export * from './schedule';
5
6
  export * from './string';
6
7
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC;AAC3B,cAAc,OAAO,CAAC;AACtB,cAAc,YAAY,CAAA;AAC1B,cAAc,UAAU,CAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC;AAC3B,cAAc,OAAO,CAAC;AACtB,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC;AAC3B,cAAc,UAAU,CAAC"}
@@ -1 +1,2 @@
1
+ export * from './runAnimation';
1
2
  export * from './runAsync';
@@ -1,2 +1,3 @@
1
+ export * from './runAnimation';
1
2
  export * from './runAsync';
2
3
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/schedule/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/schedule/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,YAAY,CAAC"}
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Run function as animation using requestAnimationFrame
3
+ *
4
+ * @param fn Function to be run as animation
5
+ * @param autoStart If animation should start right away or just return callbacks
6
+ * @returns Callbacks to start animation (startAnimation) and stop animation (stopAnimation)
7
+ */
8
+ export declare const runAnimation: (fn: () => any, autoStart?: boolean) => {
9
+ startAnimation: () => void;
10
+ stopAnimation: () => void;
11
+ };
@@ -0,0 +1,40 @@
1
+ /**
2
+ * Run function as animation using requestAnimationFrame
3
+ *
4
+ * @param fn Function to be run as animation
5
+ * @param autoStart If animation should start right away or just return callbacks
6
+ * @returns Callbacks to start animation (startAnimation) and stop animation (stopAnimation)
7
+ */
8
+ export const runAnimation = (fn, autoStart = true) => {
9
+ let isRunning = false;
10
+ let requestedAnimationFrame = null;
11
+ const runAnimation = () => {
12
+ requestedAnimationFrame = requestAnimationFrame(() => {
13
+ fn.call(this);
14
+ if (isRunning) {
15
+ runAnimation();
16
+ }
17
+ });
18
+ };
19
+ const startAnimation = () => {
20
+ if (isRunning) {
21
+ return;
22
+ }
23
+ isRunning = true;
24
+ runAnimation();
25
+ };
26
+ const stopAnimation = () => {
27
+ if (!isRunning) {
28
+ return;
29
+ }
30
+ isRunning = false;
31
+ if (!!requestedAnimationFrame) {
32
+ cancelAnimationFrame(requestedAnimationFrame);
33
+ }
34
+ };
35
+ if (autoStart) {
36
+ startAnimation();
37
+ }
38
+ return { startAnimation, stopAnimation };
39
+ };
40
+ //# sourceMappingURL=runAnimation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runAnimation.js","sourceRoot":"","sources":["../../src/schedule/runAnimation.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,CAC1B,EAAa,EACb,SAAS,GAAG,IAAI,EAC2C,EAAE;IAC7D,IAAI,SAAS,GAAG,KAAK,CAAC;IACtB,IAAI,uBAAuB,GAAkB,IAAI,CAAC;IAElD,MAAM,YAAY,GAAG,GAAS,EAAE;QAC9B,uBAAuB,GAAG,qBAAqB,CAAC,GAAS,EAAE;YACzD,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YAEd,IAAI,SAAS,EAAE;gBACb,YAAY,EAAE,CAAC;aAChB;QACH,CAAC,CAAC,CAAC;IACL,CAAC,CAAC;IAEF,MAAM,cAAc,GAAG,GAAS,EAAE;QAChC,IAAI,SAAS,EAAE;YACb,OAAO;SACR;QAED,SAAS,GAAG,IAAI,CAAC;QACjB,YAAY,EAAE,CAAC;IACjB,CAAC,CAAC;IAEF,MAAM,aAAa,GAAG,GAAS,EAAE;QAC/B,IAAI,CAAC,SAAS,EAAE;YACd,OAAO;SACR;QAED,SAAS,GAAG,KAAK,CAAC;QAElB,IAAI,CAAC,CAAC,uBAAuB,EAAE;YAC7B,oBAAoB,CAAC,uBAAuB,CAAC,CAAC;SAC/C;IACH,CAAC,CAAC;IAEF,IAAI,SAAS,EAAE;QACb,cAAc,EAAE,CAAC;KAClB;IAED,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,CAAC;AAC3C,CAAC,CAAC"}
@@ -1 +1,2 @@
1
1
  export * from './escapeHTML';
2
+ export * from './truncate';
@@ -1,2 +1,3 @@
1
1
  export * from './escapeHTML';
2
+ export * from './truncate';
2
3
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/string/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/string/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,YAAY,CAAC"}
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Truncate string to maximum given length if needed and append string at the end (by default "...")
3
+ *
4
+ * @param value String value to be truncated
5
+ * @param maxLength Maximum allowed length
6
+ * @param appendedString String to append at the end, be default "..."
7
+ * @returns Truncated value if needed otherwise original value
8
+ */
9
+ export declare const truncate: (value: string, maxLength: number, appendedString?: string) => string;
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Truncate string to maximum given length if needed and append string at the end (by default "...")
3
+ *
4
+ * @param value String value to be truncated
5
+ * @param maxLength Maximum allowed length
6
+ * @param appendedString String to append at the end, be default "..."
7
+ * @returns Truncated value if needed otherwise original value
8
+ */
9
+ export const truncate = (value, maxLength, appendedString = '...') => {
10
+ if (maxLength < appendedString.length) {
11
+ return appendedString.slice(0, maxLength);
12
+ }
13
+ return value.length > maxLength
14
+ ? value.slice(0, maxLength - appendedString.length) + appendedString
15
+ : value;
16
+ };
17
+ //# sourceMappingURL=truncate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"truncate.js","sourceRoot":"","sources":["../../src/string/truncate.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG,CACtB,KAAa,EACb,SAAiB,EACjB,iBAAyB,KAAK,EACtB,EAAE;IACV,IAAI,SAAS,GAAG,cAAc,CAAC,MAAM,EAAE;QACrC,OAAO,cAAc,CAAC,KAAK,CAAC,CAAC,EAAE,SAAS,CAAC,CAAC;KAC3C;IAED,OAAO,KAAK,CAAC,MAAM,GAAG,SAAS;QAC7B,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,SAAS,GAAG,cAAc,CAAC,MAAM,CAAC,GAAG,cAAc;QACpE,CAAC,CAAC,KAAK,CAAC;AACZ,CAAC,CAAC"}
package/docs/.nojekyll CHANGED
File without changes
@@ -1,22 +1,22 @@
1
- :root {
2
- --light-code-background: #FFFFFF;
3
- --dark-code-background: #1E1E1E;
4
- }
5
-
6
- @media (prefers-color-scheme: light) { :root {
7
- --code-background: var(--light-code-background);
8
- } }
9
-
10
- @media (prefers-color-scheme: dark) { :root {
11
- --code-background: var(--dark-code-background);
12
- } }
13
-
14
- body.light {
15
- --code-background: var(--light-code-background);
16
- }
17
-
18
- body.dark {
19
- --code-background: var(--dark-code-background);
20
- }
21
-
22
- pre, code { background: var(--code-background); }
1
+ :root {
2
+ --light-code-background: #FFFFFF;
3
+ --dark-code-background: #1E1E1E;
4
+ }
5
+
6
+ @media (prefers-color-scheme: light) { :root {
7
+ --code-background: var(--light-code-background);
8
+ } }
9
+
10
+ @media (prefers-color-scheme: dark) { :root {
11
+ --code-background: var(--dark-code-background);
12
+ } }
13
+
14
+ body.light {
15
+ --code-background: var(--light-code-background);
16
+ }
17
+
18
+ body.dark {
19
+ --code-background: var(--dark-code-background);
20
+ }
21
+
22
+ pre, code { background: var(--code-background); }