@bitfiber/utils 1.0.1 → 1.0.3
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/LICENSE.txt +1 -1
- package/README.md +1 -1
- package/dist/arr/at/at.js.map +1 -0
- package/{arr → dist/arr}/cnd/cnd.d.ts +63 -1
- package/{arr → dist/arr}/cnd/cnd.js +1 -1
- package/dist/arr/cnd/cnd.js.map +1 -0
- package/dist/arr/diff-arr/diff-arr.d.ts +30 -0
- package/dist/arr/diff-arr/diff-arr.js.map +1 -0
- package/dist/arr/fill/fill.js.map +1 -0
- package/{arr → dist/arr}/for-each-arr/for-each-arr.d.ts +1 -1
- package/{arr → dist/arr}/for-each-arr/for-each-arr.js +1 -1
- package/dist/arr/for-each-arr/for-each-arr.js.map +1 -0
- package/{arr → dist/arr}/index-by/index-by.d.ts +1 -1
- package/{arr → dist/arr}/index-by/index-by.js +1 -1
- package/dist/arr/index-by/index-by.js.map +1 -0
- package/dist/arr/index.d.ts +8 -0
- package/dist/arr/index.js +9 -0
- package/dist/arr/index.js.map +1 -0
- package/{arr → dist/arr}/pluck/pluck.d.ts +1 -1
- package/dist/arr/pluck/pluck.js.map +1 -0
- package/dist/arr/within/within.js.map +1 -0
- package/dist/common/copy/copy.js.map +1 -0
- package/dist/common/equals/equals.js.map +1 -0
- package/{common → dist/common}/error.d.ts +7 -1
- package/dist/common/error.js.map +1 -0
- package/dist/common/for-each/for-each.js.map +1 -0
- package/dist/common/get-unique-num-id/get-unique-num-id.js.map +1 -0
- package/{common → dist/common}/get-unique-str-id/get-unique-str-id.js +1 -1
- package/dist/common/get-unique-str-id/get-unique-str-id.js.map +1 -0
- package/dist/common/has-iterator/has-iterator.js.map +1 -0
- package/dist/common/index.d.ts +17 -0
- package/dist/common/index.js +17 -0
- package/dist/common/index.js.map +1 -0
- package/dist/common/interrupt.d.ts +4 -0
- package/dist/common/interrupt.js +5 -0
- package/dist/common/interrupt.js.map +1 -0
- package/dist/common/is/is.js.map +1 -0
- package/dist/common/is-empty/is-empty.js.map +1 -0
- package/dist/common/random/random.js.map +1 -0
- package/dist/common/same/same.js.map +1 -0
- package/dist/common/stub/stub.js.map +1 -0
- package/dist/common/to-float/to-float.js.map +1 -0
- package/dist/common/to-int/to-int.js.map +1 -0
- package/dist/common/to-sorted-string/to-sorted-string.js.map +1 -0
- package/{common → dist/common}/types.d.ts +0 -11
- package/{arr → dist/common}/types.js.map +1 -1
- package/dist/dom/closest/closest.js.map +1 -0
- package/{dom → dist/dom}/document/document.js +1 -1
- package/dist/dom/document/document.js.map +1 -0
- package/{dom → dist/dom}/download-file/download-file.js +1 -1
- package/dist/dom/download-file/download-file.js.map +1 -0
- package/{dom → dist/dom}/for-each-elements/for-each-elements.js +1 -1
- package/dist/dom/for-each-elements/for-each-elements.js.map +1 -0
- package/{dom → dist/dom}/for-each-nodes/for-each-nodes.js +1 -1
- package/dist/dom/for-each-nodes/for-each-nodes.js.map +1 -0
- package/dist/dom/get-all-styles/get-all-styles.js.map +1 -0
- package/dist/dom/get-body/get-body.js.map +1 -0
- package/dist/dom/get-html/get-html.js.map +1 -0
- package/dist/dom/get-non-static-parent/get-non-static-parent.js.map +1 -0
- package/dist/dom/get-offset-from-doc/get-offset-from-doc.js.map +1 -0
- package/{dom → dist/dom}/get-offset-from-parent/get-offset-from-parent.js +1 -1
- package/dist/dom/get-offset-from-parent/get-offset-from-parent.js.map +1 -0
- package/dist/dom/get-offset-from-win/get-offset-from-win.js.map +1 -0
- package/dist/dom/get-scroll-width/get-scroll-width.js.map +1 -0
- package/dist/dom/get-style/get-style.js.map +1 -0
- package/{dom → dist/dom}/get-styles/get-styles.d.ts +1 -1
- package/dist/dom/get-styles/get-styles.js.map +1 -0
- package/{dom → dist/dom}/get-valid-style-name/get-valid-style-name.js +1 -1
- package/dist/dom/get-valid-style-name/get-valid-style-name.js.map +1 -0
- package/{dom → dist/dom}/get-window/get-window.js +1 -1
- package/dist/dom/get-window/get-window.js.map +1 -0
- package/dist/dom/has-name/has-name.js.map +1 -0
- package/dist/dom/index.d.ts +25 -0
- package/dist/dom/index.js +25 -0
- package/dist/dom/index.js.map +1 -0
- package/dist/dom/is-comment/is-comment.js.map +1 -0
- package/dist/dom/is-element/is-element.js.map +1 -0
- package/dist/dom/is-text/is-text.js.map +1 -0
- package/{dom → dist/dom}/set-offset-from-parent/set-offset-from-parent.js +1 -1
- package/dist/dom/set-offset-from-parent/set-offset-from-parent.js.map +1 -0
- package/dist/dom/set-style/set-style.js.map +1 -0
- package/{dom → dist/dom}/set-styles/set-styles.d.ts +1 -1
- package/dist/dom/set-styles/set-styles.js.map +1 -0
- package/{num → dist/dom}/types.js.map +1 -1
- package/{env → dist/env}/get-browser/get-browser.js +1 -1
- package/dist/env/get-browser/get-browser.js.map +1 -0
- package/{env → dist/env}/get-engine/get-engine.js +1 -1
- package/dist/env/get-engine/get-engine.js.map +1 -0
- package/{env → dist/env}/get-os/get-os.js +1 -1
- package/dist/env/get-os/get-os.js.map +1 -0
- package/{env → dist/env}/get-platform/get-platform.js +1 -1
- package/dist/env/get-platform/get-platform.js.map +1 -0
- package/dist/env/index.d.ts +21 -0
- package/dist/env/index.js +21 -0
- package/dist/env/index.js.map +1 -0
- package/dist/env/is-browser/is-browser.js.map +1 -0
- package/dist/env/is-chrome-like/is-chrome-like.js.map +1 -0
- package/dist/env/is-desktop/is-desktop.js.map +1 -0
- package/dist/env/is-engine/is-engine.js.map +1 -0
- package/dist/env/is-firefox-like/is-firefox-like.js.map +1 -0
- package/dist/env/is-mobile/is-mobile.js.map +1 -0
- package/dist/env/is-os/is-os.js.map +1 -0
- package/dist/env/is-portable/is-portable.js.map +1 -0
- package/dist/env/is-safari-like/is-safari-like.js.map +1 -0
- package/dist/env/is-stationary/is-stationary.js.map +1 -0
- package/dist/env/is-tablet/is-tablet.js.map +1 -0
- package/dist/env/is-tv/is-tv.js.map +1 -0
- package/{env → dist/env}/matches/matches.js +1 -1
- package/dist/env/matches/matches.js.map +1 -0
- package/{env → dist/env}/matches-with-browsers/matches-with-browsers.js +1 -1
- package/dist/env/matches-with-browsers/matches-with-browsers.js.map +1 -0
- package/{env → dist/env}/matches-with-version/matches-with-version.js +1 -1
- package/dist/env/matches-with-version/matches-with-version.js.map +1 -0
- package/{env → dist/env}/private/private.d.ts +1 -1
- package/{env → dist/env}/private/private.js +4 -4
- package/dist/env/private/private.js.map +1 -0
- package/{dom → dist/env}/types.js.map +1 -1
- package/{env → dist/env}/user-agent/user-agent.js +4 -1
- package/dist/env/user-agent/user-agent.js.map +1 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +8 -0
- package/dist/index.js.map +1 -0
- package/{num/types.d.ts → dist/num/in-range/in-range.d.ts} +7 -0
- package/{num → dist/num}/in-range/in-range.js +1 -1
- package/dist/num/in-range/in-range.js.map +1 -0
- package/dist/num/index.d.ts +2 -0
- package/dist/num/index.js +3 -0
- package/dist/num/index.js.map +1 -0
- package/dist/num/round/round.js.map +1 -0
- package/{obj → dist/obj}/constant/constant.d.ts +1 -1
- package/dist/obj/constant/constant.js.map +1 -0
- package/{obj → dist/obj}/deep-constant/deep-constant.d.ts +1 -1
- package/{obj → dist/obj}/deep-constant/deep-constant.js +1 -1
- package/dist/obj/deep-constant/deep-constant.js.map +1 -0
- package/{obj/types.d.ts → dist/obj/diff-obj/diff-obj.d.ts} +8 -1
- package/{obj → dist/obj}/diff-obj/diff-obj.js +1 -1
- package/dist/obj/diff-obj/diff-obj.js.map +1 -0
- package/{obj → dist/obj}/exclude/exclude.d.ts +1 -1
- package/{obj → dist/obj}/exclude/exclude.js +1 -1
- package/dist/obj/exclude/exclude.js.map +1 -0
- package/{obj → dist/obj}/extend/extend.d.ts +1 -1
- package/{obj → dist/obj}/extend/extend.js +1 -1
- package/dist/obj/extend/extend.js.map +1 -0
- package/{obj → dist/obj}/for-each-obj/for-each-obj.d.ts +1 -1
- package/{obj → dist/obj}/for-each-obj/for-each-obj.js +1 -1
- package/dist/obj/for-each-obj/for-each-obj.js.map +1 -0
- package/{obj → dist/obj}/has-own/has-own.d.ts +1 -1
- package/dist/obj/has-own/has-own.js.map +1 -0
- package/{obj → dist/obj}/include/include.d.ts +1 -1
- package/{obj → dist/obj}/include/include.js +1 -1
- package/dist/obj/include/include.js.map +1 -0
- package/dist/obj/index.d.ts +12 -0
- package/dist/obj/index.js +13 -0
- package/dist/obj/index.js.map +1 -0
- package/{obj → dist/obj}/keys/keys.d.ts +1 -1
- package/dist/obj/keys/keys.js.map +1 -0
- package/{obj → dist/obj}/map-obj/map-obj.d.ts +1 -1
- package/dist/obj/map-obj/map-obj.js.map +1 -0
- package/{obj → dist/obj}/map-obj-to-arr/map-obj-to-arr.d.ts +1 -1
- package/dist/obj/map-obj-to-arr/map-obj-to-arr.js.map +1 -0
- package/{obj → dist/obj}/values/values.d.ts +1 -1
- package/dist/obj/values/values.js.map +1 -0
- package/dist/str/index.d.ts +3 -0
- package/dist/str/index.js +4 -0
- package/dist/str/index.js.map +1 -0
- package/dist/str/to-camel-case/to-camel-case.js.map +1 -0
- package/dist/str/to-hash/to-hash.js.map +1 -0
- package/dist/str/with-capital/with-capital.js.map +1 -0
- package/package.json +71 -73
- package/src/arr/at/at.ts +10 -0
- package/src/arr/cnd/cnd.ts +188 -0
- package/src/arr/diff-arr/diff-arr.ts +66 -0
- package/src/arr/fill/fill.ts +10 -0
- package/src/arr/for-each-arr/for-each-arr.ts +25 -0
- package/src/arr/index-by/index-by.ts +19 -0
- package/src/arr/index.ts +11 -0
- package/src/arr/pluck/pluck.ts +14 -0
- package/src/arr/within/within.ts +14 -0
- package/src/common/copy/copy.ts +89 -0
- package/src/common/equals/equals.ts +142 -0
- package/src/common/error.ts +34 -0
- package/src/common/for-each/for-each.ts +36 -0
- package/src/common/get-unique-num-id/get-unique-num-id.ts +8 -0
- package/src/common/get-unique-str-id/get-unique-str-id.ts +18 -0
- package/src/common/has-iterator/has-iterator.ts +7 -0
- package/src/common/index.ts +23 -0
- package/{common/types.js → src/common/interrupt.ts} +0 -1
- package/src/common/is/is.ts +244 -0
- package/src/common/is-empty/is-empty.ts +26 -0
- package/src/common/random/random.ts +8 -0
- package/src/common/same/same.ts +8 -0
- package/src/common/stub/stub.ts +7 -0
- package/src/common/to-float/to-float.ts +10 -0
- package/src/common/to-int/to-int.ts +10 -0
- package/src/common/to-sorted-string/to-sorted-string.ts +58 -0
- package/src/common/types.ts +66 -0
- package/src/dom/closest/closest.ts +24 -0
- package/src/dom/document/document.ts +25 -0
- package/src/dom/download-file/download-file.ts +31 -0
- package/src/dom/for-each-elements/for-each-elements.ts +17 -0
- package/src/dom/for-each-nodes/for-each-nodes.ts +15 -0
- package/src/dom/get-all-styles/get-all-styles.ts +10 -0
- package/src/dom/get-body/get-body.ts +9 -0
- package/src/dom/get-html/get-html.ts +9 -0
- package/src/dom/get-non-static-parent/get-non-static-parent.ts +9 -0
- package/src/dom/get-offset-from-doc/get-offset-from-doc.ts +18 -0
- package/src/dom/get-offset-from-parent/get-offset-from-parent.ts +48 -0
- package/src/dom/get-offset-from-win/get-offset-from-win.ts +9 -0
- package/src/dom/get-scroll-width/get-scroll-width.ts +33 -0
- package/src/dom/get-style/get-style.ts +25 -0
- package/src/dom/get-styles/get-styles.ts +14 -0
- package/src/dom/get-valid-style-name/get-valid-style-name.ts +45 -0
- package/src/dom/get-window/get-window.ts +17 -0
- package/src/dom/has-name/has-name.ts +8 -0
- package/src/dom/index.ts +25 -0
- package/src/dom/is-comment/is-comment.ts +7 -0
- package/src/dom/is-element/is-element.ts +7 -0
- package/src/dom/is-text/is-text.ts +7 -0
- package/src/dom/set-offset-from-parent/set-offset-from-parent.ts +46 -0
- package/src/dom/set-style/set-style.ts +14 -0
- package/src/dom/set-styles/set-styles.ts +17 -0
- package/src/dom/types.ts +20 -0
- package/src/env/get-browser/get-browser.ts +38 -0
- package/src/env/get-engine/get-engine.ts +27 -0
- package/src/env/get-os/get-os.ts +31 -0
- package/src/env/get-platform/get-platform.ts +34 -0
- package/src/env/index.ts +24 -0
- package/src/env/is-browser/is-browser.ts +15 -0
- package/src/env/is-chrome-like/is-chrome-like.ts +9 -0
- package/src/env/is-desktop/is-desktop.ts +9 -0
- package/src/env/is-engine/is-engine.ts +12 -0
- package/src/env/is-firefox-like/is-firefox-like.ts +9 -0
- package/src/env/is-mobile/is-mobile.ts +9 -0
- package/src/env/is-os/is-os.ts +13 -0
- package/src/env/is-portable/is-portable.ts +8 -0
- package/src/env/is-safari-like/is-safari-like.ts +9 -0
- package/src/env/is-stationary/is-stationary.ts +8 -0
- package/src/env/is-tablet/is-tablet.ts +9 -0
- package/src/env/is-tv/is-tv.ts +9 -0
- package/src/env/matches/matches.ts +55 -0
- package/src/env/matches-with-browsers/matches-with-browsers.ts +55 -0
- package/src/env/matches-with-version/matches-with-version.ts +44 -0
- package/src/env/private/private.ts +82 -0
- package/src/env/types.ts +146 -0
- package/src/env/user-agent/user-agent.ts +29 -0
- package/src/index.ts +7 -0
- package/src/num/in-range/in-range.ts +54 -0
- package/src/num/index.ts +2 -0
- package/src/num/round/round.ts +10 -0
- package/src/obj/constant/constant.ts +9 -0
- package/src/obj/deep-constant/deep-constant.ts +20 -0
- package/src/obj/diff-obj/diff-obj.ts +87 -0
- package/src/obj/exclude/exclude.ts +18 -0
- package/src/obj/extend/extend.ts +54 -0
- package/src/obj/for-each-obj/for-each-obj.ts +17 -0
- package/src/obj/has-own/has-own.ts +12 -0
- package/src/obj/include/include.ts +17 -0
- package/src/obj/index.ts +12 -0
- package/src/obj/keys/keys.ts +9 -0
- package/src/obj/map-obj/map-obj.ts +14 -0
- package/src/obj/map-obj-to-arr/map-obj-to-arr.ts +14 -0
- package/src/obj/values/values.ts +12 -0
- package/src/str/index.ts +3 -0
- package/src/str/to-camel-case/to-camel-case.ts +17 -0
- package/src/str/to-hash/to-hash.ts +21 -0
- package/src/str/with-capital/with-capital.ts +8 -0
- package/arr/at/at.js.map +0 -1
- package/arr/cnd/cnd.js.map +0 -1
- package/arr/diff-arr/diff-arr.d.ts +0 -10
- package/arr/diff-arr/diff-arr.js.map +0 -1
- package/arr/fill/fill.js.map +0 -1
- package/arr/for-each-arr/for-each-arr.js.map +0 -1
- package/arr/index-by/index-by.js.map +0 -1
- package/arr/index.d.ts +0 -9
- package/arr/index.js +0 -10
- package/arr/index.js.map +0 -1
- package/arr/pluck/pluck.js.map +0 -1
- package/arr/types.d.ts +0 -84
- package/arr/within/within.js.map +0 -1
- package/common/copy/copy.js.map +0 -1
- package/common/equals/equals.js.map +0 -1
- package/common/error.js.map +0 -1
- package/common/for-each/for-each.js.map +0 -1
- package/common/get-unique-num-id/get-unique-num-id.js.map +0 -1
- package/common/get-unique-str-id/get-unique-str-id.js.map +0 -1
- package/common/has-iterator/has-iterator.js.map +0 -1
- package/common/index.d.ts +0 -16
- package/common/index.js +0 -17
- package/common/index.js.map +0 -1
- package/common/is/is.js.map +0 -1
- package/common/is-empty/is-empty.js.map +0 -1
- package/common/random/random.js.map +0 -1
- package/common/same/same.js.map +0 -1
- package/common/stub/stub.js.map +0 -1
- package/common/to-float/to-float.js.map +0 -1
- package/common/to-int/to-int.js.map +0 -1
- package/common/to-sorted-string/to-sorted-string.js.map +0 -1
- package/common/types.js.map +0 -1
- package/dom/closest/closest.js.map +0 -1
- package/dom/document/document.js.map +0 -1
- package/dom/download-file/download-file.js.map +0 -1
- package/dom/for-each-elements/for-each-elements.js.map +0 -1
- package/dom/for-each-nodes/for-each-nodes.js.map +0 -1
- package/dom/get-all-styles/get-all-styles.js.map +0 -1
- package/dom/get-body/get-body.js.map +0 -1
- package/dom/get-html/get-html.js.map +0 -1
- package/dom/get-non-static-parent/get-non-static-parent.js.map +0 -1
- package/dom/get-offset-from-doc/get-offset-from-doc.js.map +0 -1
- package/dom/get-offset-from-parent/get-offset-from-parent.js.map +0 -1
- package/dom/get-offset-from-win/get-offset-from-win.js.map +0 -1
- package/dom/get-scroll-width/get-scroll-width.js.map +0 -1
- package/dom/get-style/get-style.js.map +0 -1
- package/dom/get-styles/get-styles.js.map +0 -1
- package/dom/get-valid-style-name/get-valid-style-name.js.map +0 -1
- package/dom/get-window/get-window.js.map +0 -1
- package/dom/has-name/has-name.js.map +0 -1
- package/dom/index.d.ts +0 -25
- package/dom/index.js +0 -26
- package/dom/index.js.map +0 -1
- package/dom/is-comment/is-comment.js.map +0 -1
- package/dom/is-element/is-element.js.map +0 -1
- package/dom/is-text/is-text.js.map +0 -1
- package/dom/set-offset-from-parent/set-offset-from-parent.js.map +0 -1
- package/dom/set-style/set-style.js.map +0 -1
- package/dom/set-styles/set-styles.js.map +0 -1
- package/env/get-browser/get-browser.js.map +0 -1
- package/env/get-engine/get-engine.js.map +0 -1
- package/env/get-os/get-os.js.map +0 -1
- package/env/get-platform/get-platform.js.map +0 -1
- package/env/index.d.ts +0 -21
- package/env/index.js +0 -22
- package/env/index.js.map +0 -1
- package/env/is-browser/is-browser.js.map +0 -1
- package/env/is-chrome-like/is-chrome-like.js.map +0 -1
- package/env/is-desktop/is-desktop.js.map +0 -1
- package/env/is-engine/is-engine.js.map +0 -1
- package/env/is-firefox-like/is-firefox-like.js.map +0 -1
- package/env/is-mobile/is-mobile.js.map +0 -1
- package/env/is-os/is-os.js.map +0 -1
- package/env/is-portable/is-portable.js.map +0 -1
- package/env/is-safari-like/is-safari-like.js.map +0 -1
- package/env/is-stationary/is-stationary.js.map +0 -1
- package/env/is-tablet/is-tablet.js.map +0 -1
- package/env/is-tv/is-tv.js.map +0 -1
- package/env/matches/matches.js.map +0 -1
- package/env/matches-with-browsers/matches-with-browsers.js.map +0 -1
- package/env/matches-with-version/matches-with-version.js.map +0 -1
- package/env/private/private.js.map +0 -1
- package/env/types.js.map +0 -1
- package/env/user-agent/user-agent.js.map +0 -1
- package/index.d.ts +0 -7
- package/index.js +0 -8
- package/index.js.map +0 -1
- package/num/in-range/in-range.d.ts +0 -8
- package/num/in-range/in-range.js.map +0 -1
- package/num/index.d.ts +0 -3
- package/num/index.js +0 -4
- package/num/index.js.map +0 -1
- package/num/round/round.js.map +0 -1
- package/num/types.js +0 -2
- package/obj/constant/constant.js.map +0 -1
- package/obj/deep-constant/deep-constant.js.map +0 -1
- package/obj/diff-obj/diff-obj.d.ts +0 -9
- package/obj/diff-obj/diff-obj.js.map +0 -1
- package/obj/exclude/exclude.js.map +0 -1
- package/obj/extend/extend.js.map +0 -1
- package/obj/for-each-obj/for-each-obj.js.map +0 -1
- package/obj/has-own/has-own.js.map +0 -1
- package/obj/include/include.js.map +0 -1
- package/obj/index.d.ts +0 -13
- package/obj/index.js +0 -14
- package/obj/index.js.map +0 -1
- package/obj/keys/keys.js.map +0 -1
- package/obj/map-obj/map-obj.js.map +0 -1
- package/obj/map-obj-to-arr/map-obj-to-arr.js.map +0 -1
- package/obj/types.js +0 -2
- package/obj/types.js.map +0 -1
- package/obj/values/values.js.map +0 -1
- package/str/index.d.ts +0 -3
- package/str/index.js +0 -4
- package/str/index.js.map +0 -1
- package/str/to-camel-case/to-camel-case.js.map +0 -1
- package/str/to-hash/to-hash.js.map +0 -1
- package/str/with-capital/with-capital.js.map +0 -1
- /package/{arr → dist/arr}/at/at.d.ts +0 -0
- /package/{arr → dist/arr}/at/at.js +0 -0
- /package/{arr → dist/arr}/diff-arr/diff-arr.js +0 -0
- /package/{arr → dist/arr}/fill/fill.d.ts +0 -0
- /package/{arr → dist/arr}/fill/fill.js +0 -0
- /package/{arr → dist/arr}/pluck/pluck.js +0 -0
- /package/{arr → dist/arr}/within/within.d.ts +0 -0
- /package/{arr → dist/arr}/within/within.js +0 -0
- /package/{common → dist/common}/copy/copy.d.ts +0 -0
- /package/{common → dist/common}/copy/copy.js +0 -0
- /package/{common → dist/common}/equals/equals.d.ts +0 -0
- /package/{common → dist/common}/equals/equals.js +0 -0
- /package/{common → dist/common}/error.js +0 -0
- /package/{common → dist/common}/for-each/for-each.d.ts +0 -0
- /package/{common → dist/common}/for-each/for-each.js +0 -0
- /package/{common → dist/common}/get-unique-num-id/get-unique-num-id.d.ts +0 -0
- /package/{common → dist/common}/get-unique-num-id/get-unique-num-id.js +0 -0
- /package/{common → dist/common}/get-unique-str-id/get-unique-str-id.d.ts +0 -0
- /package/{common → dist/common}/has-iterator/has-iterator.d.ts +0 -0
- /package/{common → dist/common}/has-iterator/has-iterator.js +0 -0
- /package/{common → dist/common}/is/is.d.ts +0 -0
- /package/{common → dist/common}/is/is.js +0 -0
- /package/{common → dist/common}/is-empty/is-empty.d.ts +0 -0
- /package/{common → dist/common}/is-empty/is-empty.js +0 -0
- /package/{common → dist/common}/random/random.d.ts +0 -0
- /package/{common → dist/common}/random/random.js +0 -0
- /package/{common → dist/common}/same/same.d.ts +0 -0
- /package/{common → dist/common}/same/same.js +0 -0
- /package/{common → dist/common}/stub/stub.d.ts +0 -0
- /package/{common → dist/common}/stub/stub.js +0 -0
- /package/{common → dist/common}/to-float/to-float.d.ts +0 -0
- /package/{common → dist/common}/to-float/to-float.js +0 -0
- /package/{common → dist/common}/to-int/to-int.d.ts +0 -0
- /package/{common → dist/common}/to-int/to-int.js +0 -0
- /package/{common → dist/common}/to-sorted-string/to-sorted-string.d.ts +0 -0
- /package/{common → dist/common}/to-sorted-string/to-sorted-string.js +0 -0
- /package/{arr → dist/common}/types.js +0 -0
- /package/{dom → dist/dom}/closest/closest.d.ts +0 -0
- /package/{dom → dist/dom}/closest/closest.js +0 -0
- /package/{dom → dist/dom}/document/document.d.ts +0 -0
- /package/{dom → dist/dom}/download-file/download-file.d.ts +0 -0
- /package/{dom → dist/dom}/for-each-elements/for-each-elements.d.ts +0 -0
- /package/{dom → dist/dom}/for-each-nodes/for-each-nodes.d.ts +0 -0
- /package/{dom → dist/dom}/get-all-styles/get-all-styles.d.ts +0 -0
- /package/{dom → dist/dom}/get-all-styles/get-all-styles.js +0 -0
- /package/{dom → dist/dom}/get-body/get-body.d.ts +0 -0
- /package/{dom → dist/dom}/get-body/get-body.js +0 -0
- /package/{dom → dist/dom}/get-html/get-html.d.ts +0 -0
- /package/{dom → dist/dom}/get-html/get-html.js +0 -0
- /package/{dom → dist/dom}/get-non-static-parent/get-non-static-parent.d.ts +0 -0
- /package/{dom → dist/dom}/get-non-static-parent/get-non-static-parent.js +0 -0
- /package/{dom → dist/dom}/get-offset-from-doc/get-offset-from-doc.d.ts +0 -0
- /package/{dom → dist/dom}/get-offset-from-doc/get-offset-from-doc.js +0 -0
- /package/{dom → dist/dom}/get-offset-from-parent/get-offset-from-parent.d.ts +0 -0
- /package/{dom → dist/dom}/get-offset-from-win/get-offset-from-win.d.ts +0 -0
- /package/{dom → dist/dom}/get-offset-from-win/get-offset-from-win.js +0 -0
- /package/{dom → dist/dom}/get-scroll-width/get-scroll-width.d.ts +0 -0
- /package/{dom → dist/dom}/get-scroll-width/get-scroll-width.js +0 -0
- /package/{dom → dist/dom}/get-style/get-style.d.ts +0 -0
- /package/{dom → dist/dom}/get-style/get-style.js +0 -0
- /package/{dom → dist/dom}/get-styles/get-styles.js +0 -0
- /package/{dom → dist/dom}/get-valid-style-name/get-valid-style-name.d.ts +0 -0
- /package/{dom → dist/dom}/get-window/get-window.d.ts +0 -0
- /package/{dom → dist/dom}/has-name/has-name.d.ts +0 -0
- /package/{dom → dist/dom}/has-name/has-name.js +0 -0
- /package/{dom → dist/dom}/is-comment/is-comment.d.ts +0 -0
- /package/{dom → dist/dom}/is-comment/is-comment.js +0 -0
- /package/{dom → dist/dom}/is-element/is-element.d.ts +0 -0
- /package/{dom → dist/dom}/is-element/is-element.js +0 -0
- /package/{dom → dist/dom}/is-text/is-text.d.ts +0 -0
- /package/{dom → dist/dom}/is-text/is-text.js +0 -0
- /package/{dom → dist/dom}/set-offset-from-parent/set-offset-from-parent.d.ts +0 -0
- /package/{dom → dist/dom}/set-style/set-style.d.ts +0 -0
- /package/{dom → dist/dom}/set-style/set-style.js +0 -0
- /package/{dom → dist/dom}/set-styles/set-styles.js +0 -0
- /package/{dom → dist/dom}/types.d.ts +0 -0
- /package/{dom → dist/dom}/types.js +0 -0
- /package/{env → dist/env}/get-browser/get-browser.d.ts +0 -0
- /package/{env → dist/env}/get-engine/get-engine.d.ts +0 -0
- /package/{env → dist/env}/get-os/get-os.d.ts +0 -0
- /package/{env → dist/env}/get-platform/get-platform.d.ts +0 -0
- /package/{env → dist/env}/is-browser/is-browser.d.ts +0 -0
- /package/{env → dist/env}/is-browser/is-browser.js +0 -0
- /package/{env → dist/env}/is-chrome-like/is-chrome-like.d.ts +0 -0
- /package/{env → dist/env}/is-chrome-like/is-chrome-like.js +0 -0
- /package/{env → dist/env}/is-desktop/is-desktop.d.ts +0 -0
- /package/{env → dist/env}/is-desktop/is-desktop.js +0 -0
- /package/{env → dist/env}/is-engine/is-engine.d.ts +0 -0
- /package/{env → dist/env}/is-engine/is-engine.js +0 -0
- /package/{env → dist/env}/is-firefox-like/is-firefox-like.d.ts +0 -0
- /package/{env → dist/env}/is-firefox-like/is-firefox-like.js +0 -0
- /package/{env → dist/env}/is-mobile/is-mobile.d.ts +0 -0
- /package/{env → dist/env}/is-mobile/is-mobile.js +0 -0
- /package/{env → dist/env}/is-os/is-os.d.ts +0 -0
- /package/{env → dist/env}/is-os/is-os.js +0 -0
- /package/{env → dist/env}/is-portable/is-portable.d.ts +0 -0
- /package/{env → dist/env}/is-portable/is-portable.js +0 -0
- /package/{env → dist/env}/is-safari-like/is-safari-like.d.ts +0 -0
- /package/{env → dist/env}/is-safari-like/is-safari-like.js +0 -0
- /package/{env → dist/env}/is-stationary/is-stationary.d.ts +0 -0
- /package/{env → dist/env}/is-stationary/is-stationary.js +0 -0
- /package/{env → dist/env}/is-tablet/is-tablet.d.ts +0 -0
- /package/{env → dist/env}/is-tablet/is-tablet.js +0 -0
- /package/{env → dist/env}/is-tv/is-tv.d.ts +0 -0
- /package/{env → dist/env}/is-tv/is-tv.js +0 -0
- /package/{env → dist/env}/matches/matches.d.ts +0 -0
- /package/{env → dist/env}/matches-with-browsers/matches-with-browsers.d.ts +0 -0
- /package/{env → dist/env}/matches-with-version/matches-with-version.d.ts +0 -0
- /package/{env → dist/env}/types.d.ts +0 -0
- /package/{env → dist/env}/types.js +0 -0
- /package/{env → dist/env}/user-agent/user-agent.d.ts +0 -0
- /package/{num → dist/num}/round/round.d.ts +0 -0
- /package/{num → dist/num}/round/round.js +0 -0
- /package/{obj → dist/obj}/constant/constant.js +0 -0
- /package/{obj → dist/obj}/has-own/has-own.js +0 -0
- /package/{obj → dist/obj}/keys/keys.js +0 -0
- /package/{obj → dist/obj}/map-obj/map-obj.js +0 -0
- /package/{obj → dist/obj}/map-obj-to-arr/map-obj-to-arr.js +0 -0
- /package/{obj → dist/obj}/values/values.js +0 -0
- /package/{str → dist/str}/to-camel-case/to-camel-case.d.ts +0 -0
- /package/{str → dist/str}/to-camel-case/to-camel-case.js +0 -0
- /package/{str → dist/str}/to-hash/to-hash.d.ts +0 -0
- /package/{str → dist/str}/to-hash/to-hash.js +0 -0
- /package/{str → dist/str}/with-capital/with-capital.d.ts +0 -0
- /package/{str → dist/str}/with-capital/with-capital.js +0 -0
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import {NumStr, isString, isDate, isRegExp, isFunction, isMap, isSet, isObject, isArray, isTypedArray} from '../';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Converts any value to a sorted string.
|
|
5
|
+
* Sorts arrays, maps and sets by value and sorts objects by field name before adding them to a string.
|
|
6
|
+
* Objects, arrays, sets, maps etc. will be ignored if they have been visited to prevent looping
|
|
7
|
+
* @param value - anything
|
|
8
|
+
*/
|
|
9
|
+
export function toSortedString(value: any): string {
|
|
10
|
+
return _toSortedString(value, null, 0, new Map<any, true>());
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function _toSortedString(value: any, index: number | null, field: NumStr, visited: Map<any, true>): string {
|
|
14
|
+
let str = index === null ? '' : ((index === 0 ? '' : ',') + (isString(field) ? field + ':' : ''));
|
|
15
|
+
|
|
16
|
+
if (isMap(value) || isSet(value)) {
|
|
17
|
+
if (visited.has(value)) {
|
|
18
|
+
return '';
|
|
19
|
+
}
|
|
20
|
+
visited.set(value, true);
|
|
21
|
+
|
|
22
|
+
value = Array.from(value);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
if (isArray(value) || isTypedArray(value)) {
|
|
26
|
+
if (visited.has(value)) {
|
|
27
|
+
return '';
|
|
28
|
+
}
|
|
29
|
+
visited.set(value, true);
|
|
30
|
+
|
|
31
|
+
str += '[';
|
|
32
|
+
value.sort();
|
|
33
|
+
value.forEach((value: any, i: number) => {
|
|
34
|
+
str += _toSortedString(value, i, i, visited);
|
|
35
|
+
});
|
|
36
|
+
str += ']';
|
|
37
|
+
} else if (isFunction(value)) {
|
|
38
|
+
str += value.toString();
|
|
39
|
+
} else if (isObject(value) && !isDate(value) && !isRegExp(value)) {
|
|
40
|
+
if (visited.has(value)) {
|
|
41
|
+
return '';
|
|
42
|
+
}
|
|
43
|
+
visited.set(value, true);
|
|
44
|
+
|
|
45
|
+
const fields = Object.keys(value);
|
|
46
|
+
|
|
47
|
+
str += '{';
|
|
48
|
+
fields.sort();
|
|
49
|
+
fields.forEach((field, i) => {
|
|
50
|
+
str += _toSortedString(value[field], i, field, visited);
|
|
51
|
+
});
|
|
52
|
+
str += '}';
|
|
53
|
+
} else {
|
|
54
|
+
str += value;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
return str;
|
|
58
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Represents a value, which can be undefined or null
|
|
3
|
+
*/
|
|
4
|
+
export type Nullish = undefined | null;
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Represents a value, which can be a number or string
|
|
8
|
+
*/
|
|
9
|
+
export type NumStr = number | string;
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Represents a value, which can be a number, string or symbol
|
|
13
|
+
*/
|
|
14
|
+
export type NumStrSym = NumStr | symbol;
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Represents any function
|
|
18
|
+
*/
|
|
19
|
+
export type Fn = (...args: any[]) => any;
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Represents any array
|
|
23
|
+
*/
|
|
24
|
+
export type Arr<T = any> = ReadonlyArray<T> | ArrayLike<T>;
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Represents all typed array types
|
|
28
|
+
*/
|
|
29
|
+
export type TypedArr = Int8Array | Int16Array | Int32Array | Float32Array | Float64Array | Uint8Array
|
|
30
|
+
| Uint8ClampedArray | Uint16Array | Uint32Array | BigInt64Array | BigUint64Array;
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Represents any object
|
|
34
|
+
*/
|
|
35
|
+
export interface Obj<T = any> {
|
|
36
|
+
[key: NumStrSym]: T;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Represents an object with an indefinite number of string keys of type T
|
|
41
|
+
*/
|
|
42
|
+
export interface Index<T = any> {
|
|
43
|
+
[key: string]: T;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Represents the union of any array type and any object type
|
|
48
|
+
*/
|
|
49
|
+
export type ArrObj<T = any> = Arr<T> | Obj<T>;
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Converts a type union to a type intersection
|
|
53
|
+
*/
|
|
54
|
+
export type UnionToIntersection<U> = (U extends any ? (x: U) => void : never) extends ((x: infer I) => void) ? I
|
|
55
|
+
: never;
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Represents the union of object value types or array value types
|
|
59
|
+
*/
|
|
60
|
+
export type ValueUnion<T extends ArrObj, K extends keyof T = keyof T> = T extends ReadonlyArray<any> ? T[number]
|
|
61
|
+
: T extends ArrayLike<any> ? T[number] : T extends object ? T[K] : never;
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Represents the intersection of object value types or array value types
|
|
65
|
+
*/
|
|
66
|
+
export type ValueIntersection<T extends ArrObj> = UnionToIntersection<ValueUnion<T>>;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns the same element or the closest parent element matching the selectors, otherwise null
|
|
3
|
+
* @param element - any HTML element
|
|
4
|
+
* @param selectors - target HTML element or string of valid CSS selectors
|
|
5
|
+
*/
|
|
6
|
+
export function closest(element: HTMLElement, selectors: string | HTMLElement): HTMLElement | null {
|
|
7
|
+
let currentElem: HTMLElement | null = element;
|
|
8
|
+
|
|
9
|
+
while (currentElem) {
|
|
10
|
+
if (selectors instanceof Element) {
|
|
11
|
+
if (currentElem === selectors) {
|
|
12
|
+
return currentElem;
|
|
13
|
+
} else {
|
|
14
|
+
currentElem = currentElem.parentElement;
|
|
15
|
+
}
|
|
16
|
+
} else if (currentElem.matches(selectors)) {
|
|
17
|
+
return currentElem;
|
|
18
|
+
} else {
|
|
19
|
+
currentElem = currentElem.parentElement;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import {BfError} from '../../common';
|
|
2
|
+
|
|
3
|
+
let doc = typeof document === 'object' ? document : undefined;
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Returns the document object representing the HTML document in the current environment
|
|
7
|
+
*/
|
|
8
|
+
export function getDocument(): Document {
|
|
9
|
+
if (doc) {
|
|
10
|
+
return doc;
|
|
11
|
+
} else {
|
|
12
|
+
throw new BfError('Document is absent', {code: 'bf_utils_dom_getDocument_1'});
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* If the global object is not a window, you can use this function to set up a stub document implementation
|
|
18
|
+
* @example
|
|
19
|
+
* For Angular:
|
|
20
|
+
* setDocument(inject(DOCUMENT));
|
|
21
|
+
* @param document - The document object representing the HTML document in the current environment
|
|
22
|
+
*/
|
|
23
|
+
export function setDocument(document: Document): void {
|
|
24
|
+
doc = document;
|
|
25
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import {BfError} from '../../common';
|
|
2
|
+
import {getBody, getDocument, getWindow} from '../';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Creates an offer to download a file from URL in the browser.
|
|
6
|
+
* Returns a promise that returns a blob if the download is successful
|
|
7
|
+
* @param url - file URL
|
|
8
|
+
*/
|
|
9
|
+
export function downloadFile(url: string): Promise<Blob> {
|
|
10
|
+
return fetch(url)
|
|
11
|
+
.then(response => {
|
|
12
|
+
if (response.ok) {
|
|
13
|
+
return response.blob();
|
|
14
|
+
} else {
|
|
15
|
+
return Promise.reject(new BfError('Network response was not ok', {code: 'bf_utils_dom_downloadFile_1'}));
|
|
16
|
+
}
|
|
17
|
+
})
|
|
18
|
+
.then(blob => {
|
|
19
|
+
const doc = getDocument();
|
|
20
|
+
const win = getWindow();
|
|
21
|
+
const body = getBody();
|
|
22
|
+
const url = win.URL.createObjectURL(blob);
|
|
23
|
+
const link = doc.createElement('a');
|
|
24
|
+
link.href = url;
|
|
25
|
+
link.download = 'downloaded_file';
|
|
26
|
+
body.appendChild(link);
|
|
27
|
+
link.click();
|
|
28
|
+
body.removeChild(link);
|
|
29
|
+
return blob;
|
|
30
|
+
});
|
|
31
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import {forEach, INTERRUPT} from '../../common';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Iterates through all child elements of the parent element to the full depth of the tree
|
|
5
|
+
* and calls a handler for each element.
|
|
6
|
+
* If the handler returns INTERRUPT, the loop will be interrupted
|
|
7
|
+
* @param parent - a parent element
|
|
8
|
+
* @param handler - function called for each element
|
|
9
|
+
*/
|
|
10
|
+
export function forEachElements(parent: Element,
|
|
11
|
+
handler: (child: Element, index: number, parent: Element) => any): void {
|
|
12
|
+
forEach(parent.children, (child, i) => {
|
|
13
|
+
if (handler(child, <number>i, parent) !== INTERRUPT) {
|
|
14
|
+
forEachElements(child, handler);
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import {INTERRUPT} from '../../common';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Iterates through all child nodes of the parent node to the full depth of the tree and calls a handler for each node.
|
|
5
|
+
* If the handler returns INTERRUPT, the loop will be interrupted
|
|
6
|
+
* @param parent - a parent node
|
|
7
|
+
* @param handler - function called for each node (Text, Comment, Element)
|
|
8
|
+
*/
|
|
9
|
+
export function forEachNodes(parent: Node, handler: (child: Node, index: number, parent: Node) => any): void {
|
|
10
|
+
parent.childNodes.forEach((child, i) => {
|
|
11
|
+
if (handler(child, i, parent) !== INTERRUPT) {
|
|
12
|
+
forEachNodes(child, handler);
|
|
13
|
+
}
|
|
14
|
+
});
|
|
15
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import {getWindow} from '../';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Returns all computed styles of a given HTML element
|
|
5
|
+
* @param element - any HTML element
|
|
6
|
+
*/
|
|
7
|
+
export function getAllStyles(element: HTMLElement): CSSStyleDeclaration {
|
|
8
|
+
const win = getWindow();
|
|
9
|
+
return win.getComputedStyle(element);
|
|
10
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import {getWindow, Offset} from '../';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Returns the offset relative to the document
|
|
5
|
+
* @param element - any element
|
|
6
|
+
*/
|
|
7
|
+
export function getOffsetFromDoc(element: Element): Offset {
|
|
8
|
+
const win = getWindow();
|
|
9
|
+
const rect = element.getBoundingClientRect();
|
|
10
|
+
return {
|
|
11
|
+
top: rect.top + win.scrollY,
|
|
12
|
+
bottom: rect.bottom + win.scrollY,
|
|
13
|
+
left: rect.left + win.scrollX,
|
|
14
|
+
right: rect.right + win.scrollX,
|
|
15
|
+
width: rect.width,
|
|
16
|
+
height: rect.height,
|
|
17
|
+
};
|
|
18
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import {BfError, toFloat} from '../../common';
|
|
2
|
+
import {Offset, hasName, getNonStaticParent, getOffsetFromWin, getOffsetFromDoc, getStyle} from '../';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Returns the offset relative to the closest non-static parent element.
|
|
6
|
+
* For fixed elements returns the offset relative to the global window
|
|
7
|
+
* @param element - any HTML element
|
|
8
|
+
*/
|
|
9
|
+
export function getOffsetFromParent(element: HTMLElement): Offset {
|
|
10
|
+
let offset: Offset;
|
|
11
|
+
let parentOffset: Offset;
|
|
12
|
+
|
|
13
|
+
if (hasName(element, 'html') || hasName(element, 'body')) {
|
|
14
|
+
throw new BfError('Element cannot be html or body', {code: 'bf_utils_dom_getOffsetFromParent_1'});
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
if (getStyle(element, 'position') === 'fixed') {
|
|
18
|
+
offset = getOffsetFromWin(element);
|
|
19
|
+
parentOffset = {
|
|
20
|
+
top: 0,
|
|
21
|
+
bottom: 0,
|
|
22
|
+
left: 0,
|
|
23
|
+
right: 0,
|
|
24
|
+
width: 0,
|
|
25
|
+
height: 0,
|
|
26
|
+
};
|
|
27
|
+
} else {
|
|
28
|
+
const parent = getNonStaticParent(element);
|
|
29
|
+
offset = getOffsetFromDoc(element);
|
|
30
|
+
parentOffset = getOffsetFromDoc(parent);
|
|
31
|
+
|
|
32
|
+
// The element cannot overlap its parent border, so the border width is added to the offset
|
|
33
|
+
parentOffset.top += toFloat(getStyle(parent, 'borderTopWidth'));
|
|
34
|
+
parentOffset.bottom -= toFloat(getStyle(parent, 'borderBottomWidth'));
|
|
35
|
+
parentOffset.left += toFloat(getStyle(parent, 'borderLeftWidth'));
|
|
36
|
+
parentOffset.right -= toFloat(getStyle(parent, 'borderRightWidth'));
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// Subtract the element's margin so that the element is correctly placed relative to its parent
|
|
40
|
+
return {
|
|
41
|
+
top: offset.top - parentOffset.top - toFloat(getStyle(element, 'marginTop')),
|
|
42
|
+
bottom: offset.bottom - parentOffset.bottom - toFloat(getStyle(element, 'marginTop')),
|
|
43
|
+
left: offset.left - parentOffset.left - toFloat(getStyle(element, 'marginLeft')),
|
|
44
|
+
right: offset.right - parentOffset.right - toFloat(getStyle(element, 'marginLeft')),
|
|
45
|
+
width: offset.width,
|
|
46
|
+
height: offset.height,
|
|
47
|
+
};
|
|
48
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import {getHtml, setStyle} from '../';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Returns width of vertical and horizontal scrollbars
|
|
5
|
+
* @param element - any HTML element, default the document's root element <html>
|
|
6
|
+
*/
|
|
7
|
+
export function getScrollWidth(element?: HTMLElement): {y: number; x: number} {
|
|
8
|
+
element = element || getHtml();
|
|
9
|
+
const originalValue = setStyle(element, 'overflow', 'hidden');
|
|
10
|
+
const clientWidth1 = element.clientWidth;
|
|
11
|
+
const clientHeight1 = element.clientHeight;
|
|
12
|
+
|
|
13
|
+
setStyle(element, 'overflow', 'scroll');
|
|
14
|
+
const clientWidth2 = element.clientWidth;
|
|
15
|
+
const clientHeight2 = element.clientHeight;
|
|
16
|
+
|
|
17
|
+
setStyle(element, 'overflow', originalValue);
|
|
18
|
+
let y = clientWidth1 - clientWidth2;
|
|
19
|
+
let x = clientHeight1 - clientHeight2;
|
|
20
|
+
|
|
21
|
+
if (y > 0) {
|
|
22
|
+
y += 1;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
if (x > 0) {
|
|
26
|
+
x += 1;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return {
|
|
30
|
+
y,
|
|
31
|
+
x,
|
|
32
|
+
};
|
|
33
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import {Index} from '../../common';
|
|
2
|
+
import {getValidStyleName, getAllStyles} from '../';
|
|
3
|
+
|
|
4
|
+
const validStyleValues: Index<[string, string]> = {
|
|
5
|
+
opacity: ['', '1'],
|
|
6
|
+
fontWeight: ['normal', '400'],
|
|
7
|
+
letterSpacing: ['normal', '0'],
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Returns certain computed style value of a given HTML element
|
|
12
|
+
* @param element - any HTML element
|
|
13
|
+
* @param styleName - any style name
|
|
14
|
+
*/
|
|
15
|
+
export function getStyle(element: HTMLElement, styleName: string): string {
|
|
16
|
+
const styles = getAllStyles(element);
|
|
17
|
+
const validName = getValidStyleName(styleName);
|
|
18
|
+
const value = styles.getPropertyValue(validName);
|
|
19
|
+
|
|
20
|
+
if (validStyleValues[validName] && value === validStyleValues[validName][0]) {
|
|
21
|
+
return validStyleValues[validName][1];
|
|
22
|
+
} else {
|
|
23
|
+
return value;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import {ValueUnion} from '../../common';
|
|
2
|
+
import {getStyle} from '../';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Returns an object with the specified computed styles for a given HTML element
|
|
6
|
+
* @param element - any HTML element
|
|
7
|
+
* @param styleNames - list of certain style names
|
|
8
|
+
*/
|
|
9
|
+
export function getStyles<A extends string[]>(element: HTMLElement,
|
|
10
|
+
...styleNames: A): {[K in ValueUnion<A>]: string} {
|
|
11
|
+
const styles: {[K in ValueUnion<A>]: string} = <any>{};
|
|
12
|
+
styleNames.forEach(name => (<any>styles)[name] = getStyle(element, name));
|
|
13
|
+
return styles;
|
|
14
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import {BfError, Index} from '../../common';
|
|
2
|
+
import {withCapital, toCamelCase} from '../../str';
|
|
3
|
+
import {getDocument} from '../';
|
|
4
|
+
|
|
5
|
+
let defaultStyles: CSSStyleDeclaration;
|
|
6
|
+
const vendorPrefixes = ['Webkit', 'Moz'];
|
|
7
|
+
const validStyleNames: Index<string> = {float: 'cssFloat'};
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Attempts to convert the name to a valid style name.
|
|
11
|
+
* Returns a valid style name or throws an exception if a valid name is not found
|
|
12
|
+
* @param name - any name
|
|
13
|
+
*/
|
|
14
|
+
export function getValidStyleName(name: string): string {
|
|
15
|
+
if (!defaultStyles) {
|
|
16
|
+
const doc = getDocument();
|
|
17
|
+
defaultStyles = doc.createElement('div').style;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
if (name in validStyleNames) {
|
|
21
|
+
return validStyleNames[name];
|
|
22
|
+
} else {
|
|
23
|
+
const camelName = toCamelCase(name);
|
|
24
|
+
|
|
25
|
+
if (camelName in defaultStyles) {
|
|
26
|
+
validStyleNames[name] = camelName;
|
|
27
|
+
} else {
|
|
28
|
+
const baseName = withCapital(camelName);
|
|
29
|
+
|
|
30
|
+
for (const prefix of vendorPrefixes) {
|
|
31
|
+
const fullName = prefix + baseName;
|
|
32
|
+
if (fullName in defaultStyles) {
|
|
33
|
+
validStyleNames[name] = fullName;
|
|
34
|
+
break;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
if (!(name in validStyleNames)) {
|
|
39
|
+
throw new BfError('Incorrect style name', {code: 'bf_utils_dom_getValidStyleName_1'});
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return validStyleNames[name];
|
|
44
|
+
}
|
|
45
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import {BfError} from '../../common';
|
|
2
|
+
import {getDocument} from '../';
|
|
3
|
+
|
|
4
|
+
let win = typeof window === 'object' ? window : undefined;
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Returns the global window object in the current environment
|
|
8
|
+
*/
|
|
9
|
+
export function getWindow(): Window & typeof globalThis {
|
|
10
|
+
const doc = getDocument();
|
|
11
|
+
win = doc.defaultView || win;
|
|
12
|
+
if (win) {
|
|
13
|
+
return win;
|
|
14
|
+
} else {
|
|
15
|
+
throw new BfError('Window is absent', {code: 'bf_utils_dom_getWindow_1'});
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Determines if the name of the passed element matches a specific name
|
|
3
|
+
* @param element - any HTML element
|
|
4
|
+
* @param name - any node name
|
|
5
|
+
*/
|
|
6
|
+
export function hasName(element: Element, name: string): boolean {
|
|
7
|
+
return element.nodeName.toLowerCase() === name.toLowerCase();
|
|
8
|
+
}
|
package/src/dom/index.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export {TopLeft, Offset} from './types';
|
|
2
|
+
export {isText} from './is-text/is-text';
|
|
3
|
+
export {isComment} from './is-comment/is-comment';
|
|
4
|
+
export {isElement} from './is-element/is-element';
|
|
5
|
+
export {hasName} from './has-name/has-name';
|
|
6
|
+
export {getDocument, setDocument} from './document/document';
|
|
7
|
+
export {getWindow} from './get-window/get-window';
|
|
8
|
+
export {getHtml} from './get-html/get-html';
|
|
9
|
+
export {getBody} from './get-body/get-body';
|
|
10
|
+
export {closest} from './closest/closest';
|
|
11
|
+
export {getNonStaticParent} from './get-non-static-parent/get-non-static-parent';
|
|
12
|
+
export {getOffsetFromWin} from './get-offset-from-win/get-offset-from-win';
|
|
13
|
+
export {getOffsetFromDoc} from './get-offset-from-doc/get-offset-from-doc';
|
|
14
|
+
export {getOffsetFromParent} from './get-offset-from-parent/get-offset-from-parent';
|
|
15
|
+
export {setOffsetFromParent} from './set-offset-from-parent/set-offset-from-parent';
|
|
16
|
+
export {getValidStyleName} from './get-valid-style-name/get-valid-style-name';
|
|
17
|
+
export {getScrollWidth} from './get-scroll-width/get-scroll-width';
|
|
18
|
+
export {downloadFile} from './download-file/download-file';
|
|
19
|
+
export {forEachNodes} from './for-each-nodes/for-each-nodes';
|
|
20
|
+
export {forEachElements} from './for-each-elements/for-each-elements';
|
|
21
|
+
export {getAllStyles} from './get-all-styles/get-all-styles';
|
|
22
|
+
export {getStyle} from './get-style/get-style';
|
|
23
|
+
export {getStyles} from './get-styles/get-styles';
|
|
24
|
+
export {setStyle} from './set-style/set-style';
|
|
25
|
+
export {setStyles} from './set-styles/set-styles';
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import {isNumber, toFloat} from '../../common';
|
|
2
|
+
import {TopLeft, getOffsetFromParent, setStyle, getStyle, setStyles} from '../';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Sets the offset relative to the closest non-static parent element
|
|
6
|
+
* For fixed elements sets the offset relative to the global window
|
|
7
|
+
* @param element - any HTML element
|
|
8
|
+
* @param offset - top and left position relative to the parent HTML element
|
|
9
|
+
*/
|
|
10
|
+
export function setOffsetFromParent(element: HTMLElement, offset: Partial<TopLeft>): void {
|
|
11
|
+
let top = 0;
|
|
12
|
+
let left = 0;
|
|
13
|
+
let styleTop = getStyle(element, 'top');
|
|
14
|
+
let styleLeft = getStyle(element, 'left');
|
|
15
|
+
const position = getStyle(element, 'position');
|
|
16
|
+
const styles: {top?: string; left?: string} = {};
|
|
17
|
+
|
|
18
|
+
// An element cannot be static for offset applying
|
|
19
|
+
if (position === 'static') {
|
|
20
|
+
styleTop = '0'; // because top was ignored for a static element
|
|
21
|
+
styleLeft = '0'; // because left was ignored for a static element
|
|
22
|
+
setStyle(element, 'position', 'relative');
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// If top or left is auto, need calculate real top and left relative to a non-static parent
|
|
26
|
+
if ((position === 'absolute' || position === 'fixed') && (styleTop === 'auto' || styleLeft === 'auto')) {
|
|
27
|
+
const offsetFromParent = getOffsetFromParent(element);
|
|
28
|
+
top = offsetFromParent.top;
|
|
29
|
+
left = offsetFromParent.left;
|
|
30
|
+
} else {
|
|
31
|
+
top = toFloat(styleTop);
|
|
32
|
+
left = toFloat(styleLeft);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
if (isNumber(offset.top)) {
|
|
36
|
+
const newTop = top + offset.top;
|
|
37
|
+
styles.top = newTop !== 0 ? newTop + 'px' : '0';
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
if (isNumber(offset.left)) {
|
|
41
|
+
const newLeft = left + offset.left;
|
|
42
|
+
styles.left = newLeft !== 0 ? newLeft + 'px' : '0';
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
setStyles(element, styles);
|
|
46
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import {getStyle} from '../';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Sets a new value for a certain style for a given HTML element
|
|
5
|
+
* @param element - any HTML element
|
|
6
|
+
* @param styleName - any style name
|
|
7
|
+
* @param value - new value for style
|
|
8
|
+
* @returns previous value for style
|
|
9
|
+
*/
|
|
10
|
+
export function setStyle(element: HTMLElement, styleName: string, value: string): string {
|
|
11
|
+
const originalStyle = getStyle(element, styleName);
|
|
12
|
+
(<any>element.style)[styleName] = value;
|
|
13
|
+
return originalStyle;
|
|
14
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import {Index} from '../../common';
|
|
2
|
+
import {forEachObj} from '../../obj';
|
|
3
|
+
import {setStyle} from '../';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Sets new styles for a given HTML element
|
|
7
|
+
* @param element - any HTML element
|
|
8
|
+
* @param styles - object containing new styles
|
|
9
|
+
* @returns object containing previous styles
|
|
10
|
+
*/
|
|
11
|
+
export function setStyles<T extends Index<string>>(element: HTMLElement, styles: T): T {
|
|
12
|
+
const originalStyles = <T>{};
|
|
13
|
+
forEachObj(styles, (value, key) => {
|
|
14
|
+
(<any>originalStyles)[key] = setStyle(element, <string>key, value);
|
|
15
|
+
});
|
|
16
|
+
return originalStyles;
|
|
17
|
+
}
|
package/src/dom/types.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Represents an object with two properties top and left
|
|
3
|
+
*/
|
|
4
|
+
export interface TopLeft {
|
|
5
|
+
top: number;
|
|
6
|
+
left: number;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Represents the response type for the following functions:
|
|
11
|
+
* getOffsetFromWin, getOffsetFromDoc and getOffsetFromParent
|
|
12
|
+
*/
|
|
13
|
+
export interface Offset {
|
|
14
|
+
top: number;
|
|
15
|
+
bottom: number;
|
|
16
|
+
left: number;
|
|
17
|
+
right: number;
|
|
18
|
+
width: number;
|
|
19
|
+
height: number;
|
|
20
|
+
}
|