@bitfiber/utils 1.0.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/CODE_OF_CONDUCT.md +127 -0
- package/CONTRIBUTING.md +87 -0
- package/LICENSE.txt +201 -0
- package/README.md +2516 -0
- package/arr/at/at.d.ts +7 -0
- package/arr/at/at.js +11 -0
- package/arr/at/at.js.map +1 -0
- package/arr/cnd/cnd.d.ts +55 -0
- package/arr/cnd/cnd.js +136 -0
- package/arr/cnd/cnd.js.map +1 -0
- package/arr/diff-arr/diff-arr.d.ts +10 -0
- package/arr/diff-arr/diff-arr.js +37 -0
- package/arr/diff-arr/diff-arr.js.map +1 -0
- package/arr/fill/fill.d.ts +8 -0
- package/arr/fill/fill.js +11 -0
- package/arr/fill/fill.js.map +1 -0
- package/arr/for-each-arr/for-each-arr.d.ts +9 -0
- package/arr/for-each-arr/for-each-arr.js +25 -0
- package/arr/for-each-arr/for-each-arr.js.map +1 -0
- package/arr/index-by/index-by.d.ts +9 -0
- package/arr/index-by/index-by.js +19 -0
- package/arr/index-by/index-by.js.map +1 -0
- package/arr/index.d.ts +9 -0
- package/arr/index.js +10 -0
- package/arr/index.js.map +1 -0
- package/arr/pluck/pluck.d.ts +7 -0
- package/arr/pluck/pluck.js +13 -0
- package/arr/pluck/pluck.js.map +1 -0
- package/arr/types.d.ts +84 -0
- package/arr/types.js +2 -0
- package/arr/types.js.map +1 -0
- package/arr/within/within.d.ts +9 -0
- package/arr/within/within.js +14 -0
- package/arr/within/within.js.map +1 -0
- package/common/copy/copy.d.ts +6 -0
- package/common/copy/copy.js +86 -0
- package/common/copy/copy.js.map +1 -0
- package/common/equals/equals.d.ts +12 -0
- package/common/equals/equals.js +127 -0
- package/common/equals/equals.js.map +1 -0
- package/common/error.d.ts +19 -0
- package/common/error.js +16 -0
- package/common/error.js.map +1 -0
- package/common/for-each/for-each.d.ts +9 -0
- package/common/for-each/for-each.js +40 -0
- package/common/for-each/for-each.js.map +1 -0
- package/common/get-unique-num-id/get-unique-num-id.d.ts +4 -0
- package/common/get-unique-num-id/get-unique-num-id.js +8 -0
- package/common/get-unique-num-id/get-unique-num-id.js.map +1 -0
- package/common/get-unique-str-id/get-unique-str-id.d.ts +4 -0
- package/common/get-unique-str-id/get-unique-str-id.js +16 -0
- package/common/get-unique-str-id/get-unique-str-id.js.map +1 -0
- package/common/has-iterator/has-iterator.d.ts +5 -0
- package/common/has-iterator/has-iterator.js +8 -0
- package/common/has-iterator/has-iterator.js.map +1 -0
- package/common/index.d.ts +16 -0
- package/common/index.js +17 -0
- package/common/index.js.map +1 -0
- package/common/is/is.d.ts +136 -0
- package/common/is/is.js +214 -0
- package/common/is/is.js.map +1 -0
- package/common/is-empty/is-empty.d.ts +6 -0
- package/common/is-empty/is-empty.js +30 -0
- package/common/is-empty/is-empty.js.map +1 -0
- package/common/random/random.d.ts +5 -0
- package/common/random/random.js +9 -0
- package/common/random/random.js.map +1 -0
- package/common/same/same.d.ts +6 -0
- package/common/same/same.js +9 -0
- package/common/same/same.js.map +1 -0
- package/common/stub/stub.d.ts +4 -0
- package/common/stub/stub.js +8 -0
- package/common/stub/stub.js.map +1 -0
- package/common/to-float/to-float.d.ts +6 -0
- package/common/to-float/to-float.js +10 -0
- package/common/to-float/to-float.js.map +1 -0
- package/common/to-int/to-int.d.ts +6 -0
- package/common/to-int/to-int.js +10 -0
- package/common/to-int/to-int.js.map +1 -0
- package/common/to-sorted-string/to-sorted-string.d.ts +7 -0
- package/common/to-sorted-string/to-sorted-string.js +53 -0
- package/common/to-sorted-string/to-sorted-string.js.map +1 -0
- package/common/types.d.ts +63 -0
- package/common/types.js +5 -0
- package/common/types.js.map +1 -0
- package/dom/closest/closest.d.ts +6 -0
- package/dom/closest/closest.js +26 -0
- package/dom/closest/closest.js.map +1 -0
- package/dom/document/document.d.ts +12 -0
- package/dom/document/document.js +24 -0
- package/dom/document/document.js.map +1 -0
- package/dom/download-file/download-file.d.ts +6 -0
- package/dom/download-file/download-file.js +32 -0
- package/dom/download-file/download-file.js.map +1 -0
- package/dom/for-each-elements/for-each-elements.d.ts +8 -0
- package/dom/for-each-elements/for-each-elements.js +16 -0
- package/dom/for-each-elements/for-each-elements.js.map +1 -0
- package/dom/for-each-nodes/for-each-nodes.d.ts +7 -0
- package/dom/for-each-nodes/for-each-nodes.js +15 -0
- package/dom/for-each-nodes/for-each-nodes.js.map +1 -0
- package/dom/get-all-styles/get-all-styles.d.ts +5 -0
- package/dom/get-all-styles/get-all-styles.js +10 -0
- package/dom/get-all-styles/get-all-styles.js.map +1 -0
- package/dom/get-body/get-body.d.ts +4 -0
- package/dom/get-body/get-body.js +9 -0
- package/dom/get-body/get-body.js.map +1 -0
- package/dom/get-html/get-html.d.ts +4 -0
- package/dom/get-html/get-html.js +9 -0
- package/dom/get-html/get-html.js.map +1 -0
- package/dom/get-non-static-parent/get-non-static-parent.d.ts +5 -0
- package/dom/get-non-static-parent/get-non-static-parent.js +9 -0
- package/dom/get-non-static-parent/get-non-static-parent.js.map +1 -0
- package/dom/get-offset-from-doc/get-offset-from-doc.d.ts +6 -0
- package/dom/get-offset-from-doc/get-offset-from-doc.js +18 -0
- package/dom/get-offset-from-doc/get-offset-from-doc.js.map +1 -0
- package/dom/get-offset-from-parent/get-offset-from-parent.d.ts +7 -0
- package/dom/get-offset-from-parent/get-offset-from-parent.js +45 -0
- package/dom/get-offset-from-parent/get-offset-from-parent.js.map +1 -0
- package/dom/get-offset-from-win/get-offset-from-win.d.ts +6 -0
- package/dom/get-offset-from-win/get-offset-from-win.js +8 -0
- package/dom/get-offset-from-win/get-offset-from-win.js.map +1 -0
- package/dom/get-scroll-width/get-scroll-width.d.ts +8 -0
- package/dom/get-scroll-width/get-scroll-width.js +28 -0
- package/dom/get-scroll-width/get-scroll-width.js.map +1 -0
- package/dom/get-style/get-style.d.ts +6 -0
- package/dom/get-style/get-style.js +23 -0
- package/dom/get-style/get-style.js.map +1 -0
- package/dom/get-styles/get-styles.d.ts +9 -0
- package/dom/get-styles/get-styles.js +12 -0
- package/dom/get-styles/get-styles.js.map +1 -0
- package/dom/get-valid-style-name/get-valid-style-name.d.ts +6 -0
- package/dom/get-valid-style-name/get-valid-style-name.js +41 -0
- package/dom/get-valid-style-name/get-valid-style-name.js.map +1 -0
- package/dom/get-window/get-window.d.ts +4 -0
- package/dom/get-window/get-window.js +17 -0
- package/dom/get-window/get-window.js.map +1 -0
- package/dom/has-name/has-name.d.ts +6 -0
- package/dom/has-name/has-name.js +9 -0
- package/dom/has-name/has-name.js.map +1 -0
- package/dom/index.d.ts +25 -0
- package/dom/index.js +26 -0
- package/dom/index.js.map +1 -0
- package/dom/is-comment/is-comment.d.ts +5 -0
- package/dom/is-comment/is-comment.js +8 -0
- package/dom/is-comment/is-comment.js.map +1 -0
- package/dom/is-element/is-element.d.ts +5 -0
- package/dom/is-element/is-element.js +8 -0
- package/dom/is-element/is-element.js.map +1 -0
- package/dom/is-text/is-text.d.ts +5 -0
- package/dom/is-text/is-text.js +8 -0
- package/dom/is-text/is-text.js.map +1 -0
- package/dom/set-offset-from-parent/set-offset-from-parent.d.ts +8 -0
- package/dom/set-offset-from-parent/set-offset-from-parent.js +42 -0
- package/dom/set-offset-from-parent/set-offset-from-parent.js.map +1 -0
- package/dom/set-style/set-style.d.ts +8 -0
- package/dom/set-style/set-style.js +14 -0
- package/dom/set-style/set-style.js.map +1 -0
- package/dom/set-styles/set-styles.d.ts +8 -0
- package/dom/set-styles/set-styles.js +16 -0
- package/dom/set-styles/set-styles.js.map +1 -0
- package/dom/types.d.ts +19 -0
- package/dom/types.js +2 -0
- package/dom/types.js.map +1 -0
- package/env/get-browser/get-browser.d.ts +10 -0
- package/env/get-browser/get-browser.js +33 -0
- package/env/get-browser/get-browser.js.map +1 -0
- package/env/get-engine/get-engine.d.ts +7 -0
- package/env/get-engine/get-engine.js +22 -0
- package/env/get-engine/get-engine.js.map +1 -0
- package/env/get-os/get-os.d.ts +8 -0
- package/env/get-os/get-os.js +26 -0
- package/env/get-os/get-os.js.map +1 -0
- package/env/get-platform/get-platform.d.ts +7 -0
- package/env/get-platform/get-platform.js +30 -0
- package/env/get-platform/get-platform.js.map +1 -0
- package/env/index.d.ts +21 -0
- package/env/index.js +22 -0
- package/env/index.js.map +1 -0
- package/env/is-browser/is-browser.d.ts +11 -0
- package/env/is-browser/is-browser.js +15 -0
- package/env/is-browser/is-browser.js.map +1 -0
- package/env/is-chrome-like/is-chrome-like.d.ts +4 -0
- package/env/is-chrome-like/is-chrome-like.js +9 -0
- package/env/is-chrome-like/is-chrome-like.js.map +1 -0
- package/env/is-desktop/is-desktop.d.ts +4 -0
- package/env/is-desktop/is-desktop.js +9 -0
- package/env/is-desktop/is-desktop.js.map +1 -0
- package/env/is-engine/is-engine.d.ts +8 -0
- package/env/is-engine/is-engine.js +12 -0
- package/env/is-engine/is-engine.js.map +1 -0
- package/env/is-firefox-like/is-firefox-like.d.ts +4 -0
- package/env/is-firefox-like/is-firefox-like.js +9 -0
- package/env/is-firefox-like/is-firefox-like.js.map +1 -0
- package/env/is-mobile/is-mobile.d.ts +4 -0
- package/env/is-mobile/is-mobile.js +9 -0
- package/env/is-mobile/is-mobile.js.map +1 -0
- package/env/is-os/is-os.d.ts +9 -0
- package/env/is-os/is-os.js +13 -0
- package/env/is-os/is-os.js.map +1 -0
- package/env/is-portable/is-portable.d.ts +4 -0
- package/env/is-portable/is-portable.js +8 -0
- package/env/is-portable/is-portable.js.map +1 -0
- package/env/is-safari-like/is-safari-like.d.ts +4 -0
- package/env/is-safari-like/is-safari-like.js +9 -0
- package/env/is-safari-like/is-safari-like.js.map +1 -0
- package/env/is-stationary/is-stationary.d.ts +4 -0
- package/env/is-stationary/is-stationary.js +8 -0
- package/env/is-stationary/is-stationary.js.map +1 -0
- package/env/is-tablet/is-tablet.d.ts +4 -0
- package/env/is-tablet/is-tablet.js +9 -0
- package/env/is-tablet/is-tablet.js.map +1 -0
- package/env/is-tv/is-tv.d.ts +4 -0
- package/env/is-tv/is-tv.js +9 -0
- package/env/is-tv/is-tv.js.map +1 -0
- package/env/matches/matches.d.ts +34 -0
- package/env/matches/matches.js +52 -0
- package/env/matches/matches.js.map +1 -0
- package/env/matches-with-browsers/matches-with-browsers.d.ts +23 -0
- package/env/matches-with-browsers/matches-with-browsers.js +53 -0
- package/env/matches-with-browsers/matches-with-browsers.js.map +1 -0
- package/env/matches-with-version/matches-with-version.d.ts +6 -0
- package/env/matches-with-version/matches-with-version.js +41 -0
- package/env/matches-with-version/matches-with-version.js.map +1 -0
- package/env/private/private.d.ts +4 -0
- package/env/private/private.js +67 -0
- package/env/private/private.js.map +1 -0
- package/env/types.d.ts +106 -0
- package/env/types.js +2 -0
- package/env/types.js.map +1 -0
- package/env/user-agent/user-agent.d.ts +9 -0
- package/env/user-agent/user-agent.js +24 -0
- package/env/user-agent/user-agent.js.map +1 -0
- package/index.d.ts +1 -0
- package/index.js +2 -0
- package/index.js.map +1 -0
- package/num/in-range/in-range.d.ts +8 -0
- package/num/in-range/in-range.js +23 -0
- package/num/in-range/in-range.js.map +1 -0
- package/num/index.d.ts +3 -0
- package/num/index.js +4 -0
- package/num/index.js.map +1 -0
- package/num/round/round.d.ts +7 -0
- package/num/round/round.js +11 -0
- package/num/round/round.js.map +1 -0
- package/num/types.d.ts +24 -0
- package/num/types.js +2 -0
- package/num/types.js.map +1 -0
- package/obj/constant/constant.d.ts +6 -0
- package/obj/constant/constant.js +8 -0
- package/obj/constant/constant.js.map +1 -0
- package/obj/deep-constant/deep-constant.d.ts +6 -0
- package/obj/deep-constant/deep-constant.js +18 -0
- package/obj/deep-constant/deep-constant.js.map +1 -0
- package/obj/diff-obj/diff-obj.d.ts +9 -0
- package/obj/diff-obj/diff-obj.js +48 -0
- package/obj/diff-obj/diff-obj.js.map +1 -0
- package/obj/exclude/exclude.d.ts +7 -0
- package/obj/exclude/exclude.js +18 -0
- package/obj/exclude/exclude.js.map +1 -0
- package/obj/extend/extend.d.ts +16 -0
- package/obj/extend/extend.js +49 -0
- package/obj/extend/extend.js.map +1 -0
- package/obj/for-each-obj/for-each-obj.d.ts +8 -0
- package/obj/for-each-obj/for-each-obj.js +16 -0
- package/obj/for-each-obj/for-each-obj.js.map +1 -0
- package/obj/has-own/has-own.d.ts +8 -0
- package/obj/has-own/has-own.js +11 -0
- package/obj/has-own/has-own.js.map +1 -0
- package/obj/include/include.d.ts +7 -0
- package/obj/include/include.js +17 -0
- package/obj/include/include.js.map +1 -0
- package/obj/index.d.ts +13 -0
- package/obj/index.js +14 -0
- package/obj/index.js.map +1 -0
- package/obj/keys/keys.d.ts +6 -0
- package/obj/keys/keys.js +8 -0
- package/obj/keys/keys.js.map +1 -0
- package/obj/map-obj/map-obj.d.ts +7 -0
- package/obj/map-obj/map-obj.js +12 -0
- package/obj/map-obj/map-obj.js.map +1 -0
- package/obj/map-obj-to-arr/map-obj-to-arr.d.ts +7 -0
- package/obj/map-obj-to-arr/map-obj-to-arr.js +12 -0
- package/obj/map-obj-to-arr/map-obj-to-arr.js.map +1 -0
- package/obj/types.d.ts +30 -0
- package/obj/types.js +2 -0
- package/obj/types.js.map +1 -0
- package/obj/values/values.d.ts +6 -0
- package/obj/values/values.js +11 -0
- package/obj/values/values.js.map +1 -0
- package/package.json +73 -0
- package/str/index.d.ts +3 -0
- package/str/index.js +4 -0
- package/str/index.js.map +1 -0
- package/str/to-camel-case/to-camel-case.d.ts +10 -0
- package/str/to-camel-case/to-camel-case.js +18 -0
- package/str/to-camel-case/to-camel-case.js.map +1 -0
- package/str/to-hash/to-hash.d.ts +7 -0
- package/str/to-hash/to-hash.js +21 -0
- package/str/to-hash/to-hash.js.map +1 -0
- package/str/with-capital/with-capital.d.ts +6 -0
- package/str/with-capital/with-capital.js +9 -0
- package/str/with-capital/with-capital.js.map +1 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"is-tv.js","sourceRoot":"","sources":["../../../../package/src/env/is-tv/is-tv.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,WAAW,EAAC,MAAM,KAAK,CAAC;AAEhC;;GAEG;AACH,MAAM,UAAU,IAAI;IAClB,MAAM,IAAI,GAAG,WAAW,EAAE,CAAC;IAC3B,OAAO,IAAI,KAAK,IAAI,CAAC;AACvB,CAAC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { PlatformsCondition } from '../';
|
|
2
|
+
/**
|
|
3
|
+
* Checks if a current browser matches a specific set of conditions
|
|
4
|
+
*
|
|
5
|
+
* Condition structure:
|
|
6
|
+
* {
|
|
7
|
+
* [platformName | anyPlatform]: {
|
|
8
|
+
* [osName | anyOS]: {
|
|
9
|
+
* osVersion?: versionCondition(x.x...x | [~ >= > <= <]x.x...x),
|
|
10
|
+
* browserName?: versionCondition(x.x...x | [~ >= > <= <]x.x...x),
|
|
11
|
+
* engines?: engineName | {
|
|
12
|
+
* engineName: versionCondition(x.x...x | [~ >= > <= <]x.x...x)
|
|
13
|
+
* ...
|
|
14
|
+
* }
|
|
15
|
+
* ...
|
|
16
|
+
* }
|
|
17
|
+
* ...
|
|
18
|
+
* }
|
|
19
|
+
* ...
|
|
20
|
+
* }
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* matches({anyPlatform: {anyOS: {chrome: ''}}});
|
|
24
|
+
* matches({desktop: {windows: {chrome: '96.0.4664.110'}}});
|
|
25
|
+
* matches({desktop: {windows: {osVersion: '~10', engines: 'blink'}}});
|
|
26
|
+
* matches({desktop: {anyOS: {engines: {blink: '>90.5', gecko: '<=100'}}}});
|
|
27
|
+
* matches({anyPlatform: {ios: {chrome: '~96.1', safari: '>80'}}});
|
|
28
|
+
*
|
|
29
|
+
* @param condition - an object that has keys corresponding to platform names
|
|
30
|
+
* and values corresponding to objects that have keys corresponding to OS names
|
|
31
|
+
* and values corresponding to objects that have keys corresponding to browser names
|
|
32
|
+
* and values corresponding to browser versions
|
|
33
|
+
*/
|
|
34
|
+
export declare function matches(condition: PlatformsCondition): boolean;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { INTERRUPT } from '../../';
|
|
2
|
+
import { exclude, forEachObj } from '../../obj';
|
|
3
|
+
import { getPlatform, isOS, matchesWithBrowsers } from '../';
|
|
4
|
+
/**
|
|
5
|
+
* Checks if a current browser matches a specific set of conditions
|
|
6
|
+
*
|
|
7
|
+
* Condition structure:
|
|
8
|
+
* {
|
|
9
|
+
* [platformName | anyPlatform]: {
|
|
10
|
+
* [osName | anyOS]: {
|
|
11
|
+
* osVersion?: versionCondition(x.x...x | [~ >= > <= <]x.x...x),
|
|
12
|
+
* browserName?: versionCondition(x.x...x | [~ >= > <= <]x.x...x),
|
|
13
|
+
* engines?: engineName | {
|
|
14
|
+
* engineName: versionCondition(x.x...x | [~ >= > <= <]x.x...x)
|
|
15
|
+
* ...
|
|
16
|
+
* }
|
|
17
|
+
* ...
|
|
18
|
+
* }
|
|
19
|
+
* ...
|
|
20
|
+
* }
|
|
21
|
+
* ...
|
|
22
|
+
* }
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* matches({anyPlatform: {anyOS: {chrome: ''}}});
|
|
26
|
+
* matches({desktop: {windows: {chrome: '96.0.4664.110'}}});
|
|
27
|
+
* matches({desktop: {windows: {osVersion: '~10', engines: 'blink'}}});
|
|
28
|
+
* matches({desktop: {anyOS: {engines: {blink: '>90.5', gecko: '<=100'}}}});
|
|
29
|
+
* matches({anyPlatform: {ios: {chrome: '~96.1', safari: '>80'}}});
|
|
30
|
+
*
|
|
31
|
+
* @param condition - an object that has keys corresponding to platform names
|
|
32
|
+
* and values corresponding to objects that have keys corresponding to OS names
|
|
33
|
+
* and values corresponding to objects that have keys corresponding to browser names
|
|
34
|
+
* and values corresponding to browser versions
|
|
35
|
+
*/
|
|
36
|
+
export function matches(condition) {
|
|
37
|
+
let result = false;
|
|
38
|
+
forEachObj(condition, (oss, platform) => {
|
|
39
|
+
if (oss && (platform === 'anyPlatform' || platform === getPlatform())) {
|
|
40
|
+
forEachObj(oss, (browsers, osName) => {
|
|
41
|
+
const osVersion = browsers === null || browsers === void 0 ? void 0 : browsers.osVersion;
|
|
42
|
+
if (browsers && (osName === 'anyOS' || isOS(osName, osVersion))) {
|
|
43
|
+
result = matchesWithBrowsers(exclude(browsers, 'osVersion'));
|
|
44
|
+
}
|
|
45
|
+
return result && INTERRUPT;
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
return result && INTERRUPT;
|
|
49
|
+
});
|
|
50
|
+
return result;
|
|
51
|
+
}
|
|
52
|
+
//# sourceMappingURL=matches.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"matches.js","sourceRoot":"","sources":["../../../../package/src/env/matches/matches.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,SAAS,EAAC,MAAM,QAAQ,CAAC;AACjC,OAAO,EAAC,OAAO,EAAE,UAAU,EAAC,MAAM,WAAW,CAAC;AAC9C,OAAO,EAAC,WAAW,EAAE,IAAI,EAAE,mBAAmB,EAAqB,MAAM,KAAK,CAAC;AAE/E;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,MAAM,UAAU,OAAO,CAAC,SAA6B;IACnD,IAAI,MAAM,GAAG,KAAK,CAAC;IAEnB,UAAU,CAAC,SAAS,EAAE,CAAC,GAAG,EAAE,QAAQ,EAAE,EAAE;QACtC,IAAI,GAAG,IAAI,CAAC,QAAQ,KAAK,aAAa,IAAI,QAAQ,KAAK,WAAW,EAAE,CAAC,EAAE;YACrE,UAAU,CAAC,GAAG,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,EAAE;gBACnC,MAAM,SAAS,GAAG,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAE,SAAS,CAAC;gBACtC,IAAI,QAAQ,IAAI,CAAC,MAAM,KAAK,OAAO,IAAI,IAAI,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC,EAAE;oBAC/D,MAAM,GAAG,mBAAmB,CAAC,OAAO,CAAC,QAAQ,EAAE,WAAW,CAAC,CAAC,CAAC;iBAC9D;gBACD,OAAO,MAAM,IAAI,SAAS,CAAC;YAC7B,CAAC,CAAC,CAAC;SACJ;QAED,OAAO,MAAM,IAAI,SAAS,CAAC;IAC7B,CAAC,CAAC,CAAC;IAEH,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { BrowsersCondition } from '../';
|
|
2
|
+
/**
|
|
3
|
+
* Checks if a current browser matches a specific set of browsers
|
|
4
|
+
*
|
|
5
|
+
* Condition structure:
|
|
6
|
+
* {
|
|
7
|
+
* browserName?: versionCondition(x.x...x | [~ >= > <= <]x.x...x),
|
|
8
|
+
* engines?: engineName | {
|
|
9
|
+
* engineNane: versionCondition(x.x...x | [~ >= > <= <]x.x...x)
|
|
10
|
+
* ...
|
|
11
|
+
* }
|
|
12
|
+
* ...
|
|
13
|
+
* }
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* matchesWithBrowsers({firefox: '>=95.5', chrome: '~96.0.4664'});
|
|
17
|
+
* matchesWithBrowsers({engines: 'gecko', firefox: '>100.1'});
|
|
18
|
+
* matchesWithBrowsers({engines: {blink: '~96', gecko: '110.5.0'}, firefox: '>100.1'});
|
|
19
|
+
*
|
|
20
|
+
* @param condition - an object that has keys corresponding to browser names
|
|
21
|
+
* and values corresponding to browser version conditions
|
|
22
|
+
*/
|
|
23
|
+
export declare function matchesWithBrowsers(condition: BrowsersCondition): boolean;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { INTERRUPT, isObject, isString } from '../../';
|
|
2
|
+
import { forEachObj } from '../../obj';
|
|
3
|
+
import { getEngine, isBrowser, isEngine } from '../';
|
|
4
|
+
/**
|
|
5
|
+
* Checks if a current browser matches a specific set of browsers
|
|
6
|
+
*
|
|
7
|
+
* Condition structure:
|
|
8
|
+
* {
|
|
9
|
+
* browserName?: versionCondition(x.x...x | [~ >= > <= <]x.x...x),
|
|
10
|
+
* engines?: engineName | {
|
|
11
|
+
* engineNane: versionCondition(x.x...x | [~ >= > <= <]x.x...x)
|
|
12
|
+
* ...
|
|
13
|
+
* }
|
|
14
|
+
* ...
|
|
15
|
+
* }
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* matchesWithBrowsers({firefox: '>=95.5', chrome: '~96.0.4664'});
|
|
19
|
+
* matchesWithBrowsers({engines: 'gecko', firefox: '>100.1'});
|
|
20
|
+
* matchesWithBrowsers({engines: {blink: '~96', gecko: '110.5.0'}, firefox: '>100.1'});
|
|
21
|
+
*
|
|
22
|
+
* @param condition - an object that has keys corresponding to browser names
|
|
23
|
+
* and values corresponding to browser version conditions
|
|
24
|
+
*/
|
|
25
|
+
export function matchesWithBrowsers(condition) {
|
|
26
|
+
let result = false;
|
|
27
|
+
forEachObj(condition, (enginesOrVer, browser) => {
|
|
28
|
+
if (browser === 'engines') {
|
|
29
|
+
const { name } = getEngine();
|
|
30
|
+
const engines = enginesOrVer;
|
|
31
|
+
if (isObject(engines)) {
|
|
32
|
+
forEachObj(engines, (version, engine) => {
|
|
33
|
+
if (isEngine(engine, version)) {
|
|
34
|
+
result = true;
|
|
35
|
+
}
|
|
36
|
+
return result && INTERRUPT;
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
else if (isString(engines) && engines === name) {
|
|
40
|
+
result = true;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
const version = enginesOrVer;
|
|
45
|
+
if (isBrowser(browser, version)) {
|
|
46
|
+
result = true;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return result && INTERRUPT;
|
|
50
|
+
});
|
|
51
|
+
return result;
|
|
52
|
+
}
|
|
53
|
+
//# sourceMappingURL=matches-with-browsers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"matches-with-browsers.js","sourceRoot":"","sources":["../../../../package/src/env/matches-with-browsers/matches-with-browsers.ts"],"names":[],"mappings":"AAAA,OAAO,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
4
|
+
* @param condition - version condition in the format: x.x...x | [~ >= > <= <]x.x...x
|
|
5
|
+
*/
|
|
6
|
+
export declare function matchesWithVersion(version: string, condition: string): boolean;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { INTERRUPT } from '../../';
|
|
2
|
+
import { forEachArr } from '../../arr';
|
|
3
|
+
/**
|
|
4
|
+
* Checks if a specific version matches a version condition
|
|
5
|
+
* @param version - any browser or OS version, for example: x.x...x
|
|
6
|
+
* @param condition - version condition in the format: x.x...x | [~ >= > <= <]x.x...x
|
|
7
|
+
*/
|
|
8
|
+
export function matchesWithVersion(version, condition) {
|
|
9
|
+
let result = 0;
|
|
10
|
+
const versionParts = version.split('.');
|
|
11
|
+
const conditionParts = condition.split('.');
|
|
12
|
+
const matches = conditionParts[0].match(/^([~><=]*)(\d+)$/i);
|
|
13
|
+
const operator = matches && matches.length ? matches[1] : '';
|
|
14
|
+
conditionParts[0] = matches && matches.length ? matches[2] : '0';
|
|
15
|
+
forEachArr(conditionParts, (part, index) => {
|
|
16
|
+
const a = Number(versionParts[index]);
|
|
17
|
+
const b = Number(part);
|
|
18
|
+
switch (operator) {
|
|
19
|
+
case '~':
|
|
20
|
+
result = a === b ? 1 : -1;
|
|
21
|
+
return result !== -1 || INTERRUPT;
|
|
22
|
+
case '>':
|
|
23
|
+
result = a === b ? 0 : (a > b ? 1 : -1);
|
|
24
|
+
return result === 0 || INTERRUPT;
|
|
25
|
+
case '>=':
|
|
26
|
+
result = a === b || a > b ? 1 : -1;
|
|
27
|
+
return (result !== -1 && !(a > b)) || INTERRUPT;
|
|
28
|
+
case '<':
|
|
29
|
+
result = a === b ? 0 : (a < b ? 1 : -1);
|
|
30
|
+
return result === 0 || INTERRUPT;
|
|
31
|
+
case '<=':
|
|
32
|
+
result = a === b || a < b ? 1 : -1;
|
|
33
|
+
return (result !== -1 && !(a < b)) || INTERRUPT;
|
|
34
|
+
default:
|
|
35
|
+
result = a === b && versionParts.length === conditionParts.length ? 1 : -1;
|
|
36
|
+
return result !== -1 || INTERRUPT;
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
return result === 1;
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=matches-with-version.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"matches-with-version.js","sourceRoot":"","sources":["../../../../package/src/env/matches-with-version/matches-with-version.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,SAAS,EAAC,MAAM,QAAQ,CAAC;AACjC,OAAO,EAAC,UAAU,EAAC,MAAM,WAAW,CAAC;AAErC;;;;GAIG;AACH,MAAM,UAAU,kBAAkB,CAAC,OAAe,EAAE,SAAiB;IACnE,IAAI,MAAM,GAAG,CAAC,CAAC;IACf,MAAM,YAAY,GAAG,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IACxC,MAAM,cAAc,GAAG,SAAS,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAC5C,MAAM,OAAO,GAAG,cAAc,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,mBAAmB,CAAC,CAAC;IAC7D,MAAM,QAAQ,GAAG,OAAO,IAAI,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;IAC7D,cAAc,CAAC,CAAC,CAAC,GAAG,OAAO,IAAI,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC;IAEjE,UAAU,CAAC,cAAc,EAAE,CAAC,IAAY,EAAE,KAAa,EAAE,EAAE;QACzD,MAAM,CAAC,GAAG,MAAM,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC,CAAC;QACtC,MAAM,CAAC,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC;QAEvB,QAAQ,QAAQ,EAAE;YAChB,KAAK,GAAG;gBACN,MAAM,GAAG,CAAC,KAAK,CAAC,CAAC,CAA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,OAAO,MAAM,KAAK,CAAC,CAAC,IAAI,SAAS,CAAC;SACrC;IACH,CAAC,CAAC,CAAC;IAEH,OAAO,MAAM,KAAK,CAAC,CAAC;AACtB,CAAC"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { isArray, isFunction, isRegExp, isString, isUndefined } from '../../';
|
|
2
|
+
import { getUserAgent } from '../';
|
|
3
|
+
/*
|
|
4
|
+
* Functions for internal use
|
|
5
|
+
*/
|
|
6
|
+
let bot = null;
|
|
7
|
+
const botConditions = ['googlebot', 'bingbot', 'yandexbot', 'slurp'];
|
|
8
|
+
/*
|
|
9
|
+
* @private
|
|
10
|
+
* For internal use
|
|
11
|
+
*/
|
|
12
|
+
export function getBot() {
|
|
13
|
+
return bot !== null && bot !== void 0 ? bot : (bot = getEnvData(botConditions));
|
|
14
|
+
}
|
|
15
|
+
/*
|
|
16
|
+
* @private
|
|
17
|
+
* For internal use
|
|
18
|
+
*/
|
|
19
|
+
export function resetBot() {
|
|
20
|
+
bot = null;
|
|
21
|
+
}
|
|
22
|
+
/*
|
|
23
|
+
* @private
|
|
24
|
+
* For internal use
|
|
25
|
+
*/
|
|
26
|
+
export function getEnvData(conditions, needVersion = false) {
|
|
27
|
+
const agent = getUserAgent();
|
|
28
|
+
const result = {
|
|
29
|
+
name: 'unknown',
|
|
30
|
+
version: '',
|
|
31
|
+
major: '',
|
|
32
|
+
};
|
|
33
|
+
for (const condition of conditions) {
|
|
34
|
+
// eslint-disable-next-line prefer-const
|
|
35
|
+
let [name, test, ver] = isString(condition) ? [condition] : condition;
|
|
36
|
+
const tests = isArray(test) ? test : (isUndefined(test) ? [name] : [test]);
|
|
37
|
+
if (needVersion) {
|
|
38
|
+
ver = isUndefined(ver) ? getVerRegExp(isString(test) ? test : name) : (isString(ver) ? getVerRegExp(ver) : ver);
|
|
39
|
+
}
|
|
40
|
+
for (let test of tests) {
|
|
41
|
+
if (isString(test)) {
|
|
42
|
+
test = getTestRegExp(test);
|
|
43
|
+
}
|
|
44
|
+
if ((isFunction(test) && test()) || (isRegExp(test) && agent.search(test) > -1)) {
|
|
45
|
+
result.name = name;
|
|
46
|
+
if (needVersion && isRegExp(ver)) {
|
|
47
|
+
const matches = agent.match(ver);
|
|
48
|
+
result.version = (matches && matches.length > 1 && matches[1]) || '';
|
|
49
|
+
result.version = result.version.trim().replace(/[\s_-]+/g, '.');
|
|
50
|
+
if (result.version) {
|
|
51
|
+
result.major = result.version.split('.')[0];
|
|
52
|
+
return result;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return result;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return result;
|
|
60
|
+
}
|
|
61
|
+
function getTestRegExp(name) {
|
|
62
|
+
return new RegExp(name, 'i');
|
|
63
|
+
}
|
|
64
|
+
function getVerRegExp(name) {
|
|
65
|
+
return new RegExp(`${name}(?:[\\s:;/-]?ver(?:sion)?)?[\\s:/-]?(\\d+(?:[_.-]\\d+)*)`, 'i');
|
|
66
|
+
}
|
|
67
|
+
//# sourceMappingURL=private.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"private.js","sourceRoot":"","sources":["../../../../package/src/env/private/private.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,QAAQ,EAAE,WAAW,EAAC,MAAM,QAAQ,CAAC;AAC5E,OAAO,EAAiC,YAAY,EAAC,MAAM,KAAK,CAAC;AAEjE;;GAEG;AAEH,IAAI,GAAG,GAAmB,IAAI,CAAC;AAE/B,MAAM,aAAa,GAAmB,CAAC,WAAW,EAAE,SAAS,EAAE,WAAW,EAAE,OAAO,CAAC,CAAC;AAErF;;;GAGG;AACH,MAAM,UAAU,MAAM;IACpB,OAAO,GAAG,aAAH,GAAG,cAAH,GAAG,IAAH,GAAG,GAAc,UAAU,CAAC,aAAa,CAAC,EAAC;AACpD,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU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AC,IAAI,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE;gBAC/E,MAAM,CAAC,IAAI,GAAQ,IAAI,CAAC;gBAExB,IAAI,WAAW,IAAI,QAAQ,CAAC,GAAG,CAAC,EAAE;oBAChC,MAAM,OAAO,GAAG,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;oBACjC,MAAM,CAAC,OAAO,GAAG,CAAC,OAAO,IAAI,OAAO,CAAC,MAAM,GAAG,CAAC,IAAI,OAAO,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;oBACrE,MAAM,CAAC,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC,OAAO,CAAC,UAAU,EAAE,GAAG,CAAC,CAAC;oBAEhE,IAAI,MAAM,CAAC,OAAO,EAAE;wBAClB,MAAM,CAAC,KAAK,GAAG,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;wBAC5C,OAAO,MAAM,CAAC;qBACf;iBACF;gBAED,OAAO,MAAM,CAAC;aACf;SACF;KACF;IAED,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,SAAS,aAAa,CAAC,IAAY;IACjC,OAAO,IAAI,MAAM,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;AAC/B,CAAC;AAED,SAAS,YAAY,CAAC,IAAY;IAChC,OAAO,IAAI,MAAM,CAAC,GAAG,IAAI,0DAA0D,EAAE,GAAG,CAAC,CAAC;AAC5F,CAAC"}
|
package/env/types.d.ts
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Represents supported bot names
|
|
3
|
+
*/
|
|
4
|
+
export declare type BotNames = 'googlebot' | 'bingbot' | 'yandexbot' | 'slurp' | 'unknown';
|
|
5
|
+
/**
|
|
6
|
+
* Represents supported platform names
|
|
7
|
+
*/
|
|
8
|
+
export declare type PlatformNames = 'tv' | 'desktop' | 'tablet' | 'mobile' | BotNames;
|
|
9
|
+
/**
|
|
10
|
+
* Represents supported OS names
|
|
11
|
+
*/
|
|
12
|
+
export declare type OSNames = 'xbox' | 'windows' | 'ios' | 'macOS' | 'webOS' | 'tizen' | 'appleTV' | 'roku' | 'chromeOS' | 'playstation4' | 'playstation5' | 'nintendoSwitch' | 'likeAndroid' | 'android' | 'linux' | BotNames;
|
|
13
|
+
/**
|
|
14
|
+
* Represents supported engine names
|
|
15
|
+
*/
|
|
16
|
+
export declare type EngineNames = 'blink' | 'webkit' | 'gecko' | BotNames;
|
|
17
|
+
/**
|
|
18
|
+
* Represents supported browser names
|
|
19
|
+
*/
|
|
20
|
+
export declare type BrowserNames = 'opera' | 'operaCoast' | 'operaTouch' | 'samsung' | 'mz' | 'yandex' | 'uc' | 'maxthon' | 'kmeleon' | 'wechat' | 'qqLite' | 'qq' | 'edge' | 'sailfish' | 'webOS' | 'tizen' | 'miui' | 'silk' | 'phantomjs' | 'slimerjs' | 'qupzilla' | 'electron' | 'whale' | 'focus' | 'swing' | 'epiphany' | 'puffin' | 'sleipnir' | 'vivaldi' | 'seamonkey' | 'playstation4' | 'playstation5' | 'googleSearch' | 'firefox' | 'chrome' | 'android' | 'safari' | BotNames;
|
|
21
|
+
/**
|
|
22
|
+
* Represents a version data
|
|
23
|
+
*/
|
|
24
|
+
export interface VersionData {
|
|
25
|
+
/**
|
|
26
|
+
* Full version
|
|
27
|
+
*/
|
|
28
|
+
version: string;
|
|
29
|
+
/**
|
|
30
|
+
* Major version (first number)
|
|
31
|
+
*/
|
|
32
|
+
major: string;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Represents the returned data by the getOS function
|
|
36
|
+
*/
|
|
37
|
+
export interface OSData extends VersionData {
|
|
38
|
+
/**
|
|
39
|
+
* Unique name of the OS
|
|
40
|
+
*/
|
|
41
|
+
name: OSNames;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Represents the returned data by the getEngine function
|
|
45
|
+
*/
|
|
46
|
+
export interface EngineData extends VersionData {
|
|
47
|
+
/**
|
|
48
|
+
* Unique name of the browser engine
|
|
49
|
+
*/
|
|
50
|
+
name: EngineNames;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Represents the returned data by the getBrowser function
|
|
54
|
+
*/
|
|
55
|
+
export interface BrowserData extends VersionData {
|
|
56
|
+
/**
|
|
57
|
+
* Unique name of the browser
|
|
58
|
+
*/
|
|
59
|
+
name: BrowserNames;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Represents an object that have keys corresponding to engine names and values corresponding to engine versions
|
|
63
|
+
*/
|
|
64
|
+
export declare type EnginesCondition = {
|
|
65
|
+
[key in EngineNames]?: string;
|
|
66
|
+
};
|
|
67
|
+
/**
|
|
68
|
+
* Represents an object that have keys corresponding to browser names and values corresponding to browser versions,
|
|
69
|
+
* and may have an engine property with the engines condition
|
|
70
|
+
*/
|
|
71
|
+
export declare type BrowsersCondition = {
|
|
72
|
+
[key in BrowserNames]?: string;
|
|
73
|
+
} & {
|
|
74
|
+
engines?: EngineNames | EnginesCondition;
|
|
75
|
+
};
|
|
76
|
+
/**
|
|
77
|
+
* Represents the browsers condition with an optional osVersion property
|
|
78
|
+
*/
|
|
79
|
+
export declare type OSBrowsersCondition = BrowsersCondition & {
|
|
80
|
+
osVersion?: string;
|
|
81
|
+
};
|
|
82
|
+
/**
|
|
83
|
+
* Represents an object that have keys corresponding to OS names and values corresponding to the OS browsers conditions
|
|
84
|
+
*/
|
|
85
|
+
export declare type OSCondition = {
|
|
86
|
+
[key in OSNames]?: OSBrowsersCondition;
|
|
87
|
+
} & {
|
|
88
|
+
anyOS?: OSBrowsersCondition;
|
|
89
|
+
};
|
|
90
|
+
/**
|
|
91
|
+
* Represents an object that have keys corresponding to platform names and values corresponding to the OS conditions
|
|
92
|
+
*/
|
|
93
|
+
export declare type PlatformsCondition = {
|
|
94
|
+
[key in PlatformNames]?: OSCondition;
|
|
95
|
+
} & {
|
|
96
|
+
anyPlatform?: OSCondition;
|
|
97
|
+
};
|
|
98
|
+
export interface BotData extends VersionData {
|
|
99
|
+
name: BotNames;
|
|
100
|
+
}
|
|
101
|
+
export interface EnvData extends VersionData {
|
|
102
|
+
name: PlatformNames | OSNames | EngineNames | BrowserNames;
|
|
103
|
+
}
|
|
104
|
+
export declare type EnvTest = string | RegExp | (() => boolean);
|
|
105
|
+
export declare type EnvTestGroup = EnvTest | EnvTest[];
|
|
106
|
+
export declare type EnvCondition = string | [string, EnvTestGroup] | [string, EnvTestGroup, string | RegExp];
|
package/env/types.js
ADDED
package/env/types.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../package/src/env/types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns user agent
|
|
3
|
+
*/
|
|
4
|
+
export declare function getUserAgent(): string;
|
|
5
|
+
/**
|
|
6
|
+
* If the global object is not a window, you can use this function to set up a stub user agent
|
|
7
|
+
* @param userAgent - any string with user agent data
|
|
8
|
+
*/
|
|
9
|
+
export declare function setUserAgent(userAgent: string): void;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { resetBrowser, resetEngine, resetOS, resetPlatform } from '../';
|
|
2
|
+
import { resetBot } from '../private/private';
|
|
3
|
+
let agent = typeof navigator === 'object' ? navigator.userAgent : '';
|
|
4
|
+
/**
|
|
5
|
+
* Returns user agent
|
|
6
|
+
*/
|
|
7
|
+
export function getUserAgent() {
|
|
8
|
+
return agent;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* If the global object is not a window, you can use this function to set up a stub user agent
|
|
12
|
+
* @param userAgent - any string with user agent data
|
|
13
|
+
*/
|
|
14
|
+
export function setUserAgent(userAgent) {
|
|
15
|
+
if (agent !== userAgent) {
|
|
16
|
+
resetBot();
|
|
17
|
+
resetOS();
|
|
18
|
+
resetEngine();
|
|
19
|
+
resetPlatform();
|
|
20
|
+
resetBrowser();
|
|
21
|
+
agent = userAgent;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=user-agent.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"user-agent.js","sourceRoot":"","sources":["../../../../package/src/env/user-agent/user-agent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,YAAY,EAAE,WAAW,EAAE,OAAO,EAAE,aAAa,EAAC,MAAM,KAAK,CAAC;AACtE,OAAO,EAAC,QAAQ,EAAC,MAAM,oBAAoB,CAAC;AAE5C,IAAI,KAAK,GAAG,OAAO,SAAS,KAAK,QAAQ,CAAC,CAAC,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC;AAErE;;GAEG;AACH,MAAM,UAAU,YAAY;IAC1B,OAAO,KAAK,CAAC;AACf,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,YAAY,CAAC,SAAiB;IAC5C,IAAI,KAAK,KAAK,SAAS,EAAE;QACvB,QAAQ,EAAE,CAAC;QACX,OAAO,EAAE,CAAC;QACV,WAAW,EAAE,CAAC;QACd,aAAa,EAAE,CAAC;QAChB,YAAY,EAAE,CAAC;QACf,KAAK,GAAG,SAAS,CAAC;KACnB;AACH,CAAC"}
|
package/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './common';
|
package/index.js
ADDED
package/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../package/src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Nullish } from '../../';
|
|
2
|
+
import { InRangeOptions } from '../';
|
|
3
|
+
/**
|
|
4
|
+
* Converts the numeric value to a new number according to the options
|
|
5
|
+
* @param value - numeric value
|
|
6
|
+
* @param options - options for converting the numeric value
|
|
7
|
+
*/
|
|
8
|
+
export declare function inRange(value: number | Nullish, options?: InRangeOptions): number | null;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { isNumber } from '../../';
|
|
2
|
+
import { round } from '../';
|
|
3
|
+
/**
|
|
4
|
+
* Converts the numeric value to a new number according to the options
|
|
5
|
+
* @param value - numeric value
|
|
6
|
+
* @param options - options for converting the numeric value
|
|
7
|
+
*/
|
|
8
|
+
export function inRange(value, options = {}) {
|
|
9
|
+
let newValue = isNumber(value) ? (isNumber(options.precision) ? round(value, options.precision) : value) : null;
|
|
10
|
+
if (isNumber(newValue)) {
|
|
11
|
+
if (isNumber(options.min) && newValue < options.min) {
|
|
12
|
+
newValue = options.min;
|
|
13
|
+
}
|
|
14
|
+
if (isNumber(options.max) && newValue > options.max) {
|
|
15
|
+
newValue = options.max;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
else if (options.required) {
|
|
19
|
+
newValue = options.min || (isNumber(options.max) && options.max < 0 ? options.max : 0);
|
|
20
|
+
}
|
|
21
|
+
return newValue;
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=in-range.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"in-range.js","sourceRoot":"","sources":["../../../../package/src/num/in-range/in-range.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,QAAQ,EAAU,MAAM,QAAQ,CAAC;AACzC,OAAO,EAAC,KAAK,EAAiB,MAAM,KAAK,CAAC;AAE1C;;;;GAIG;AACH,MAAM,UAAU,OAAO,CAAC,KAAuB,EAAE,UAA0B,EAAE;IAC3E,IAAI,QAAQ,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,EAAE,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;IAEhH,IAAI,QAAQ,CAAC,QAAQ,CAAC,EAAE;QACtB,IAAI,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,QAAQ,GAAG,OAAO,CAAC,GAAG,EAAE;YACnD,QAAQ,GAAG,OAAO,CAAC,GAAG,CAAC;SACxB;QAED,IAAI,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,QAAQ,GAAG,OAAO,CAAC,GAAG,EAAE;YACnD,QAAQ,GAAG,OAAO,CAAC,GAAG,CAAC;SACxB;KACF;SAAM,IAAI,OAAO,CAAC,QAAQ,EAAE;QAC3B,QAAQ,GAAG,OAAO,CAAC,GAAG,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,OAAO,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;KACxF;IAED,OAAO,QAAQ,CAAC;AAClB,CAAC"}
|
package/num/index.d.ts
ADDED
package/num/index.js
ADDED
package/num/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../package/src/num/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,cAAc,eAAe,CAAC;AAC9B,cAAc,qBAAqB,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Rounds a numeric value to a number with a specified number of decimal places
|
|
3
|
+
* and replaces NaN and Infinity with 0
|
|
4
|
+
* @param value - numeric value
|
|
5
|
+
* @param precision - number of decimal places, default 0
|
|
6
|
+
*/
|
|
7
|
+
export declare function round(value: number, precision?: number): number;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Rounds a numeric value to a number with a specified number of decimal places
|
|
3
|
+
* and replaces NaN and Infinity with 0
|
|
4
|
+
* @param value - numeric value
|
|
5
|
+
* @param precision - number of decimal places, default 0
|
|
6
|
+
*/
|
|
7
|
+
export function round(value, precision = 0) {
|
|
8
|
+
const num = Number(value.toFixed(precision));
|
|
9
|
+
return isFinite(num) ? num : 0;
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=round.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"round.js","sourceRoot":"","sources":["../../../../package/src/num/round/round.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,UAAU,KAAK,CAAC,KAAa,EAAE,SAAS,GAAG,CAAC;IAChD,MAAM,GAAG,GAAG,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC;IAC7C,OAAO,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;AACjC,CAAC"}
|
package/num/types.d.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Represents options type for the inRange function
|
|
3
|
+
*/
|
|
4
|
+
export interface InRangeOptions {
|
|
5
|
+
/**
|
|
6
|
+
* If the minimum is specified and the value is less than the minimum,
|
|
7
|
+
* the value will be replaced with the minimum
|
|
8
|
+
*/
|
|
9
|
+
min?: number;
|
|
10
|
+
/**
|
|
11
|
+
* If the maximum is specified and the value is greater than the maximum,
|
|
12
|
+
* the value will be replaced with the maximum
|
|
13
|
+
*/
|
|
14
|
+
max?: number;
|
|
15
|
+
/**
|
|
16
|
+
* If the precision is specified, the value will be rounded to the number of decimal places
|
|
17
|
+
*/
|
|
18
|
+
precision?: number;
|
|
19
|
+
/**
|
|
20
|
+
* If true, the empty value will be replaced with
|
|
21
|
+
* either the defined minimum or defined maximum if the maximum is less than 0 or 0
|
|
22
|
+
*/
|
|
23
|
+
required?: boolean;
|
|
24
|
+
}
|
package/num/types.js
ADDED
package/num/types.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../package/src/num/types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constant.js","sourceRoot":"","sources":["../../../../package/src/obj/constant/constant.ts"],"names":[],"mappings":"AAEA;;;GAGG;AACH,MAAM,UAAU,QAAQ,CAAgB,GAAM;IAC5C,OAAO,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;AAC5B,CAAC"}
|