@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 CHANGED
@@ -1,123 +1,128 @@
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;
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
- 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;
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
- export declare function arrayDiff(array1: Array<Primitive | null | undefined>, array2: Array<Primitive | null | undefined>): Array<Primitive | null | undefined>;
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
- 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;
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
- export declare function getObjectKeys(object: object): string[];
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
- export declare function objectToQueryString(object: {
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
- export declare function countObjectInnerLength(object: Record<string | number, any[] | null | undefined>): number;
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
- 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;
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
- export declare function getHtmlElement(id: string): HTMLElement | null;
62
+ declare function getHtmlElement(id: string): HTMLElement | null;
58
63
  /**
59
64
  * Convert an HTML string into a list of nodes
60
65
  */
61
- export declare function stringToHtmlElements(html: string): NodeListOf<ChildNode>;
66
+ declare function stringToHtmlElements(html: string): NodeListOf<ChildNode>;
62
67
  /**
63
68
  * Creates an HTML element and sets attributes
64
69
  */
65
- export declare function createHtmlElement(type: string, attributes?: Record<string, string>): HTMLElement;
70
+ declare function createHtmlElement(type: string, attributes?: Record<string, string>): HTMLElement;
66
71
  /**
67
72
  * Insert HTML elements into DOM
68
73
  */
69
- export declare function insertHtmlElements(nodes: NodeListOf<Node>, appendTo?: Element | ShadowRoot): void;
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
- export declare function flatHtmlAttributes(attributes?: NamedNodeMap | null): Record<string, string>;
78
+ declare function flatHtmlAttributes(attributes?: NamedNodeMap | null): Record<string, string>;
74
79
  /**
75
80
  * Create a <script> element
76
81
  */
77
- export declare function createScriptElement(js: string, inline?: boolean, attributes?: Record<string, string>): HTMLScriptElement;
82
+ declare function createScriptElement(js: string, inline?: boolean, attributes?: Record<string, string>): HTMLScriptElement;
78
83
  /**
79
84
  * Create a <style> element
80
85
  */
81
- export declare function createStyleElement(css: string | null): HTMLStyleElement;
86
+ declare function createStyleElement(css: string | null): HTMLStyleElement;
82
87
  /**
83
88
  * Create a <link> element
84
89
  */
85
- export declare function createLinkElement(href: string): HTMLLinkElement;
90
+ declare function createLinkElement(href: string): HTMLLinkElement;
86
91
  /**
87
92
  * Create svg elements
88
93
  */
89
- export declare function createSvgElement(content: string, attributes?: Record<string, string>): SVGSVGElement;
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
- export declare function createPixelElement(src: string): HTMLImageElement;
98
+ declare function createPixelElement(src: string): HTMLImageElement;
94
99
  /**
95
100
  * Append a new script element to the DOM head
96
101
  */
97
- export declare function insertJs(js: string, inline?: boolean): void;
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
- export declare function insertCss(css: string, className?: string, external?: boolean): void;
106
+ declare function insertCss(css: string, className?: string, external?: boolean): void;
102
107
  /**
103
108
  * Get screen sizes
104
109
  */
105
- export declare function getScreenSize(): {
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
- export declare function getRandomInt(min?: number, max?: number): number;
117
+ declare function getRandomInt(min?: number, max?: number): number;
113
118
  /**
114
119
  * Implementation of Java's String.hashCode() method
115
120
  */
116
- export declare function hashCode(str: string): number;
121
+ declare function hashCode(str: string): number;
117
122
  /**
118
123
  * Executes a callback as soon as DOM is interactive
119
124
  */
120
- export declare function onDOMReady<T extends unknown[]>(callback: (...args: T) => void, ...args: T): void;
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
- export declare function toPercent(a: number, b: number): number;
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
- export declare function toCamelCase(string: string): string;
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
- export declare function toSnakeCase(string: string): string;
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
- export declare function capitalize(string: string): string;
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
- export declare function sortByAlphabet(first: string, second: string): number;
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
- export declare function getRandomStr(length?: number): string;
162
- export declare function getRandomItem(items: any[]): any;
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
- export declare function sumArray(values: Array<any>): number | string;
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
- export declare function filterObjectKeysByValues(obj: {
182
+ declare function filterObjectKeysByValues(obj: {
178
183
  [key: string]: any;
179
184
  }, values: Array<string | number | boolean | null | undefined>): string[];
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;
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 };