@nativerent/js-utils 1.2.2 → 1.2.4
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/index.d.ts +82 -74
- package/dist/index.js +596 -650
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +139 -164
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +18 -1
- package/tests/tests.ts +129 -0
package/dist/index.d.ts
CHANGED
|
@@ -1,123 +1,128 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
type Primitive = boolean | number | string;
|
|
2
|
+
|
|
3
|
+
type SimpleObject = {
|
|
4
|
+
[key: string | number]: Primitive | Primitive[] | null | undefined;
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
declare function debounce(fn: Function, delay: number): () => void;
|
|
8
|
+
declare function throttle(fn: Function, delay: number): (...args: any[]) => void;
|
|
9
|
+
declare function isObject(value: any): value is object;
|
|
10
|
+
declare function isFn(value: any): value is Function;
|
|
11
|
+
declare function isStr(value: any): boolean;
|
|
12
|
+
declare function isString(value: any): value is string;
|
|
8
13
|
/**
|
|
9
14
|
* Check if the given argument is a string which is not empty
|
|
10
15
|
*/
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
declare function isNotEmptyString(value: any): boolean;
|
|
17
|
+
declare function isHTMLElement(value: any): value is HTMLElement;
|
|
18
|
+
declare function isNum(value: any): value is number;
|
|
19
|
+
declare function isBool(value: any): value is boolean;
|
|
20
|
+
declare function isUndef(value: any): value is undefined;
|
|
21
|
+
declare function isNullOrUndef(value: unknown): value is null | undefined;
|
|
22
|
+
declare function isDefined(value: any): boolean;
|
|
18
23
|
/**
|
|
19
24
|
* Returns an array containing all the elements of array1 that are not in array2 and vice-versa
|
|
20
25
|
*/
|
|
21
|
-
|
|
26
|
+
declare function arrayDiff(array1: Array<Primitive | null | undefined>, array2: Array<Primitive | null | undefined>): Array<Primitive | null | undefined>;
|
|
22
27
|
/**
|
|
23
28
|
* Returns an array of elements present in array1 and array2
|
|
24
29
|
*/
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
30
|
+
declare function arrayIntersect(array1: Array<Primitive | null | undefined>, array2: Array<Primitive | null | undefined>): (Primitive | null | undefined)[];
|
|
31
|
+
declare function deepCloneObject<Type>(object: Type): Type;
|
|
32
|
+
declare function getNumericStyleProp(prop: string, el: Element): number;
|
|
33
|
+
declare function objectHasProp(obj: any, prop: string | number | symbol): boolean;
|
|
29
34
|
/**
|
|
30
35
|
* Custom version of Object.keys()
|
|
31
36
|
*/
|
|
32
|
-
|
|
37
|
+
declare function getObjectKeys(object: object): string[];
|
|
33
38
|
/**
|
|
34
39
|
* Convert an object to a query string
|
|
35
40
|
* Works with primitive objects
|
|
36
41
|
*/
|
|
37
|
-
|
|
42
|
+
declare function objectToQueryString(object: {
|
|
38
43
|
[key: string | number]: Primitive | Array<Primitive | null | undefined> | SimpleObject | {
|
|
39
44
|
[key: string | number]: SimpleObject;
|
|
40
45
|
} | undefined | null;
|
|
41
46
|
}): string;
|
|
42
|
-
|
|
47
|
+
declare function countObjectInnerLength(object: Record<string | number, any[] | null | undefined>): number;
|
|
43
48
|
/**
|
|
44
49
|
* Check if the element is in viewport
|
|
45
50
|
*/
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
51
|
+
declare function isElementVisible(element: HTMLElement, minVisiblePercent?: number): boolean;
|
|
52
|
+
declare function decodeSafeURL(url: string): string;
|
|
53
|
+
declare function getSafeURL(url?: string): string;
|
|
54
|
+
declare function parseURL(url: string): URL;
|
|
55
|
+
declare function encodeQueryString(url: string): string;
|
|
56
|
+
declare function injectScript(filename: string): void;
|
|
57
|
+
declare function injectStyleLink(filename: string): void;
|
|
58
|
+
declare function toBinaryStr(str: string): string;
|
|
54
59
|
/**
|
|
55
60
|
* Find a DOM element where an ad unit should be rendered to
|
|
56
61
|
*/
|
|
57
|
-
|
|
62
|
+
declare function getHtmlElement(id: string): HTMLElement | null;
|
|
58
63
|
/**
|
|
59
64
|
* Convert an HTML string into a list of nodes
|
|
60
65
|
*/
|
|
61
|
-
|
|
66
|
+
declare function stringToHtmlElements(html: string): NodeListOf<ChildNode>;
|
|
62
67
|
/**
|
|
63
68
|
* Creates an HTML element and sets attributes
|
|
64
69
|
*/
|
|
65
|
-
|
|
70
|
+
declare function createHtmlElement(type: string, attributes?: Record<string, string>): HTMLElement;
|
|
66
71
|
/**
|
|
67
72
|
* Insert HTML elements into DOM
|
|
68
73
|
*/
|
|
69
|
-
|
|
74
|
+
declare function insertHtmlElements(nodes: NodeListOf<Node>, appendTo?: Element | ShadowRoot): void;
|
|
70
75
|
/**
|
|
71
76
|
* Make a simple object which contains only attribute name and value
|
|
72
77
|
*/
|
|
73
|
-
|
|
78
|
+
declare function flatHtmlAttributes(attributes?: NamedNodeMap | null): Record<string, string>;
|
|
74
79
|
/**
|
|
75
80
|
* Create a <script> element
|
|
76
81
|
*/
|
|
77
|
-
|
|
82
|
+
declare function createScriptElement(js: string, inline?: boolean, attributes?: Record<string, string>): HTMLScriptElement;
|
|
78
83
|
/**
|
|
79
84
|
* Create a <style> element
|
|
80
85
|
*/
|
|
81
|
-
|
|
86
|
+
declare function createStyleElement(css: string | null): HTMLStyleElement;
|
|
82
87
|
/**
|
|
83
88
|
* Create a <link> element
|
|
84
89
|
*/
|
|
85
|
-
|
|
90
|
+
declare function createLinkElement(href: string): HTMLLinkElement;
|
|
86
91
|
/**
|
|
87
92
|
* Create svg elements
|
|
88
93
|
*/
|
|
89
|
-
|
|
94
|
+
declare function createSvgElement(content: string, attributes?: Record<string, string>): SVGSVGElement;
|
|
90
95
|
/**
|
|
91
96
|
* Create an image element to use as a tracking pixel
|
|
92
97
|
*/
|
|
93
|
-
|
|
98
|
+
declare function createPixelElement(src: string): HTMLImageElement;
|
|
94
99
|
/**
|
|
95
100
|
* Append a new script element to the DOM head
|
|
96
101
|
*/
|
|
97
|
-
|
|
102
|
+
declare function insertJs(js: string, inline?: boolean): void;
|
|
98
103
|
/**
|
|
99
104
|
* Append a new style element to the DOM head
|
|
100
105
|
*/
|
|
101
|
-
|
|
106
|
+
declare function insertCss(css: string, className?: string, external?: boolean): void;
|
|
102
107
|
/**
|
|
103
108
|
* Get screen sizes
|
|
104
109
|
*/
|
|
105
|
-
|
|
110
|
+
declare function getScreenSize(): {
|
|
106
111
|
width: number;
|
|
107
112
|
height: number;
|
|
108
113
|
};
|
|
109
114
|
/**
|
|
110
115
|
* Get a random integer between min and max
|
|
111
116
|
*/
|
|
112
|
-
|
|
117
|
+
declare function getRandomInt(min?: number, max?: number): number;
|
|
113
118
|
/**
|
|
114
119
|
* Implementation of Java's String.hashCode() method
|
|
115
120
|
*/
|
|
116
|
-
|
|
121
|
+
declare function hashCode(str: string): number;
|
|
117
122
|
/**
|
|
118
123
|
* Executes a callback as soon as DOM is interactive
|
|
119
124
|
*/
|
|
120
|
-
|
|
125
|
+
declare function onDOMReady<T extends unknown[]>(callback: (...args: T) => void, ...args: T): void;
|
|
121
126
|
/**
|
|
122
127
|
* Calculate the percentage of two values
|
|
123
128
|
*
|
|
@@ -125,41 +130,41 @@ export declare function onDOMReady<T extends unknown[]>(callback: (...args: T) =
|
|
|
125
130
|
* @param b
|
|
126
131
|
* @return number
|
|
127
132
|
*/
|
|
128
|
-
|
|
133
|
+
declare function toPercent(a: number, b: number): number;
|
|
129
134
|
/**
|
|
130
135
|
* Make a camelCase string
|
|
131
136
|
*
|
|
132
137
|
* @param string
|
|
133
138
|
* @return string
|
|
134
139
|
*/
|
|
135
|
-
|
|
140
|
+
declare function toCamelCase(string: string): string;
|
|
136
141
|
/**
|
|
137
142
|
* Make a snake_case string
|
|
138
143
|
*
|
|
139
144
|
* @param string
|
|
140
145
|
* @return string
|
|
141
146
|
*/
|
|
142
|
-
|
|
147
|
+
declare function toSnakeCase(string: string): string;
|
|
143
148
|
/**
|
|
144
149
|
* Transform the first letter of the given string to the upper case
|
|
145
150
|
*
|
|
146
151
|
* @param string
|
|
147
152
|
* @return string
|
|
148
153
|
*/
|
|
149
|
-
|
|
154
|
+
declare function capitalize(string: string): string;
|
|
150
155
|
/**
|
|
151
156
|
* Registry independent string sorting
|
|
152
157
|
*
|
|
153
158
|
* @param first
|
|
154
159
|
* @param second
|
|
155
160
|
*/
|
|
156
|
-
|
|
161
|
+
declare function sortByAlphabet(first: string, second: string): number;
|
|
157
162
|
/**
|
|
158
163
|
* @param length
|
|
159
164
|
* @return string of max length 100
|
|
160
165
|
*/
|
|
161
|
-
|
|
162
|
-
|
|
166
|
+
declare function getRandomStr(length?: number): string;
|
|
167
|
+
declare function getRandomItem(items: any[]): any;
|
|
163
168
|
/**
|
|
164
169
|
* Summarize elements of the given array
|
|
165
170
|
*
|
|
@@ -167,32 +172,35 @@ export declare function getRandomItem(items: any[]): any;
|
|
|
167
172
|
* @return number | string - a summary of all the numbers in the array or an empty string if
|
|
168
173
|
* there was only NaNs
|
|
169
174
|
*/
|
|
170
|
-
|
|
175
|
+
declare function sumArray(values: Array<any>): number | string;
|
|
171
176
|
/**
|
|
172
177
|
* Returns an array of the object keys which values are not present in filter
|
|
173
178
|
*
|
|
174
179
|
* @param obj
|
|
175
180
|
* @param values
|
|
176
181
|
*/
|
|
177
|
-
|
|
182
|
+
declare function filterObjectKeysByValues(obj: {
|
|
178
183
|
[key: string]: any;
|
|
179
184
|
}, values: Array<string | number | boolean | null | undefined>): string[];
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
185
|
+
declare function getFromObject(object: object, key: string): any;
|
|
186
|
+
declare function fireBlurEvent(element: string | Element | null, delay?: number): void;
|
|
187
|
+
declare function fireInputEvent(element: string | Element | null, delay?: number): void;
|
|
188
|
+
declare function fireEvent(eventName: string, element: string | Element | null, delay?: number): void;
|
|
189
|
+
declare function hasObjectChanged(oldObj: Record<string, any>, values: [string, any][], checkNewKeys?: boolean): boolean;
|
|
190
|
+
declare function roundBigNum(number: number): number;
|
|
191
|
+
declare function extractNumbers(value: unknown): string;
|
|
192
|
+
declare function removeSpaces(value: unknown): string;
|
|
193
|
+
declare function roundUp(num: number, precision: number): number;
|
|
194
|
+
declare function roundDown(num: number, precision: number): number;
|
|
195
|
+
declare function areDiff(val1?: Primitive | null, val2?: Primitive | null, strict?: boolean): boolean;
|
|
196
|
+
declare function flattenObject(obj: Record<string, any>, prefix?: string): Record<string, any>;
|
|
197
|
+
declare function flattenObjectAsArray(obj: Record<string, any>): Record<string, any>;
|
|
198
|
+
declare function parseObjectPathStr(pathStr: string): string[];
|
|
199
|
+
declare function formatNumber(num: number | string, fractionDigits?: number): string;
|
|
200
|
+
declare function formatNumberWithSign(num: number | string, fractionDigits?: number): string;
|
|
201
|
+
declare function formatPercent(num: number | string): string;
|
|
202
|
+
declare function formatWithSign(num: number | string, numString?: string): string;
|
|
203
|
+
declare function autoSizeText(el: HTMLElement, height: number, minFontSize: number, maxFontSize?: number): void;
|
|
204
|
+
declare function monitor(fn: Function, interval?: number, attempts?: number): Promise<boolean>;
|
|
205
|
+
|
|
206
|
+
export { areDiff, arrayDiff, arrayIntersect, autoSizeText, capitalize, countObjectInnerLength, createHtmlElement, createLinkElement, createPixelElement, createScriptElement, createStyleElement, createSvgElement, debounce, decodeSafeURL, deepCloneObject, encodeQueryString, extractNumbers, filterObjectKeysByValues, fireBlurEvent, fireEvent, fireInputEvent, flatHtmlAttributes, flattenObject, flattenObjectAsArray, formatNumber, formatNumberWithSign, formatPercent, formatWithSign, getFromObject, getHtmlElement, getNumericStyleProp, getObjectKeys, getRandomInt, getRandomItem, getRandomStr, getSafeURL, getScreenSize, hasObjectChanged, hashCode, injectScript, injectStyleLink, insertCss, insertHtmlElements, insertJs, isBool, isDefined, isElementVisible, isFn, isHTMLElement, isNotEmptyString, isNullOrUndef, isNum, isObject, isStr, isString, isUndef, monitor, objectHasProp, objectToQueryString, onDOMReady, parseObjectPathStr, parseURL, removeSpaces, roundBigNum, roundDown, roundUp, sortByAlphabet, stringToHtmlElements, sumArray, throttle, toBinaryStr, toCamelCase, toPercent, toSnakeCase };
|