@bitfiber/utils 1.0.4 → 1.1.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/README.md +74 -127
- package/dist/cjs/arr/cnd/cnd.js +12 -4
- package/dist/cjs/arr/cnd/cnd.js.map +1 -1
- package/dist/cjs/arr/fill/fill.js.map +1 -1
- package/dist/cjs/arr/index-by/index-by.js.map +1 -1
- package/dist/cjs/arr/index.js.map +1 -1
- package/dist/cjs/common/copy/copy.js +4 -3
- package/dist/cjs/common/copy/copy.js.map +1 -1
- package/dist/cjs/common/equals/equals.js +2 -2
- package/dist/cjs/common/equals/equals.js.map +1 -1
- package/dist/cjs/common/for-each/for-each.js.map +1 -1
- package/dist/cjs/common/index.js.map +1 -1
- package/dist/cjs/common/is/is.js +6 -3
- package/dist/cjs/common/is/is.js.map +1 -1
- package/dist/cjs/common/is-empty/is-empty.js.map +1 -1
- package/dist/cjs/common/to-sorted-string/to-sorted-string.js +11 -9
- package/dist/cjs/common/to-sorted-string/to-sorted-string.js.map +1 -1
- package/dist/cjs/dom/download-file/download-file.js +17 -18
- package/dist/cjs/dom/download-file/download-file.js.map +1 -1
- package/dist/cjs/dom/for-each-elements/for-each-elements.js.map +1 -1
- package/dist/cjs/dom/for-each-nodes/for-each-nodes.js.map +1 -1
- package/dist/cjs/dom/get-offset-from-parent/get-offset-from-parent.js.map +1 -1
- package/dist/cjs/dom/get-styles/get-styles.js.map +1 -1
- package/dist/cjs/dom/set-offset-from-parent/set-offset-from-parent.js +2 -1
- package/dist/cjs/dom/set-offset-from-parent/set-offset-from-parent.js.map +1 -1
- package/dist/cjs/env/get-browser/get-browser.js +36 -8
- package/dist/cjs/env/get-browser/get-browser.js.map +1 -1
- package/dist/cjs/env/get-os/get-os.js +15 -4
- package/dist/cjs/env/get-os/get-os.js.map +1 -1
- package/dist/cjs/env/get-platform/get-platform.js +11 -5
- package/dist/cjs/env/get-platform/get-platform.js.map +1 -1
- package/dist/cjs/env/index.js.map +1 -1
- package/dist/cjs/env/private/private.js +3 -1
- package/dist/cjs/env/private/private.js.map +1 -1
- package/dist/cjs/num/in-range/in-range.js +5 -1
- package/dist/cjs/num/in-range/in-range.js.map +1 -1
- package/dist/cjs/obj/extend/extend.js.map +1 -1
- package/dist/cjs/obj/for-each-obj/for-each-obj.js.map +1 -1
- package/dist/cjs/obj/map-obj/map-obj.js.map +1 -1
- package/dist/cjs/obj/map-obj-to-arr/map-obj-to-arr.js.map +1 -1
- package/dist/esm/arr/cnd/cnd.js +13 -5
- package/dist/esm/arr/cnd/cnd.js.map +1 -1
- package/dist/esm/arr/fill/fill.js.map +1 -1
- package/dist/esm/arr/index-by/index-by.js.map +1 -1
- package/dist/esm/arr/index.js.map +1 -1
- package/dist/esm/common/copy/copy.js +4 -3
- package/dist/esm/common/copy/copy.js.map +1 -1
- package/dist/esm/common/equals/equals.js +2 -2
- package/dist/esm/common/equals/equals.js.map +1 -1
- package/dist/esm/common/for-each/for-each.js +1 -1
- package/dist/esm/common/for-each/for-each.js.map +1 -1
- package/dist/esm/common/index.js.map +1 -1
- package/dist/esm/common/is/is.js +6 -3
- package/dist/esm/common/is/is.js.map +1 -1
- package/dist/esm/common/is-empty/is-empty.js +1 -1
- package/dist/esm/common/is-empty/is-empty.js.map +1 -1
- package/dist/esm/common/to-sorted-string/to-sorted-string.js +12 -10
- package/dist/esm/common/to-sorted-string/to-sorted-string.js.map +1 -1
- package/dist/esm/dom/download-file/download-file.js +17 -18
- package/dist/esm/dom/download-file/download-file.js.map +1 -1
- package/dist/esm/dom/for-each-elements/for-each-elements.js.map +1 -1
- package/dist/esm/dom/for-each-nodes/for-each-nodes.js.map +1 -1
- package/dist/esm/dom/get-offset-from-parent/get-offset-from-parent.js +1 -1
- package/dist/esm/dom/get-offset-from-parent/get-offset-from-parent.js.map +1 -1
- package/dist/esm/dom/get-styles/get-styles.js.map +1 -1
- package/dist/esm/dom/set-offset-from-parent/set-offset-from-parent.js +2 -1
- package/dist/esm/dom/set-offset-from-parent/set-offset-from-parent.js.map +1 -1
- package/dist/esm/env/get-browser/get-browser.js +36 -8
- package/dist/esm/env/get-browser/get-browser.js.map +1 -1
- package/dist/esm/env/get-os/get-os.js +15 -4
- package/dist/esm/env/get-os/get-os.js.map +1 -1
- package/dist/esm/env/get-platform/get-platform.js +11 -5
- package/dist/esm/env/get-platform/get-platform.js.map +1 -1
- package/dist/esm/env/index.js.map +1 -1
- package/dist/esm/env/private/private.js +3 -1
- package/dist/esm/env/private/private.js.map +1 -1
- package/dist/esm/num/in-range/in-range.js +5 -1
- package/dist/esm/num/in-range/in-range.js.map +1 -1
- package/dist/esm/obj/extend/extend.js.map +1 -1
- package/dist/esm/obj/for-each-obj/for-each-obj.js.map +1 -1
- package/dist/esm/obj/map-obj/map-obj.js.map +1 -1
- package/dist/esm/obj/map-obj-to-arr/map-obj-to-arr.js.map +1 -1
- package/dist/types/arr/cnd/cnd.d.ts.map +1 -1
- package/dist/types/arr/fill/fill.d.ts.map +1 -1
- package/dist/types/arr/index-by/index-by.d.ts.map +1 -1
- package/dist/types/arr/index.d.ts.map +1 -1
- package/dist/types/common/copy/copy.d.ts.map +1 -1
- package/dist/types/common/equals/equals.d.ts.map +1 -1
- package/dist/types/common/for-each/for-each.d.ts.map +1 -1
- package/dist/types/common/index.d.ts.map +1 -1
- package/dist/types/common/is/is.d.ts.map +1 -1
- package/dist/types/common/is-empty/is-empty.d.ts.map +1 -1
- package/dist/types/common/types.d.ts +12 -0
- package/dist/types/common/types.d.ts.map +1 -1
- package/dist/types/dom/download-file/download-file.d.ts +2 -1
- package/dist/types/dom/download-file/download-file.d.ts.map +1 -1
- package/dist/types/dom/for-each-elements/for-each-elements.d.ts.map +1 -1
- package/dist/types/dom/for-each-nodes/for-each-nodes.d.ts.map +1 -1
- package/dist/types/dom/get-offset-from-parent/get-offset-from-parent.d.ts.map +1 -1
- package/dist/types/dom/get-styles/get-styles.d.ts.map +1 -1
- package/dist/types/dom/set-offset-from-parent/set-offset-from-parent.d.ts.map +1 -1
- package/dist/types/env/get-browser/get-browser.d.ts.map +1 -1
- package/dist/types/env/get-os/get-os.d.ts.map +1 -1
- package/dist/types/env/get-platform/get-platform.d.ts.map +1 -1
- package/dist/types/env/index.d.ts.map +1 -1
- package/dist/types/env/private/private.d.ts.map +1 -1
- package/dist/types/env/types.d.ts.map +1 -1
- package/dist/types/num/in-range/in-range.d.ts.map +1 -1
- package/dist/types/obj/extend/extend.d.ts.map +1 -1
- package/dist/types/obj/for-each-obj/for-each-obj.d.ts.map +1 -1
- package/dist/types/obj/map-obj/map-obj.d.ts.map +1 -1
- package/dist/types/obj/map-obj-to-arr/map-obj-to-arr.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/arr/cnd/cnd.ts +21 -8
- package/src/arr/fill/fill.ts +5 -1
- package/src/arr/index-by/index-by.ts +4 -1
- package/src/arr/index.ts +2 -1
- package/src/common/copy/copy.ts +7 -5
- package/src/common/equals/equals.ts +10 -4
- package/src/common/for-each/for-each.ts +8 -2
- package/src/common/index.ts +6 -4
- package/src/common/is/is.ts +6 -5
- package/src/common/is-empty/is-empty.ts +3 -1
- package/src/common/to-sorted-string/to-sorted-string.ts +12 -14
- package/src/common/types.ts +16 -6
- package/src/dom/download-file/download-file.ts +22 -22
- package/src/dom/for-each-elements/for-each-elements.ts +4 -2
- package/src/dom/for-each-nodes/for-each-nodes.ts +4 -1
- package/src/dom/get-offset-from-parent/get-offset-from-parent.ts +7 -2
- package/src/dom/get-styles/get-styles.ts +4 -2
- package/src/dom/set-offset-from-parent/set-offset-from-parent.ts +2 -1
- package/src/env/get-browser/get-browser.ts +36 -8
- package/src/env/get-os/get-os.ts +15 -4
- package/src/env/get-platform/get-platform.ts +11 -5
- package/src/env/index.ts +3 -2
- package/src/env/private/private.ts +3 -1
- package/src/env/types.ts +19 -10
- package/src/num/in-range/in-range.ts +5 -1
- package/src/obj/extend/extend.ts +8 -4
- package/src/obj/for-each-obj/for-each-obj.ts +4 -2
- package/src/obj/map-obj/map-obj.ts +4 -2
- package/src/obj/map-obj-to-arr/map-obj-to-arr.ts +4 -2
|
@@ -7,12 +7,16 @@ let platform: PlatformNames | null = null;
|
|
|
7
7
|
const platformConditions: EnvCondition[] = [
|
|
8
8
|
[
|
|
9
9
|
'tv', [
|
|
10
|
-
() => ['tizen', 'webOS', 'appleTV', 'roku', 'xbox', 'playstation4', 'playstation5']
|
|
11
|
-
|
|
10
|
+
() => ['tizen', 'webOS', 'appleTV', 'roku', 'xbox', 'playstation4', 'playstation5']
|
|
11
|
+
.includes(getOS().name),
|
|
12
|
+
'(?:smart|web|google|hbb)[\\s:_/-]?tv',
|
|
13
|
+
'bravia',
|
|
12
14
|
],
|
|
13
|
-
],
|
|
15
|
+
],
|
|
16
|
+
['desktop', [() => ['macOS', 'chromeOS', 'windows', 'linux'].includes(getOS().name)]],
|
|
14
17
|
['tablet', [() => ['nintendoSwitch'].includes(getOS().name), 'ipad', 'silk', 'tablet']],
|
|
15
|
-
['mobile', ['iphone', 'android.*?mobi(?:le)?']],
|
|
18
|
+
['mobile', ['iphone', 'android.*?mobi(?:le)?']],
|
|
19
|
+
['tablet', 'android'],
|
|
16
20
|
];
|
|
17
21
|
|
|
18
22
|
/**
|
|
@@ -21,7 +25,9 @@ const platformConditions: EnvCondition[] = [
|
|
|
21
25
|
*/
|
|
22
26
|
export function getPlatform(): PlatformNames {
|
|
23
27
|
const bot = getBot();
|
|
24
|
-
platform ??= bot.name !== 'unknown'
|
|
28
|
+
platform ??= bot.name !== 'unknown'
|
|
29
|
+
? bot.name
|
|
30
|
+
: <PlatformNames>getEnvData(platformConditions).name;
|
|
25
31
|
return <PlatformNames>platform;
|
|
26
32
|
}
|
|
27
33
|
|
package/src/env/index.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export {
|
|
2
|
-
BotNames, PlatformNames, OSNames, EngineNames, BrowserNames, VersionData, OSData, EngineData,
|
|
3
|
-
EnginesCondition, BrowsersCondition, OSBrowsersCondition, OSCondition,
|
|
2
|
+
BotNames, PlatformNames, OSNames, EngineNames, BrowserNames, VersionData, OSData, EngineData,
|
|
3
|
+
BrowserData, EnginesCondition, BrowsersCondition, OSBrowsersCondition, OSCondition,
|
|
4
|
+
PlatformsCondition,
|
|
4
5
|
} from './types';
|
|
5
6
|
export {getUserAgent, setUserAgent} from './user-agent/user-agent';
|
|
6
7
|
export {getOS} from './get-os/get-os';
|
|
@@ -44,7 +44,9 @@ export function getEnvData(conditions: EnvCondition[], needVersion = false): Env
|
|
|
44
44
|
const tests = isArray(test) ? test : (isUndefined(test) ? [name] : [test]);
|
|
45
45
|
|
|
46
46
|
if (needVersion) {
|
|
47
|
-
ver = isUndefined(ver)
|
|
47
|
+
ver = isUndefined(ver)
|
|
48
|
+
? getVerRegExp(isString(test) ? test : name)
|
|
49
|
+
: (isString(ver) ? getVerRegExp(ver) : ver);
|
|
48
50
|
}
|
|
49
51
|
|
|
50
52
|
for (let test of tests) {
|
package/src/env/types.ts
CHANGED
|
@@ -11,8 +11,9 @@ export type PlatformNames = 'tv' | 'desktop' | 'tablet' | 'mobile' | BotNames;
|
|
|
11
11
|
/**
|
|
12
12
|
* Represents supported OS names
|
|
13
13
|
*/
|
|
14
|
-
export type OSNames = 'xbox' | 'windows' | 'ios' | 'macOS' | 'webOS' | 'tizen' | 'appleTV' | 'roku'
|
|
15
|
-
| 'playstation4' | 'playstation5' | 'nintendoSwitch' | 'likeAndroid' | 'android'
|
|
14
|
+
export type OSNames = 'xbox' | 'windows' | 'ios' | 'macOS' | 'webOS' | 'tizen' | 'appleTV' | 'roku'
|
|
15
|
+
| 'chromeOS' | 'playstation4' | 'playstation5' | 'nintendoSwitch' | 'likeAndroid' | 'android'
|
|
16
|
+
| 'linux' | BotNames;
|
|
16
17
|
|
|
17
18
|
/**
|
|
18
19
|
* Represents supported engine names
|
|
@@ -22,10 +23,11 @@ export type EngineNames = 'blink' | 'webkit' | 'gecko' | BotNames;
|
|
|
22
23
|
/**
|
|
23
24
|
* Represents supported browser names
|
|
24
25
|
*/
|
|
25
|
-
export type BrowserNames = 'opera' | 'operaCoast' | 'operaTouch' | 'samsung' | 'mz' | 'yandex'
|
|
26
|
-
| '
|
|
27
|
-
| '
|
|
28
|
-
| '
|
|
26
|
+
export type BrowserNames = 'opera' | 'operaCoast' | 'operaTouch' | 'samsung' | 'mz' | 'yandex'
|
|
27
|
+
| 'uc' | 'maxthon' | 'kmeleon' | 'wechat' | 'qqLite' | 'qq' | 'edge' | 'sailfish' | 'webOS'
|
|
28
|
+
| 'tizen' | 'miui' | 'silk' | 'phantomjs' | 'slimerjs' | 'qupzilla' | 'electron' | 'whale'
|
|
29
|
+
| 'focus' | 'swing' | 'epiphany' | 'puffin' | 'sleipnir' | 'vivaldi' | 'seamonkey'
|
|
30
|
+
| 'playstation4' | 'playstation5' | 'googleSearch' | 'firefox' | 'chrome' | 'android' | 'safari'
|
|
29
31
|
| BotNames;
|
|
30
32
|
|
|
31
33
|
/**
|
|
@@ -86,7 +88,9 @@ export type EnginesCondition = {[key in EngineNames]?: string};
|
|
|
86
88
|
* Represents an object that have keys corresponding to browser names and values corresponding to browser versions,
|
|
87
89
|
* and may have an engine property with the engines condition
|
|
88
90
|
*/
|
|
89
|
-
export type BrowsersCondition = {[key in BrowserNames]?: string} & {
|
|
91
|
+
export type BrowsersCondition = {[key in BrowserNames]?: string} & {
|
|
92
|
+
engines?: EngineNames | EnginesCondition;
|
|
93
|
+
};
|
|
90
94
|
|
|
91
95
|
/**
|
|
92
96
|
* Represents the browsers condition with an optional osVersion property
|
|
@@ -96,12 +100,16 @@ export type OSBrowsersCondition = BrowsersCondition & {osVersion?: string};
|
|
|
96
100
|
/**
|
|
97
101
|
* Represents an object that have keys corresponding to OS names and values corresponding to the OS browsers conditions
|
|
98
102
|
*/
|
|
99
|
-
export type OSCondition = {[key in OSNames]?: OSBrowsersCondition} & {
|
|
103
|
+
export type OSCondition = {[key in OSNames]?: OSBrowsersCondition} & {
|
|
104
|
+
anyOS?: OSBrowsersCondition;
|
|
105
|
+
};
|
|
100
106
|
|
|
101
107
|
/**
|
|
102
108
|
* Represents an object that have keys corresponding to platform names and values corresponding to the OS conditions
|
|
103
109
|
*/
|
|
104
|
-
export type PlatformsCondition = {[key in PlatformNames]?: OSCondition} & {
|
|
110
|
+
export type PlatformsCondition = {[key in PlatformNames]?: OSCondition} & {
|
|
111
|
+
anyPlatform?: OSCondition;
|
|
112
|
+
};
|
|
105
113
|
|
|
106
114
|
/*
|
|
107
115
|
* @internal
|
|
@@ -143,4 +151,5 @@ export type EnvTestGroup = EnvTest | EnvTest[];
|
|
|
143
151
|
* @internal
|
|
144
152
|
* Represents a set of tests and template for retrieving a version
|
|
145
153
|
*/
|
|
146
|
-
export type EnvCondition = string | [string, EnvTestGroup]
|
|
154
|
+
export type EnvCondition = string | [string, EnvTestGroup]
|
|
155
|
+
| [string, EnvTestGroup, string | RegExp];
|
|
@@ -36,7 +36,11 @@ export interface InRangeOptions {
|
|
|
36
36
|
* @param options - options for converting the numeric value
|
|
37
37
|
*/
|
|
38
38
|
export function inRange(value: number | Nullish, options: InRangeOptions = {}): number | null {
|
|
39
|
-
let newValue = isNumber(value)
|
|
39
|
+
let newValue = isNumber(value)
|
|
40
|
+
? (isNumber(options.precision)
|
|
41
|
+
? round(value, options.precision)
|
|
42
|
+
: value)
|
|
43
|
+
: null;
|
|
40
44
|
|
|
41
45
|
if (isNumber(newValue)) {
|
|
42
46
|
if (isNumber(options.min) && newValue < options.min) {
|
package/src/obj/extend/extend.ts
CHANGED
|
@@ -7,8 +7,10 @@ import {forEachObj} from '../';
|
|
|
7
7
|
* @param target - target object
|
|
8
8
|
* @param sources - source objects
|
|
9
9
|
*/
|
|
10
|
-
export function extend<T extends Obj, U extends Obj[]>(
|
|
11
|
-
|
|
10
|
+
export function extend<T extends Obj, U extends Obj[]>(
|
|
11
|
+
target: T,
|
|
12
|
+
...sources: U
|
|
13
|
+
): T & ValueIntersection<typeof sources> {
|
|
12
14
|
return _extend(target, sources, false, new Map<any, true>());
|
|
13
15
|
}
|
|
14
16
|
|
|
@@ -19,8 +21,10 @@ export function extend<T extends Obj, U extends Obj[]>(target: T,
|
|
|
19
21
|
* @param target - target object
|
|
20
22
|
* @param sources - source objects
|
|
21
23
|
*/
|
|
22
|
-
export function extendAll<T extends Obj, U extends Obj[]>(
|
|
23
|
-
|
|
24
|
+
export function extendAll<T extends Obj, U extends Obj[]>(
|
|
25
|
+
target: T,
|
|
26
|
+
...sources: U
|
|
27
|
+
): T & ValueIntersection<typeof sources> {
|
|
24
28
|
return _extend(target, sources, true, new Map<any, true>());
|
|
25
29
|
}
|
|
26
30
|
|
|
@@ -7,8 +7,10 @@ import {hasOwn} from '../';
|
|
|
7
7
|
* @param obj - any object
|
|
8
8
|
* @param handler - function called for each field
|
|
9
9
|
*/
|
|
10
|
-
export function forEachObj<T extends Obj, K extends keyof T>(
|
|
11
|
-
|
|
10
|
+
export function forEachObj<T extends Obj, K extends keyof T>(
|
|
11
|
+
obj: T,
|
|
12
|
+
handler: (value: ValueUnion<T>, key: K, obj: T) => any,
|
|
13
|
+
): void {
|
|
12
14
|
for (const key in obj) {
|
|
13
15
|
if (hasOwn(obj, key) && handler(obj[key], <Extract<K, string>>key, obj) === INTERRUPT) {
|
|
14
16
|
return;
|
|
@@ -6,8 +6,10 @@ import {forEachObj} from '../';
|
|
|
6
6
|
* @param obj - any object
|
|
7
7
|
* @param handler - function called for each field
|
|
8
8
|
*/
|
|
9
|
-
export function mapObj<T extends Obj, K extends keyof T, R>(
|
|
10
|
-
|
|
9
|
+
export function mapObj<T extends Obj, K extends keyof T, R>(
|
|
10
|
+
obj: T,
|
|
11
|
+
handler: (value: ValueUnion<T>, key: K, obj: T) => R,
|
|
12
|
+
): Record<K, R> {
|
|
11
13
|
const result = <Record<K, R>>{};
|
|
12
14
|
forEachObj(obj, (value, key) => result[<K>key] = handler(value, <K>key, obj));
|
|
13
15
|
return result;
|
|
@@ -6,8 +6,10 @@ import {forEachObj} from '../';
|
|
|
6
6
|
* @param obj - any object
|
|
7
7
|
* @param handler - function called for each field
|
|
8
8
|
*/
|
|
9
|
-
export function mapObjToArr<T extends Obj, K extends keyof T, R>(
|
|
10
|
-
|
|
9
|
+
export function mapObjToArr<T extends Obj, K extends keyof T, R>(
|
|
10
|
+
obj: T,
|
|
11
|
+
handler: (value: ValueUnion<T>, key: K, obj: T) => R,
|
|
12
|
+
): R[] {
|
|
11
13
|
const result: R[] = [];
|
|
12
14
|
forEachObj(obj, (value, key) => result.push(handler(value, <K>key, obj)));
|
|
13
15
|
return result;
|