@onereach/ui-components-common 19.3.0-beta.5083.0
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.
- package/dist/assets/index.d.ts +2 -0
- package/dist/assets.js +5 -0
- package/dist/directives/dropdown-close.d.ts +4 -0
- package/dist/directives/dropdown-open.d.ts +4 -0
- package/dist/directives/index.d.ts +2 -0
- package/dist/directives.js +5 -0
- package/dist/dom-CwV-xS38.js +95 -0
- package/dist/dropdown-open-k6cFnrqA.js +20 -0
- package/dist/extractCssVarName-IHa2pGlF.js +160 -0
- package/dist/helpers/getItemByValue.d.ts +2 -0
- package/dist/helpers/getItemsByValue.d.ts +2 -0
- package/dist/helpers/index.d.ts +3 -0
- package/dist/helpers/searchItemsByLabel.d.ts +2 -0
- package/dist/helpers.js +6 -0
- package/dist/hooks/index.d.ts +15 -0
- package/dist/hooks/useControlAttributes.d.ts +7 -0
- package/dist/hooks/useDateFormat.d.ts +4 -0
- package/dist/hooks/useDateMask.d.ts +4 -0
- package/dist/hooks/useElevation.d.ts +3 -0
- package/dist/hooks/useIdAttribute.d.ts +3 -0
- package/dist/hooks/useLocale.d.ts +4 -0
- package/dist/hooks/useOverflow.d.ts +11 -0
- package/dist/hooks/usePopoverState.d.ts +12 -0
- package/dist/hooks/useProxyModelValue.d.ts +8 -0
- package/dist/hooks/useResponsive/index.d.ts +1 -0
- package/dist/hooks/useResponsive/useResponsive.d.ts +6 -0
- package/dist/hooks/useTheme.d.ts +3 -0
- package/dist/hooks/useTimeFormat.d.ts +4 -0
- package/dist/hooks/useTimeMask.d.ts +4 -0
- package/dist/hooks/useToggle.d.ts +8 -0
- package/dist/hooks/useValidationAttributes.d.ts +11 -0
- package/dist/hooks.js +18 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +138 -0
- package/dist/isUndefined-B5qXrATz.js +4 -0
- package/dist/isVisible-BuGrjvTY.js +4 -0
- package/dist/searchItemsByLabel-BhinsABA.js +13 -0
- package/dist/tokens/DATE_FORMAT.d.ts +3 -0
- package/dist/tokens/LOCALE.d.ts +3 -0
- package/dist/tokens/TIME_FORMAT.d.ts +3 -0
- package/dist/tokens/index.d.ts +3 -0
- package/dist/types/DataModel.d.ts +6 -0
- package/dist/types/DateFormat.d.ts +5 -0
- package/dist/types/FilterFunction.d.ts +1 -0
- package/dist/types/FormatFunction.d.ts +2 -0
- package/dist/types/Group.d.ts +5 -0
- package/dist/types/GroupFunction.d.ts +1 -0
- package/dist/types/Id.d.ts +1 -0
- package/dist/types/Item.d.ts +5 -0
- package/dist/types/Locale.d.ts +1 -0
- package/dist/types/ModelValue.d.ts +1 -0
- package/dist/types/SearchFunction.d.ts +1 -0
- package/dist/types/TimeFormat.d.ts +5 -0
- package/dist/types/index.d.ts +12 -0
- package/dist/types.js +5 -0
- package/dist/useValidationAttributes-DxhcSj_h.js +217 -0
- package/dist/utils/constants/color.d.ts +14 -0
- package/dist/utils/constants/key-codes.d.ts +14 -0
- package/dist/utils/constants/poper.d.ts +8 -0
- package/dist/utils/constants/regex.d.ts +42 -0
- package/dist/utils/exclude.d.ts +4 -0
- package/dist/utils/extractCssVarName.d.ts +1 -0
- package/dist/utils/functions/color.d.ts +23 -0
- package/dist/utils/functions/dom.d.ts +30 -0
- package/dist/utils/functions/flattenDeep.d.ts +2 -0
- package/dist/utils/functions/hash.d.ts +2 -0
- package/dist/utils/functions/px-to-rem.d.ts +1 -0
- package/dist/utils/functions/text.d.ts +1 -0
- package/dist/utils/include.d.ts +4 -0
- package/dist/utils/index.d.ts +26 -0
- package/dist/utils/isAncestor.d.ts +4 -0
- package/dist/utils/isArray.d.ts +4 -0
- package/dist/utils/isDescendant.d.ts +4 -0
- package/dist/utils/isEmpty.d.ts +4 -0
- package/dist/utils/isEqual.d.ts +4 -0
- package/dist/utils/isNil.d.ts +4 -0
- package/dist/utils/isNull.d.ts +4 -0
- package/dist/utils/isNumber.d.ts +4 -0
- package/dist/utils/isObject.d.ts +4 -0
- package/dist/utils/isString.d.ts +4 -0
- package/dist/utils/isUndefined.d.ts +4 -0
- package/dist/utils/isVisible.d.ts +1 -0
- package/dist/utils/toArray.d.ts +4 -0
- package/dist/utils.js +109 -0
- package/package.json +77 -0
- package/src/assets/error.png +0 -0
- package/src/assets/index.ts +2 -0
- package/src/assets/success.png +0 -0
- package/src/directives/dropdown-close.ts +14 -0
- package/src/directives/dropdown-open.ts +21 -0
- package/src/directives/index.ts +2 -0
- package/src/helpers/getItemByValue.ts +12 -0
- package/src/helpers/getItemsByValue.ts +6 -0
- package/src/helpers/index.ts +3 -0
- package/src/helpers/searchItemsByLabel.ts +5 -0
- package/src/hooks/index.ts +15 -0
- package/src/hooks/useControlAttributes.ts +19 -0
- package/src/hooks/useDateFormat.ts +13 -0
- package/src/hooks/useDateMask.ts +54 -0
- package/src/hooks/useElevation.ts +32 -0
- package/src/hooks/useIdAttribute.ts +11 -0
- package/src/hooks/useLocale.ts +13 -0
- package/src/hooks/useOverflow.ts +83 -0
- package/src/hooks/usePopoverState.ts +67 -0
- package/src/hooks/useProxyModelValue.ts +50 -0
- package/src/hooks/useResponsive/index.ts +1 -0
- package/src/hooks/useResponsive/useResponsive.ts +58 -0
- package/src/hooks/useTheme.ts +8 -0
- package/src/hooks/useTimeFormat.ts +13 -0
- package/src/hooks/useTimeMask.ts +41 -0
- package/src/hooks/useToggle.ts +32 -0
- package/src/hooks/useValidationAttributes.ts +25 -0
- package/src/index.ts +6 -0
- package/src/tokens/DATE_FORMAT.ts +4 -0
- package/src/tokens/LOCALE.ts +4 -0
- package/src/tokens/TIME_FORMAT.ts +4 -0
- package/src/tokens/index.ts +3 -0
- package/src/types/DataModel.ts +3 -0
- package/src/types/DateFormat.ts +5 -0
- package/src/types/FilterFunction.ts +1 -0
- package/src/types/FormatFunction.ts +3 -0
- package/src/types/Group.ts +6 -0
- package/src/types/GroupFunction.ts +1 -0
- package/src/types/Id.ts +1 -0
- package/src/types/Item.ts +5 -0
- package/src/types/Locale.ts +1 -0
- package/src/types/ModelValue.ts +1 -0
- package/src/types/SearchFunction.ts +1 -0
- package/src/types/TimeFormat.ts +5 -0
- package/src/types/index.ts +12 -0
- package/src/utils/constants/color.ts +14 -0
- package/src/utils/constants/key-codes.ts +14 -0
- package/src/utils/constants/poper.ts +8 -0
- package/src/utils/constants/regex.ts +57 -0
- package/src/utils/exclude.ts +6 -0
- package/src/utils/extractCssVarName.ts +5 -0
- package/src/utils/functions/color.ts +55 -0
- package/src/utils/functions/dom.ts +206 -0
- package/src/utils/functions/flattenDeep.ts +5 -0
- package/src/utils/functions/hash.ts +10 -0
- package/src/utils/functions/px-to-rem.ts +2 -0
- package/src/utils/functions/text.ts +8 -0
- package/src/utils/include.ts +6 -0
- package/src/utils/index.ts +28 -0
- package/src/utils/isAncestor.ts +16 -0
- package/src/utils/isArray.ts +6 -0
- package/src/utils/isDescendant.ts +16 -0
- package/src/utils/isEmpty.ts +24 -0
- package/src/utils/isEqual.ts +23 -0
- package/src/utils/isNil.ts +8 -0
- package/src/utils/isNull.ts +6 -0
- package/src/utils/isNumber.ts +6 -0
- package/src/utils/isObject.ts +6 -0
- package/src/utils/isString.ts +6 -0
- package/src/utils/isUndefined.ts +6 -0
- package/src/utils/isVisible.ts +3 -0
- package/src/utils/toArray.ts +16 -0
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
import get from 'lodash/get';
|
|
2
|
+
import isElement from 'lodash/isElement';
|
|
3
|
+
|
|
4
|
+
const WINDOW = typeof window !== 'undefined' ? window : null;
|
|
5
|
+
|
|
6
|
+
export const MutationObs: MutationObserver =
|
|
7
|
+
WINDOW?.MutationObserver
|
|
8
|
+
|| (WINDOW as any)?.WebKitMutationObserver
|
|
9
|
+
|| (WINDOW as any)?.MozMutationObserver
|
|
10
|
+
|| null;
|
|
11
|
+
|
|
12
|
+
export const requestAF = (
|
|
13
|
+
WINDOW?.requestAnimationFrame ||
|
|
14
|
+
(WINDOW as any)?.webkitRequestAnimationFrame ||
|
|
15
|
+
(WINDOW as any)?.mozRequestAnimationFrame ||
|
|
16
|
+
(WINDOW as any)?.msRequestAnimationFrame ||
|
|
17
|
+
(WINDOW as any)?.oRequestAnimationFrame ||
|
|
18
|
+
// Fallback, but not a true polyfill
|
|
19
|
+
// Only needed for Opera Mini
|
|
20
|
+
((cb: () => void) => setTimeout(cb, 16))
|
|
21
|
+
).bind(WINDOW);
|
|
22
|
+
|
|
23
|
+
// eslint-disable-next-line no-unsafe-optional-chaining
|
|
24
|
+
export const cancelAF = (WINDOW?.cancelAnimationFrame || (WINDOW as any)?.mozCancelAnimationFrame).bind(WINDOW);
|
|
25
|
+
|
|
26
|
+
// Remove a node from DOM
|
|
27
|
+
export const removeNode = (el: HTMLElement): void => { el && el.parentNode && el.parentNode.removeChild(el); };
|
|
28
|
+
|
|
29
|
+
// Cause/wait-for an element to reflow its content (adjusting its height/width)
|
|
30
|
+
export const reflow = (el: HTMLElement): number | null => {
|
|
31
|
+
// Requesting an elements offsetHeight will trigger a reflow of the element content
|
|
32
|
+
return get(el, ['offsetHeight'], null);
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
// Select all elements matching selector. Returns `[]` if none found
|
|
36
|
+
export const selectAll = (selector: string, root?: HTMLElement | undefined): Element[] =>
|
|
37
|
+
[...(root && isElement(root) ? root : document).querySelectorAll(selector)];
|
|
38
|
+
|
|
39
|
+
// Select a single element, returns `null` if not found
|
|
40
|
+
export const select = (selector: string, root?: HTMLElement | undefined): Element | null =>
|
|
41
|
+
(root && isElement(root) ? root : document).querySelector(selector) || null;
|
|
42
|
+
|
|
43
|
+
// Returns true if the parent element contains the child element
|
|
44
|
+
export const contains = (parent: HTMLElement, child: HTMLElement): boolean =>
|
|
45
|
+
parent && typeof parent.contains === 'function' ? parent.contains(child) : false;
|
|
46
|
+
|
|
47
|
+
// Get an element given an ID
|
|
48
|
+
export const getById = (id: string): HTMLElement | null =>
|
|
49
|
+
document.getElementById(/^#/.test(id) ? id.slice(1) : id) || null;
|
|
50
|
+
|
|
51
|
+
// Add a class to an element
|
|
52
|
+
export const addClass = (el: HTMLElement, className: string): void => {
|
|
53
|
+
// We are checking for `el.classList` existence here since IE 11
|
|
54
|
+
// returns `undefined` for some elements (e.g. SVG elements)
|
|
55
|
+
if (className && isElement(el) && el.classList) {
|
|
56
|
+
el.classList.add(className);
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
// Remove a class from an element
|
|
61
|
+
export const removeClass = (el: HTMLElement, className: string): void => {
|
|
62
|
+
// We are checking for `el.classList` existence here since IE 11
|
|
63
|
+
// returns `undefined` for some elements (e.g. SVG elements)
|
|
64
|
+
if (className && isElement(el) && el.classList) el.classList.remove(className);
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
// Test if an element has a class
|
|
68
|
+
export const hasClass = (el: HTMLElement, className: string): boolean => {
|
|
69
|
+
// We are checking for `el.classList` existence here since IE 11
|
|
70
|
+
// returns `undefined` for some elements (e.g. SVG elements)
|
|
71
|
+
if (className && isElement(el) && el.classList) return el.classList.contains(className);
|
|
72
|
+
|
|
73
|
+
return false;
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
// Set an attribute on an element
|
|
77
|
+
export const setAttr = (el: HTMLElement, attr: string, value: any): void => {
|
|
78
|
+
if (attr && isElement(el)) {
|
|
79
|
+
el.setAttribute(attr, value);
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
// Remove an attribute from an element
|
|
84
|
+
export const removeAttr = (el: HTMLElement, attr: string): void => {
|
|
85
|
+
if (attr && isElement(el)) {
|
|
86
|
+
el.removeAttribute(attr);
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
// Get an attribute value from an element
|
|
91
|
+
export const getAttr = (el: HTMLElement, attr: string): string | null =>
|
|
92
|
+
(attr && isElement(el) ? el.getAttribute(attr) : null);
|
|
93
|
+
|
|
94
|
+
// Determine if an attribute exists on an element
|
|
95
|
+
// Returns `true` or `false`, or `null` if element not found
|
|
96
|
+
export const hasAttr = (el: HTMLElement, attr: string): boolean | null =>
|
|
97
|
+
(attr && isElement(el) ? el.hasAttribute(attr) : null);
|
|
98
|
+
|
|
99
|
+
// Set an style property on an element
|
|
100
|
+
export const setStyle = (el: HTMLElement, prop: any, value: any): void => {
|
|
101
|
+
if (prop && isElement(el)) {
|
|
102
|
+
el.style[prop] = value;
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
// Remove an style property from an element
|
|
107
|
+
export const removeStyle = (el: HTMLElement, prop: any): void => {
|
|
108
|
+
if (prop && isElement(el)) {
|
|
109
|
+
el.style[prop] = '';
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
// Get an style property value from an element
|
|
114
|
+
// Returns `null` if not found
|
|
115
|
+
export const getStyle = (el: HTMLElement, prop: any): string | null =>
|
|
116
|
+
(prop && isElement(el) ? el.style[prop] || null : null);
|
|
117
|
+
|
|
118
|
+
// Return the Bounding Client Rect of an element
|
|
119
|
+
export const getBCR = (el: HTMLElement): DOMRect | null => (isElement(el) ? el.getBoundingClientRect() : null);
|
|
120
|
+
|
|
121
|
+
// Get computed style object for an element
|
|
122
|
+
export const getCS = (el: HTMLElement): CSSStyleDeclaration | Record<string, string> =>
|
|
123
|
+
get(WINDOW, 'getComputedStyle', null) && isElement(el)
|
|
124
|
+
? getComputedStyle(el)
|
|
125
|
+
: {};
|
|
126
|
+
|
|
127
|
+
// Return an element's offset with respect to document element
|
|
128
|
+
export const offset = (el: HTMLElement): { top: number; left: number; } => {
|
|
129
|
+
const _offset = {
|
|
130
|
+
top: 0,
|
|
131
|
+
left: 0,
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
if (!isElement(el) || el.getClientRects().length === 0) {
|
|
135
|
+
return _offset;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
const bcr = getBCR(el);
|
|
139
|
+
if (bcr) {
|
|
140
|
+
const win = el.ownerDocument.defaultView;
|
|
141
|
+
|
|
142
|
+
_offset.top = bcr.top + get(win, 'pageYOffset', 0);
|
|
143
|
+
_offset.left = bcr.left + get(win, 'pageXOffset', 0);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
return _offset;
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
// Return an element's offset with respect to to its offsetParent
|
|
150
|
+
export const position = (el: HTMLElement): { top: number; left: number; } => {
|
|
151
|
+
let _offset = {
|
|
152
|
+
top: 0,
|
|
153
|
+
left: 0,
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
if (!isElement(el)) {
|
|
157
|
+
return _offset;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
let parentOffset = {
|
|
161
|
+
top: 0,
|
|
162
|
+
left: 0,
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
const elStyles = getCS(el);
|
|
166
|
+
|
|
167
|
+
if (elStyles.position === 'fixed') {
|
|
168
|
+
_offset = getBCR(el) || _offset;
|
|
169
|
+
} else {
|
|
170
|
+
_offset = offset(el);
|
|
171
|
+
const doc = el.ownerDocument;
|
|
172
|
+
let offsetParent: (Node & ParentNode) | null = el.offsetParent || doc.documentElement;
|
|
173
|
+
while (
|
|
174
|
+
offsetParent &&
|
|
175
|
+
(offsetParent === doc.body || offsetParent === doc.documentElement) &&
|
|
176
|
+
getCS(offsetParent as HTMLElement).position === 'static'
|
|
177
|
+
) {
|
|
178
|
+
offsetParent = offsetParent.parentNode;
|
|
179
|
+
}
|
|
180
|
+
if (offsetParent && offsetParent !== el && offsetParent.nodeType === Node.ELEMENT_NODE) {
|
|
181
|
+
parentOffset = offset(offsetParent as HTMLElement);
|
|
182
|
+
|
|
183
|
+
const offsetParentStyles = getCS(offsetParent as HTMLElement);
|
|
184
|
+
parentOffset.top += parseFloat(offsetParentStyles.borderTopWidth as string);
|
|
185
|
+
parentOffset.left += parseFloat(offsetParentStyles.borderLeftWidth as string);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
return {
|
|
190
|
+
top: _offset.top - parentOffset.top - parseFloat(elStyles.marginTop as string),
|
|
191
|
+
left: _offset.left - parentOffset.left - parseFloat(elStyles.marginLeft as string),
|
|
192
|
+
};
|
|
193
|
+
};
|
|
194
|
+
|
|
195
|
+
export const getMaxZIndex = (element: HTMLElement | null): number => {
|
|
196
|
+
let maxZIndex = 0;
|
|
197
|
+
while (element) {
|
|
198
|
+
const cs = getCS(element);
|
|
199
|
+
const zIndex = cs.zIndex;
|
|
200
|
+
if (zIndex !== 'auto') {
|
|
201
|
+
maxZIndex = +zIndex > maxZIndex ? +zIndex : maxZIndex;
|
|
202
|
+
}
|
|
203
|
+
element = element.parentElement;
|
|
204
|
+
}
|
|
205
|
+
return maxZIndex;
|
|
206
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export function getHashOfString(str: string): number {
|
|
2
|
+
return Math.abs(
|
|
3
|
+
str.split('')
|
|
4
|
+
.reduce((hash, char) => char.charCodeAt(0) + ((hash << 5) - hash), 0),
|
|
5
|
+
);
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export function normalize(hash: number, min: number, max: number): number {
|
|
9
|
+
return Math.floor((hash % (max - min)) + min);
|
|
10
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { RX_ABBREVIATION_FROM_STRING } from '../constants/regex';
|
|
2
|
+
|
|
3
|
+
export function getAbbreviation(text: string | null, limit?: number): string {
|
|
4
|
+
if (typeof text != 'string' || !text) return '';
|
|
5
|
+
return ((text.match(RX_ABBREVIATION_FROM_STRING) ?? []) as string[])
|
|
6
|
+
.reduce((previous: string, next: string) => previous + ((+next === 0 || parseInt(next)) ? parseInt(next) : next[0] || ''), '')
|
|
7
|
+
.toUpperCase().substring(0, limit);
|
|
8
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export * from './constants/color';
|
|
2
|
+
export * from './constants/key-codes';
|
|
3
|
+
export * from './constants/poper';
|
|
4
|
+
export * from './constants/regex';
|
|
5
|
+
export * from './exclude';
|
|
6
|
+
|
|
7
|
+
export * from './functions/color';
|
|
8
|
+
export * from './functions/dom';
|
|
9
|
+
export * from './functions/flattenDeep';
|
|
10
|
+
export * from './functions/hash';
|
|
11
|
+
export * from './functions/px-to-rem';
|
|
12
|
+
export * from './functions/text';
|
|
13
|
+
|
|
14
|
+
export * from './include';
|
|
15
|
+
export * from './isAncestor';
|
|
16
|
+
export * from './isArray';
|
|
17
|
+
export * from './isDescendant';
|
|
18
|
+
export * from './isEmpty';
|
|
19
|
+
export * from './isEqual';
|
|
20
|
+
export * from './isNil';
|
|
21
|
+
export * from './isNull';
|
|
22
|
+
export * from './isNumber';
|
|
23
|
+
export * from './isObject';
|
|
24
|
+
export * from './isString';
|
|
25
|
+
export * from './isUndefined';
|
|
26
|
+
export * from './isVisible';
|
|
27
|
+
export * from './toArray';
|
|
28
|
+
export * from './extractCssVarName';
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Determines whether the element `a` is an ancestor of the element `b`.
|
|
3
|
+
*/
|
|
4
|
+
export const isAncestor = (a: Element, b: Element): boolean => {
|
|
5
|
+
const { parentElement } = b;
|
|
6
|
+
|
|
7
|
+
if (!parentElement) {
|
|
8
|
+
return false;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
if (a === parentElement) {
|
|
12
|
+
return true;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
return isAncestor(a, parentElement);
|
|
16
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Determines whether the element `a` is a descendant of the element `b`.
|
|
3
|
+
*/
|
|
4
|
+
export const isDescendant = (a: Element, b: Element): boolean => {
|
|
5
|
+
const { parentElement } = a;
|
|
6
|
+
|
|
7
|
+
if (!parentElement) {
|
|
8
|
+
return false;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
if (b === parentElement) {
|
|
12
|
+
return true;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
return isDescendant(parentElement, b);
|
|
16
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { isArray, isNil, isObject, isString } from '.';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Determines whether the `value` is an empty object, an empty array, a zero-length string, `null`, or `undefined`.
|
|
5
|
+
*/
|
|
6
|
+
export const isEmpty = (value: unknown): boolean => {
|
|
7
|
+
if (isNil(value)) {
|
|
8
|
+
return true;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
if (isString(value)) {
|
|
12
|
+
return value.length === 0;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
if (isArray(value)) {
|
|
16
|
+
return value.length === 0;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
if (isObject(value)) {
|
|
20
|
+
return Object.keys(value).length === 0;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
return false;
|
|
24
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { isArray, isObject } from '.';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Determines whether `a` and `b` are the same value (makes shallow comparison of arrays and objects).
|
|
5
|
+
*/
|
|
6
|
+
export const isEqual = (a: unknown, b: unknown): boolean => {
|
|
7
|
+
if (Object.is(a, b)) {
|
|
8
|
+
return true;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
if (isArray(a) && isArray(b)) {
|
|
12
|
+
return a.length === b.length && a.every((item, index) => item === b[index]);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
if (isObject(a) && isObject(b)) {
|
|
16
|
+
const aKeys = Object.keys(a);
|
|
17
|
+
const bKeys = Object.keys(b);
|
|
18
|
+
|
|
19
|
+
return isEqual(aKeys, bKeys) && aKeys.every((key) => a[key] === b[key]);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
return false;
|
|
23
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { isArray, isNil } from '.';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Converts the `value` to an array literal.
|
|
5
|
+
*/
|
|
6
|
+
export const toArray = <T>(value: T | T[]): T[] => {
|
|
7
|
+
if (isNil(value)) {
|
|
8
|
+
return [];
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
if (isArray(value)) {
|
|
12
|
+
return value;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
return [value];
|
|
16
|
+
};
|