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