tool-shack 0.0.8 → 0.0.12

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 (78) hide show
  1. package/dist/browser/isTouchSupported.js +3 -1
  2. package/dist/browser/isTouchSupported.js.map +1 -1
  3. package/dist/browser/preferColorScheme.js +2 -2
  4. package/dist/browser/preferColorScheme.js.map +1 -1
  5. package/dist/browser/tabFocusListener.js.map +1 -1
  6. package/dist/dateTime/dateAsIso.js.map +1 -1
  7. package/dist/dateTime/parseDuration.js.map +1 -1
  8. package/dist/dom/addAsyncEventListener.js.map +1 -1
  9. package/dist/dom/addEventListener.js +3 -3
  10. package/dist/dom/addEventListener.js.map +1 -1
  11. package/dist/dom/createElement.d.ts +1 -1
  12. package/dist/dom/createElement.js +13 -1
  13. package/dist/dom/createElement.js.map +1 -1
  14. package/dist/dom/fireEvent.js.map +1 -1
  15. package/dist/dom/interfaces/createElement.d.ts +2 -0
  16. package/dist/schedule/runAsync.js +1 -1
  17. package/dist/schedule/runAsync.js.map +1 -1
  18. package/dist/string/byteSize.d.ts +7 -0
  19. package/dist/string/byteSize.js +8 -0
  20. package/dist/string/byteSize.js.map +1 -0
  21. package/dist/string/escapeHTML.js.map +1 -1
  22. package/dist/string/index.d.ts +3 -0
  23. package/dist/string/index.js +3 -0
  24. package/dist/string/index.js.map +1 -1
  25. package/dist/string/removeDiacritics.d.ts +7 -0
  26. package/dist/string/removeDiacritics.js +11 -0
  27. package/dist/string/removeDiacritics.js.map +1 -0
  28. package/dist/string/slugify.d.ts +8 -0
  29. package/dist/string/slugify.js +16 -0
  30. package/dist/string/slugify.js.map +1 -0
  31. package/docs/assets/search.js +1 -1
  32. package/docs/index.html +4 -4
  33. package/docs/interfaces/dateTime.IDuration.html +1 -1
  34. package/docs/interfaces/dom.IExtendingElementProps.html +1 -1
  35. package/docs/modules/browser.html +6 -6
  36. package/docs/modules/dateTime.html +2 -2
  37. package/docs/modules/dom.html +8 -8
  38. package/docs/modules/general.html +3 -3
  39. package/docs/modules/schedule.html +2 -2
  40. package/docs/modules/string.html +20 -3
  41. package/docs/modules.html +0 -0
  42. package/package.json +3 -3
  43. package/src/browser/index.ts +4 -4
  44. package/src/browser/interfaces/isTouchSupported.ts +3 -3
  45. package/src/browser/isTabFocused.ts +6 -6
  46. package/src/browser/isTouchSupported.ts +4 -5
  47. package/src/browser/preferColorScheme.ts +6 -3
  48. package/src/browser/tabFocusListener.ts +1 -1
  49. package/src/dateTime/dateAsIso.ts +9 -3
  50. package/src/dateTime/index.ts +4 -4
  51. package/src/dateTime/interfaces/index.ts +1 -1
  52. package/src/dateTime/interfaces/parseDuration.ts +7 -7
  53. package/src/dateTime/parseDuration.ts +1 -1
  54. package/src/dom/addAsyncEventListener.ts +15 -13
  55. package/src/dom/addClickOutsideListener.ts +16 -16
  56. package/src/dom/addEventListener.ts +12 -7
  57. package/src/dom/appendAfter.ts +9 -9
  58. package/src/dom/appendBefore.ts +9 -9
  59. package/src/dom/createElement.ts +55 -40
  60. package/src/dom/fireEvent.ts +2 -1
  61. package/src/dom/index.ts +9 -9
  62. package/src/dom/interfaces/createElement.ts +36 -10
  63. package/src/dom/interfaces/index.ts +1 -1
  64. package/src/general/index.ts +3 -3
  65. package/src/general/isEmpty.ts +21 -21
  66. package/src/general/isNil.ts +7 -7
  67. package/src/general/isValidJson.ts +15 -15
  68. package/src/index.ts +6 -6
  69. package/src/schedule/index.ts +2 -2
  70. package/src/schedule/runAnimation.ts +51 -51
  71. package/src/schedule/runAsync.ts +3 -5
  72. package/src/string/byteSize.ts +7 -0
  73. package/src/string/escapeHTML.ts +1 -1
  74. package/src/string/index.ts +3 -0
  75. package/src/string/removeDiacritics.ts +11 -0
  76. package/src/string/slugify.ts +17 -0
  77. package/src/string/truncate.ts +21 -21
  78. package/tsconfig.json +19 -19
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tool-shack",
3
- "version": "0.0.8",
3
+ "version": "0.0.12",
4
4
  "description": "Collection of usefull functions to ease work",
5
5
  "main": "dist",
6
6
  "author": "David Myška",
@@ -22,8 +22,8 @@
22
22
  "devDependencies": {
23
23
  "husky": "^7.0.4",
24
24
  "prettier": "^2.5.1",
25
- "pretty-quick": "^3.1.2",
25
+ "pretty-quick": "^3.1.3",
26
26
  "typedoc": "^0.22.10",
27
- "typescript": "^4.5.2"
27
+ "typescript": "^4.5.4"
28
28
  }
29
29
  }
@@ -1,4 +1,4 @@
1
- export * from './isTabFocused';
2
- export * from './isTouchSupported';
3
- export * from './preferColorScheme';
4
- export * from './tabFocusListener';
1
+ export * from './isTabFocused';
2
+ export * from './isTouchSupported';
3
+ export * from './preferColorScheme';
4
+ export * from './tabFocusListener';
@@ -1,3 +1,3 @@
1
- export interface IExtendedWindow extends Window {
2
- DocumentTouch: any;
3
- }
1
+ export interface IExtendedWindow extends Window {
2
+ DocumentTouch: any;
3
+ }
@@ -1,6 +1,6 @@
1
- /**
2
- * Check if current browser tab is in focus
3
- *
4
- * @returns Boolean indicating if current browser tab is in focus
5
- */
6
- export const isTabFocused = (): boolean => !document.hidden;
1
+ /**
2
+ * Check if current browser tab is in focus
3
+ *
4
+ * @returns Boolean indicating if current browser tab is in focus
5
+ */
6
+ export const isTabFocused = (): boolean => !document.hidden;
@@ -5,8 +5,7 @@ import { IExtendedWindow } from './interfaces/isTouchSupported';
5
5
  *
6
6
  * @returns Boolean indicating if user's browser support touch events
7
7
  */
8
- export const isTouchSupported = (): boolean => (
9
- 'ontouchstart' in window || (
10
- (window as unknown as IExtendedWindow).DocumentTouch && document instanceof (window as unknown as IExtendedWindow).DocumentTouch
11
- )
12
- );
8
+ export const isTouchSupported = (): boolean =>
9
+ 'ontouchstart' in window ||
10
+ ((window as unknown as IExtendedWindow).DocumentTouch &&
11
+ document instanceof (window as unknown as IExtendedWindow).DocumentTouch);
@@ -3,18 +3,21 @@
3
3
  *
4
4
  * @returns Boolean indicating if user prefers light color scheme
5
5
  */
6
- export const preferLightColorScheme = (): boolean => !!(window.matchMedia('(prefers-color-scheme: light)').matches);
6
+ export const preferLightColorScheme = (): boolean =>
7
+ !!window.matchMedia('(prefers-color-scheme: light)').matches;
7
8
 
8
9
  /**
9
10
  * Check if user prefers dark color scheme
10
11
  *
11
12
  * @returns Boolean indicating if user prefers dark color scheme
12
13
  */
13
- export const preferDarkColorScheme = (): boolean => !!(window.matchMedia('(prefers-color-scheme: dark)').matches);
14
+ export const preferDarkColorScheme = (): boolean =>
15
+ !!window.matchMedia('(prefers-color-scheme: dark)').matches;
14
16
 
15
17
  /**
16
18
  * Check what color scheme (light or dark) is prefered by user
17
19
  *
18
20
  * @returns String indicating prefered light color scheme ('light') or dark color scheme ('dark')
19
21
  */
20
- export const preferColorScheme = (): 'light'|'dark' => preferLightColorScheme() ? 'light' : 'dark';
22
+ export const preferColorScheme = (): 'light' | 'dark' =>
23
+ preferLightColorScheme() ? 'light' : 'dark';
@@ -15,4 +15,4 @@ export const tabFocusListener = (focusCallback?: () => void, blurCallback?: () =
15
15
  blurCallback?.call(this);
16
16
  }
17
17
  });
18
- }
18
+ };
@@ -8,9 +8,15 @@ export const dateAsIso = (date: Date) => {
8
8
  const timezoneOffset = date.getTimezoneOffset();
9
9
 
10
10
  let isoFormat = '';
11
- isoFormat += `${date.getFullYear()}-${padNumber(date.getMonth() + 1)}-${padNumber(date.getDate())}`;
12
- isoFormat += `T${padNumber(date.getHours())}:${padNumber(date.getMinutes())}:${padNumber(date.getSeconds())}`;
13
- isoFormat += `${timezoneOffset <= 0 ? '+' : '-'}${padNumber(Math.floor(Math.abs(timezoneOffset) / 60))}:${padNumber(Math.abs(timezoneOffset) % 60)}`;
11
+ isoFormat += `${date.getFullYear()}-${padNumber(date.getMonth() + 1)}-${padNumber(
12
+ date.getDate(),
13
+ )}`;
14
+ isoFormat += `T${padNumber(date.getHours())}:${padNumber(date.getMinutes())}:${padNumber(
15
+ date.getSeconds(),
16
+ )}`;
17
+ isoFormat += `${timezoneOffset <= 0 ? '+' : '-'}${padNumber(
18
+ Math.floor(Math.abs(timezoneOffset) / 60),
19
+ )}:${padNumber(Math.abs(timezoneOffset) % 60)}`;
14
20
 
15
21
  return isoFormat;
16
22
  };
@@ -1,4 +1,4 @@
1
- export * from './interfaces';
2
-
3
- export * from './dateAsIso';
4
- export * from './parseDuration';
1
+ export * from './interfaces';
2
+
3
+ export * from './dateAsIso';
4
+ export * from './parseDuration';
@@ -1 +1 @@
1
- export * from './parseDuration';
1
+ export * from './parseDuration';
@@ -1,7 +1,7 @@
1
- export interface IDuration {
2
- days: number;
3
- hours: number;
4
- minutes: number;
5
- seconds: number;
6
- milliseconds: number;
7
- }
1
+ export interface IDuration {
2
+ days: number;
3
+ hours: number;
4
+ minutes: number;
5
+ seconds: number;
6
+ milliseconds: number;
7
+ }
@@ -16,4 +16,4 @@ export const parseDuration = (durationInMs: number): IDuration => {
16
16
  seconds: Math.floor(durationInMs / 1000) % 60,
17
17
  milliseconds: Math.floor(durationInMs) % 1000,
18
18
  };
19
- }
19
+ };
@@ -9,24 +9,26 @@
9
9
  export const addAsyncEventListener = (
10
10
  elementSelector: string,
11
11
  listeners: Record<string, EventListener | EventListener[]>,
12
- acceptBubbling = true
12
+ acceptBubbling = true,
13
13
  ): void => {
14
14
  for (let eventName in listeners) {
15
15
  const functionList = (
16
16
  listeners[eventName] instanceof Array ? listeners[eventName] : [listeners[eventName]]
17
17
  ) as EventListener[];
18
18
 
19
- functionList.forEach((fn: EventListener) => document.addEventListener(eventName, (event: Event) => {
20
- const target = event.target as HTMLElement;
21
- if (!target) {
22
- return;
23
- }
19
+ functionList.forEach((fn: EventListener) =>
20
+ document.addEventListener(eventName, (event: Event) => {
21
+ const target = event.target as HTMLElement;
22
+ if (!target) {
23
+ return;
24
+ }
24
25
 
25
- if (!acceptBubbling && target.matches(elementSelector)) {
26
- fn.call(this, event);
27
- } else if (acceptBubbling && target.closest(elementSelector)) {
28
- fn.call(this, event);
29
- }
30
- }));
26
+ if (!acceptBubbling && target.matches(elementSelector)) {
27
+ fn.call(this, event);
28
+ } else if (acceptBubbling && target.closest(elementSelector)) {
29
+ fn.call(this, event);
30
+ }
31
+ }),
32
+ );
31
33
  }
32
- }
34
+ };
@@ -1,16 +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: HTMLElement, fn: () => any): void => {
9
- document.addEventListener('click', (event: Event) => {
10
- const target = event.target as HTMLElement;
11
-
12
- if (!!target && !element.contains(target)) {
13
- fn.call(this);
14
- }
15
- });
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: HTMLElement, fn: () => any): void => {
9
+ document.addEventListener('click', (event: Event) => {
10
+ const target = event.target as HTMLElement;
11
+
12
+ if (!!target && !element.contains(target)) {
13
+ fn.call(this);
14
+ }
15
+ });
16
+ };
@@ -7,13 +7,16 @@
7
7
  */
8
8
  export const addEventListener = (
9
9
  element: HTMLElement | HTMLElement[] | NodeListOf<HTMLElement> | HTMLCollectionOf<HTMLElement>,
10
- listeners: Record<string, EventListenerOrEventListenerObject | EventListenerOrEventListenerObject[]>
10
+ listeners: Record<
11
+ string,
12
+ EventListenerOrEventListenerObject | EventListenerOrEventListenerObject[]
13
+ >,
11
14
  ): void => {
12
15
  const elementList = (
13
- element instanceof Array || element instanceof HTMLCollection || element instanceof NodeList ?
14
- Array.from(element) :
15
- [element]
16
- ) as HTMLElement[];
16
+ element instanceof Array || element instanceof HTMLCollection || element instanceof NodeList
17
+ ? Array.from(element)
18
+ : [element]
19
+ ) as HTMLElement[];
17
20
 
18
21
  elementList.forEach((element: HTMLElement) => {
19
22
  for (let eventName in listeners) {
@@ -21,7 +24,9 @@ export const addEventListener = (
21
24
  listeners[eventName] instanceof Array ? listeners[eventName] : [listeners[eventName]]
22
25
  ) as EventListenerOrEventListenerObject[];
23
26
 
24
- functionList.forEach((fn: EventListenerOrEventListenerObject) => element.addEventListener(eventName, fn));
27
+ functionList.forEach((fn: EventListenerOrEventListenerObject) =>
28
+ element.addEventListener(eventName, fn),
29
+ );
25
30
  }
26
31
  });
27
- }
32
+ };
@@ -1,9 +1,9 @@
1
- /**
2
- * Append given node after reference node in the DOM
3
- *
4
- * @param newNode New node element to be appended
5
- * @param referenceNode Reference node element
6
- * @returns Result of the action
7
- */
8
- export const appendAfter = (newNode: HTMLElement, referenceNode: HTMLElement): boolean =>
9
- !!referenceNode.parentElement?.insertBefore(newNode, referenceNode.nextSibling);
1
+ /**
2
+ * Append given node after reference node in the DOM
3
+ *
4
+ * @param newNode New node element to be appended
5
+ * @param referenceNode Reference node element
6
+ * @returns Result of the action
7
+ */
8
+ export const appendAfter = (newNode: HTMLElement, referenceNode: HTMLElement): boolean =>
9
+ !!referenceNode.parentElement?.insertBefore(newNode, referenceNode.nextSibling);
@@ -1,9 +1,9 @@
1
- /**
2
- * Append given node before reference node in the DOM
3
- *
4
- * @param newNode New node element to be appended
5
- * @param referenceNode Reference node element
6
- * @returns Result of the action
7
- */
8
- export const appendBefore = (newNode: HTMLElement, referenceNode: HTMLElement): boolean =>
9
- !!referenceNode.parentElement?.insertBefore(newNode, referenceNode);
1
+ /**
2
+ * Append given node before reference node in the DOM
3
+ *
4
+ * @param newNode New node element to be appended
5
+ * @param referenceNode Reference node element
6
+ * @returns Result of the action
7
+ */
8
+ export const appendBefore = (newNode: HTMLElement, referenceNode: HTMLElement): boolean =>
9
+ !!referenceNode.parentElement?.insertBefore(newNode, referenceNode);
@@ -1,40 +1,55 @@
1
- import { IExtendingElementProps } from './interfaces/createElement';
2
-
3
- /**
4
- * Method for creating Node element and assigning multiple parameters, event listeners & children in one method call
5
- *
6
- * @param tagName Node tag name
7
- * @param props List of attributes, event listeners or/and children to assign to the newly created element
8
- * @returns Resulting Node element
9
- */
10
- export const createElement = <T = HTMLElement> (tagName: string, props?: Partial<Omit<T, 'children'>> & IExtendingElementProps): T => {
11
- const element: HTMLElement = document.createElement(tagName);
12
-
13
- if (props) {
14
- for (let key in props) {
15
- const value = (props as any)[key];
16
-
17
- if (key === 'role') {
18
- element.setAttribute(key, value);
19
- } else if (key === 'aria') {
20
- for (let ariaKey in props.aria!) {
21
- element.setAttribute(`aria-${ariaKey}`, value[ariaKey]);
22
- }
23
- } else if (key === 'children') {
24
- props.children!.forEach((child: HTMLElement) => element.appendChild(child));
25
- } else if (key === 'listeners') {
26
- for (let eventName in props.listeners!) {
27
- const functionList = (
28
- props.listeners![eventName] instanceof Array ? props.listeners![eventName] : [props.listeners![eventName]]
29
- ) as EventListenerOrEventListenerObject[];
30
-
31
- functionList.forEach((fn: EventListenerOrEventListenerObject) => element.addEventListener(eventName, fn));
32
- }
33
- } else {
34
- (element as any)[key] = value;
35
- }
36
- }
37
- }
38
-
39
- return element as unknown as T;
40
- };
1
+ import { IExtendingElementProps } from './interfaces/createElement';
2
+
3
+ /**
4
+ * Method for creating Node element and assigning multiple parameters, event listeners & children in one method call
5
+ *
6
+ * @param tagName Node tag name
7
+ * @param props List of attributes, event listeners or/and children to assign to the newly created element
8
+ * @returns Resulting Node element
9
+ */
10
+ export const createElement = <T = HTMLElement>(
11
+ tagName: string,
12
+ props?: Partial<Omit<T, 'children' | 'dataset' | 'style'>> & IExtendingElementProps,
13
+ ): T => {
14
+ const element: HTMLElement = document.createElement(tagName);
15
+
16
+ if (props) {
17
+ for (let key in props) {
18
+ const value = (props as any)[key];
19
+
20
+ if (key === 'role') {
21
+ element.setAttribute(key, value);
22
+ } else if (key === 'aria') {
23
+ for (let ariaKey in props.aria!) {
24
+ element.setAttribute(`aria-${ariaKey}`, value[ariaKey]);
25
+ }
26
+ } else if (key === 'style') {
27
+ for (let styleKey in props.style!) {
28
+ (element.style as any)[styleKey] = value[styleKey];
29
+ }
30
+ } else if (key === 'children') {
31
+ props.children!.forEach((child: HTMLElement) => element.appendChild(child));
32
+ } else if (key === 'listeners') {
33
+ for (let eventName in props.listeners!) {
34
+ const functionList = (
35
+ props.listeners![eventName] instanceof Array
36
+ ? props.listeners![eventName]
37
+ : [props.listeners![eventName]]
38
+ ) as EventListenerOrEventListenerObject[];
39
+
40
+ functionList.forEach((fn: EventListenerOrEventListenerObject) =>
41
+ element.addEventListener(eventName, fn),
42
+ );
43
+ }
44
+ } else if (key === 'dataset') {
45
+ for (let datasetKey in props.dataset) {
46
+ element.dataset[datasetKey] = props.dataset[datasetKey];
47
+ }
48
+ } else {
49
+ (element as any)[key] = value;
50
+ }
51
+ }
52
+ }
53
+
54
+ return element as unknown as T;
55
+ };
@@ -5,4 +5,5 @@
5
5
  * @param eventType Type name of event that should be fired
6
6
  * @returns Result of the action
7
7
  */
8
- export const fireEvent = (element: HTMLElement, eventType: string): boolean => element.dispatchEvent(new Event(eventType));
8
+ export const fireEvent = (element: HTMLElement, eventType: string): boolean =>
9
+ element.dispatchEvent(new Event(eventType));
package/src/dom/index.ts CHANGED
@@ -1,9 +1,9 @@
1
- export * from './interfaces';
2
-
3
- export * from './addAsyncEventListener';
4
- export * from './addClickOutsideListener';
5
- export * from './addEventListener';
6
- export * from './appendAfter';
7
- export * from './appendBefore';
8
- export * from './createElement';
9
- export * from './fireEvent';
1
+ export * from './interfaces';
2
+
3
+ export * from './addAsyncEventListener';
4
+ export * from './addClickOutsideListener';
5
+ export * from './addEventListener';
6
+ export * from './appendAfter';
7
+ export * from './appendBefore';
8
+ export * from './createElement';
9
+ export * from './fireEvent';
@@ -1,10 +1,36 @@
1
- export type TAriaLabelKey = 'atomic' | 'busy' | 'controls' | 'current' | 'describedby' | 'details' | 'disables' |
2
- 'dropeffect' | 'errormessage' | 'expanded' | 'flowto' | 'grabbed' | 'haspopup' | 'hidden' | 'invalid' |
3
- 'keyshortcuts' | 'label' | 'labelledby' | 'live' | 'modal' | 'owns' | 'relevant' | 'roledescription';
4
-
5
- export interface IExtendingElementProps {
6
- children?: HTMLElement[];
7
- listeners?: Record<string, EventListenerOrEventListenerObject | EventListenerOrEventListenerObject[]>;
8
- role?: string;
9
- aria?: Partial<Record<TAriaLabelKey, string>>;
10
- }
1
+ export type TAriaLabelKey =
2
+ | 'atomic'
3
+ | 'busy'
4
+ | 'controls'
5
+ | 'current'
6
+ | 'describedby'
7
+ | 'details'
8
+ | 'disables'
9
+ | 'dropeffect'
10
+ | 'errormessage'
11
+ | 'expanded'
12
+ | 'flowto'
13
+ | 'grabbed'
14
+ | 'haspopup'
15
+ | 'hidden'
16
+ | 'invalid'
17
+ | 'keyshortcuts'
18
+ | 'label'
19
+ | 'labelledby'
20
+ | 'live'
21
+ | 'modal'
22
+ | 'owns'
23
+ | 'relevant'
24
+ | 'roledescription';
25
+
26
+ export interface IExtendingElementProps {
27
+ children?: HTMLElement[];
28
+ listeners?: Record<
29
+ string,
30
+ EventListenerOrEventListenerObject | EventListenerOrEventListenerObject[]
31
+ >;
32
+ role?: string;
33
+ aria?: Partial<Record<TAriaLabelKey, string>>;
34
+ dataset?: Record<string, string>;
35
+ style?: Record<string, string | number>;
36
+ }
@@ -1 +1 @@
1
- export * from './createElement';
1
+ export * from './createElement';
@@ -1,3 +1,3 @@
1
- export * from './isEmpty';
2
- export * from './isNil';
3
- export * from './isValidJson';
1
+ export * from './isEmpty';
2
+ export * from './isNil';
3
+ export * from './isValidJson';
@@ -1,21 +1,21 @@
1
- import { isNil } from './isNil';
2
-
3
- /**
4
- * Check if given value is empty
5
- *
6
- * @param value Value to be checked
7
- * @returns Boolean indicating if given value is empty
8
- */
9
- export const isEmpty = (value: any): boolean => {
10
- if (value instanceof Function) {
11
- return false;
12
- }
13
-
14
- return (
15
- isNil(value) ||
16
- (value instanceof Object &&
17
- !Object.keys(value).length &&
18
- Object.getPrototypeOf(value) === Object.prototype) ||
19
- !value.valueOf().toString().length
20
- );
21
- };
1
+ import { isNil } from './isNil';
2
+
3
+ /**
4
+ * Check if given value is empty
5
+ *
6
+ * @param value Value to be checked
7
+ * @returns Boolean indicating if given value is empty
8
+ */
9
+ export const isEmpty = (value: any): boolean => {
10
+ if (value instanceof Function) {
11
+ return false;
12
+ }
13
+
14
+ return (
15
+ isNil(value) ||
16
+ (value instanceof Object &&
17
+ !Object.keys(value).length &&
18
+ Object.getPrototypeOf(value) === Object.prototype) ||
19
+ !value.valueOf().toString().length
20
+ );
21
+ };
@@ -1,7 +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 const isNil = (value: any): boolean => value === undefined || value === null;
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: any): boolean => value === undefined || value === null;
@@ -1,15 +1,15 @@
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: string): boolean => {
8
- try {
9
- JSON.parse(value);
10
- } catch (error: any) {
11
- return false;
12
- }
13
-
14
- return true;
15
- };
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: string): boolean => {
8
+ try {
9
+ JSON.parse(value);
10
+ } catch (error: any) {
11
+ return false;
12
+ }
13
+
14
+ return true;
15
+ };
package/src/index.ts CHANGED
@@ -1,6 +1,6 @@
1
- export * from './browser';
2
- export * from './dateTime';
3
- export * from './dom';
4
- export * from './general';
5
- export * from './schedule';
6
- export * from './string';
1
+ export * from './browser';
2
+ export * from './dateTime';
3
+ export * from './dom';
4
+ export * from './general';
5
+ export * from './schedule';
6
+ export * from './string';
@@ -1,2 +1,2 @@
1
- export * from './runAnimation';
2
- export * from './runAsync';
1
+ export * from './runAnimation';
2
+ export * from './runAsync';