@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,18 @@
|
|
|
1
|
+
import { isObject } from '../../';
|
|
2
|
+
import { constant } from '../';
|
|
3
|
+
/**
|
|
4
|
+
* Makes an object and its nested objects read-only
|
|
5
|
+
* @param obj - any object
|
|
6
|
+
*/
|
|
7
|
+
export function deepConstant(obj) {
|
|
8
|
+
// Gets fields of enumerable and non-enumerable own properties
|
|
9
|
+
const fields = Object.getOwnPropertyNames(obj);
|
|
10
|
+
// Makes nested objects read-only
|
|
11
|
+
fields.forEach(key => {
|
|
12
|
+
if (isObject(obj[key])) {
|
|
13
|
+
deepConstant(obj[key]);
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
return constant(obj);
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=deep-constant.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deep-constant.js","sourceRoot":"","sources":["../../../../package/src/obj/deep-constant/deep-constant.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,QAAQ,EAAM,MAAM,QAAQ,CAAC;AACrC,OAAO,EAAC,QAAQ,EAAC,MAAM,KAAK,CAAC;AAE7B;;;GAGG;AACH,MAAM,UAAU,YAAY,CAAgB,GAAM;IAChD,8DAA8D;IAC9D,MAAM,MAAM,GAAG,MAAM,CAAC,mBAAmB,CAAC,GAAG,CAAC,CAAC;IAE/C,iCAAiC;IACjC,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE;QACnB,IAAI,QAAQ,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,EAAE;YACtB,YAAY,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC;SACxB;IACH,CAAC,CAAC,CAAC;IAEH,OAAO,QAAQ,CAAC,GAAG,CAAC,CAAC;AACvB,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Obj } from '../../';
|
|
2
|
+
import { ObjDiff } from '../';
|
|
3
|
+
/**
|
|
4
|
+
* Returns the difference between two objects
|
|
5
|
+
* @param obj1 - any object 1
|
|
6
|
+
* @param obj2 - any object 2
|
|
7
|
+
* @param sortFn - if added, arrays and sets will be sorted before comparison
|
|
8
|
+
*/
|
|
9
|
+
export declare function diffObj<T1 extends Obj, T2 extends Obj>(obj1: T1, obj2: T2, sortFn?: (a: any, b: any) => number): ObjDiff<T1 & T2>;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { equals, isDefined, isUndefined } from '../../';
|
|
2
|
+
import { forEachObj } from '../';
|
|
3
|
+
/**
|
|
4
|
+
* Returns the difference between two objects
|
|
5
|
+
* @param obj1 - any object 1
|
|
6
|
+
* @param obj2 - any object 2
|
|
7
|
+
* @param sortFn - if added, arrays and sets will be sorted before comparison
|
|
8
|
+
*/
|
|
9
|
+
export function diffObj(obj1, obj2, sortFn) {
|
|
10
|
+
let isEqual = true;
|
|
11
|
+
const equal = {};
|
|
12
|
+
const notEqual1 = {};
|
|
13
|
+
const notEqual2 = {};
|
|
14
|
+
const only1 = {};
|
|
15
|
+
const only2 = {};
|
|
16
|
+
forEachObj(obj1, (value, key) => {
|
|
17
|
+
if (isDefined(value)) {
|
|
18
|
+
if (equals(value, obj2[key], sortFn)) {
|
|
19
|
+
equal[key] = value;
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
isEqual = false;
|
|
23
|
+
notEqual1[key] = value;
|
|
24
|
+
if (isDefined(obj2[key])) {
|
|
25
|
+
notEqual2[key] = obj2[key];
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
only1[key] = notEqual1[key];
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
forEachObj(obj2, (value, key) => {
|
|
34
|
+
if (isDefined(value) && isUndefined(equal[key]) && isUndefined(notEqual1[key])) {
|
|
35
|
+
isEqual = false;
|
|
36
|
+
notEqual2[key] = only2[key] = value;
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
return {
|
|
40
|
+
equal,
|
|
41
|
+
notEqual1,
|
|
42
|
+
notEqual2,
|
|
43
|
+
only1,
|
|
44
|
+
only2,
|
|
45
|
+
isEqual,
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
//# sourceMappingURL=diff-obj.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"diff-obj.js","sourceRoot":"","sources":["../../../../package/src/obj/diff-obj/diff-obj.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,MAAM,EAAE,SAAS,EAAE,WAAW,EAAM,MAAM,QAAQ,CAAC;AAC3D,OAAO,EAAC,UAAU,EAAU,MAAM,KAAK,CAAC;AAExC;;;;;GAKG;AACH,MAAM,UAAU,OAAO,CAAiC,IAAQ,EAAE,IAAQ,EACxE,MAAmC;IACnC,IAAI,OAAO,GAAG,IAAI,CAAC;IACnB,MAAM,KAAK,GAAqB,EAAE,CAAC;IACnC,MAAM,SAAS,GAAqB,EAAE,CAAC;IACvC,MAAM,SAAS,GAAqB,EAAE,CAAC;IACvC,MAAM,KAAK,GAAqB,EAAE,CAAC;IACnC,MAAM,KAAK,GAAqB,EAAE,CAAC;IAEnC,UAAU,CAAC,IAAI,EAAE,CAAC,KAAK,EAAE,GAAG,EAAE,EAAE;QAC9B,IAAI,SAAS,CAAC,KAAK,CAAC,EAAE;YACpB,IAAI,MAAM,CAAC,KAAK,EAAE,IAAI,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC,EAAE;gBACpC,KAAK,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;aACpB;iBAAM;gBACL,OAAO,GAAG,KAAK,CAAC;gBAChB,SAAS,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;gBAEvB,IAAI,SAAS,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE;oBACxB,SAAS,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC;iBAC5B;qBAAM;oBACL,KAAK,CAAC,GAAG,CAAC,GAAG,SAAS,CAAC,GAAG,CAAC,CAAC;iBAC7B;aACF;SACF;IACH,CAAC,CAAC,CAAC;IAEH,UAAU,CAAC,IAAI,EAAE,CAAC,KAAK,EAAE,GAAG,EAAE,EAAE;QAC9B,IAAI,SAAS,CAAC,KAAK,CAAC,IAAI,WAAW,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,WAAW,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,EAAE;YAC9E,OAAO,GAAG,KAAK,CAAC;YAChB,SAAS,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;SACrC;IACH,CAAC,CAAC,CAAC;IAEH,OAAO;QACL,KAAK;QACL,SAAS;QACT,SAAS;QACT,KAAK;QACL,KAAK;QACL,OAAO;KACR,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Obj } from '../../';
|
|
2
|
+
/**
|
|
3
|
+
* Returns a new object with the fields of the passed object, excluding the specified set of fields
|
|
4
|
+
* @param obj - any object
|
|
5
|
+
* @param fields - set of fields to be excluded
|
|
6
|
+
*/
|
|
7
|
+
export declare function exclude<T extends Obj, K extends keyof T>(obj: T, ...fields: K[]): Omit<T, K>;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { isDefined } from '../../';
|
|
2
|
+
import { forEachObj } from '../';
|
|
3
|
+
/**
|
|
4
|
+
* Returns a new object with the fields of the passed object, excluding the specified set of fields
|
|
5
|
+
* @param obj - any object
|
|
6
|
+
* @param fields - set of fields to be excluded
|
|
7
|
+
*/
|
|
8
|
+
export function exclude(obj, ...fields) {
|
|
9
|
+
const result = {};
|
|
10
|
+
forEachObj(obj, (value, key) => {
|
|
11
|
+
if (isDefined(value) && !fields.includes(key)) {
|
|
12
|
+
// @ts-ignore
|
|
13
|
+
result[key] = value;
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
return result;
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=exclude.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"exclude.js","sourceRoot":"","sources":["../../../../package/src/obj/exclude/exclude.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,SAAS,EAAM,MAAM,QAAQ,CAAC;AACtC,OAAO,EAAC,UAAU,EAAC,MAAM,KAAK,CAAC;AAE/B;;;;GAIG;AACH,MAAM,UAAU,OAAO,CAAmC,GAAM,EAAE,GAAG,MAAW;IAC9E,MAAM,MAAM,GAAe,EAAE,CAAC;IAC9B,UAAU,CAAC,GAAG,EAAE,CAAC,KAAK,EAAE,GAAG,EAAE,EAAE;QAC7B,IAAI,SAAS,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAI,GAAG,CAAC,EAAE;YAChD,aAAa;YACb,MAAM,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;SACrB;IACH,CAAC,CAAC,CAAC;IACH,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Obj, ValueIntersection } from '../../';
|
|
2
|
+
/**
|
|
3
|
+
* Copies all enumerable own properties from one or more source objects to a target object.
|
|
4
|
+
* It returns the modified target object
|
|
5
|
+
* @param target - target object
|
|
6
|
+
* @param sources - source objects
|
|
7
|
+
*/
|
|
8
|
+
export declare function extend<T extends Obj, U extends Obj[]>(target: T, ...sources: U): T & ValueIntersection<typeof sources>;
|
|
9
|
+
/**
|
|
10
|
+
* Copies all enumerable own properties from one or more source objects to a target object
|
|
11
|
+
* and copies enumerable properties from nested source objects to nested target objects
|
|
12
|
+
* It returns the modified target object
|
|
13
|
+
* @param target - target object
|
|
14
|
+
* @param sources - source objects
|
|
15
|
+
*/
|
|
16
|
+
export declare function extendAll<T extends Obj, U extends Obj[]>(target: T, ...sources: U): T & ValueIntersection<typeof sources>;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { copy, isDefined, isUsualObject } from '../../';
|
|
2
|
+
import { forEachObj } from '../';
|
|
3
|
+
/**
|
|
4
|
+
* Copies all enumerable own properties from one or more source objects to a target object.
|
|
5
|
+
* It returns the modified target object
|
|
6
|
+
* @param target - target object
|
|
7
|
+
* @param sources - source objects
|
|
8
|
+
*/
|
|
9
|
+
export function extend(target, ...sources) {
|
|
10
|
+
return _extend(target, sources, false, new Map());
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Copies all enumerable own properties from one or more source objects to a target object
|
|
14
|
+
* and copies enumerable properties from nested source objects to nested target objects
|
|
15
|
+
* It returns the modified target object
|
|
16
|
+
* @param target - target object
|
|
17
|
+
* @param sources - source objects
|
|
18
|
+
*/
|
|
19
|
+
export function extendAll(target, ...sources) {
|
|
20
|
+
return _extend(target, sources, true, new Map());
|
|
21
|
+
}
|
|
22
|
+
function _extend(target, sources, deep, visited) {
|
|
23
|
+
sources.forEach(obj => {
|
|
24
|
+
if (obj !== target && !visited.has(obj) && isUsualObject(obj)) {
|
|
25
|
+
visited.set(obj, true);
|
|
26
|
+
forEachObj(obj, (value, key) => {
|
|
27
|
+
const descriptor = Object.getOwnPropertyDescriptor(obj, key);
|
|
28
|
+
if ((descriptor === null || descriptor === void 0 ? void 0 : descriptor.get) || (descriptor === null || descriptor === void 0 ? void 0 : descriptor.set)) {
|
|
29
|
+
Object.defineProperty(target, key, descriptor);
|
|
30
|
+
}
|
|
31
|
+
else if (isDefined(value)) {
|
|
32
|
+
if (deep) {
|
|
33
|
+
if (isUsualObject(target[key]) && isUsualObject(obj[key])) {
|
|
34
|
+
target[key] = _extend(target[key], [obj[key]], true, visited);
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
target[key] = copy(obj[key]);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
target[key] = obj[key];
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
return target;
|
|
48
|
+
}
|
|
49
|
+
//# sourceMappingURL=extend.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"extend.js","sourceRoot":"","sources":["../../../../package/src/obj/extend/extend.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,IAAI,EAAE,SAAS,EAAE,aAAa,EAAyB,MAAM,QAAQ,CAAC;AAC9E,OAAO,EAAC,UAAU,EAAC,MAAM,KAAK,CAAC;AAE/B;;;;;GAKG;AACH,MAAM,UAAU,MAAM,CAAiC,MAAS,EAC9D,GAAG,OAAU;IACb,OAAO,OAAO,CAAC,MAAM,EAAE,OAAO,EAAE,KAAK,EAAE,IAAI,GAAG,EAAa,CAAC,CAAC;AAC/D,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,SAAS,CAAiC,MAAS,EACjE,GAAG,OAAU;IACb,OAAO,OAAO,CAAC,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,GAAG,EAAa,CAAC,CAAC;AAC9D,CAAC;AAED,SAAS,OAAO,CAAiC,MAAS,EAAE,OAAU,EAAE,IAAa,EACnF,OAAuB;IACvB,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE;QACpB,IAAI,GAAG,KAAK,MAAM,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,aAAa,CAAC,GAAG,CAAC,EAAE;YAC7D,OAAO,CAAC,GAAG,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;YAEvB,UAAU,CAAC,GAAG,EAAE,CAAC,KAAK,EAAE,GAAG,EAAE,EAAE;gBAC7B,MAAM,UAAU,GAAG,MAAM,CAAC,wBAAwB,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;gBAE7D,IAAI,CAAA,UAAU,aAAV,UAAU,uBAAV,UAAU,CAAE,GAAG,MAAI,UAAU,aAAV,UAAU,uBAAV,UAAU,CAAE,GAAG,CAAA,EAAE;oBACtC,MAAM,CAAC,cAAc,CAAC,MAAM,EAAE,GAAG,EAAE,UAAU,CAAC,CAAC;iBAChD;qBAAM,IAAI,SAAS,CAAC,KAAK,CAAC,EAAE;oBAC3B,IAAI,IAAI,EAAE;wBACR,IAAI,aAAa,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,aAAa,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,EAAE;4BACnD,MAAO,CAAC,GAAG,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;yBACtE;6BAAM;4BACC,MAAO,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC;yBACrC;qBACF;yBAAM;wBACC,MAAO,CAAC,GAAG,CAAC,GAAG,GAAG,CAAC,GAAG,CAAC,CAAC;qBAC/B;iBACF;YACH,CAAC,CAAC,CAAC;SACJ;IACH,CAAC,CAAC,CAAC;IAEH,OAA8C,MAAM,CAAC;AACvD,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Obj, ValueUnion } from '../../';
|
|
2
|
+
/**
|
|
3
|
+
* Iterates through all the fields of an object and calls a handler for each field
|
|
4
|
+
* If the handler returns INTERRUPT, the loop will be interrupted
|
|
5
|
+
* @param obj - any object
|
|
6
|
+
* @param handler - function called for each field
|
|
7
|
+
*/
|
|
8
|
+
export declare function forEachObj<T extends Obj, K extends keyof T>(obj: T, handler: (value: ValueUnion<T>, key: K, obj: T) => any): void;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { INTERRUPT } from '../../';
|
|
2
|
+
import { hasOwn } from '../';
|
|
3
|
+
/**
|
|
4
|
+
* Iterates through all the fields of an object and calls a handler for each field
|
|
5
|
+
* If the handler returns INTERRUPT, the loop will be interrupted
|
|
6
|
+
* @param obj - any object
|
|
7
|
+
* @param handler - function called for each field
|
|
8
|
+
*/
|
|
9
|
+
export function forEachObj(obj, handler) {
|
|
10
|
+
for (const key in obj) {
|
|
11
|
+
if (hasOwn(obj, key) && handler(obj[key], key, obj) === INTERRUPT) {
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=for-each-obj.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"for-each-obj.js","sourceRoot":"","sources":["../../../../package/src/obj/for-each-obj/for-each-obj.ts"],"names":[],"mappings":"AAAA,OAAO,EAAM,SAAS,EAAa,MAAM,QAAQ,CAAC;AAClD,OAAO,EAAC,MAAM,EAAC,MAAM,KAAK,CAAC;AAE3B;;;;;GAKG;AACH,MAAM,UAAU,UAAU,CAAmC,GAAM,EACjE,OAAsD;IACtD,KAAK,MAAM,GAAG,IAAI,GAAG,EAAE;QACrB,IAAI,MAAM,CAAC,GAAG,EAAE,GAAG,CAAC,IAAI,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,EAAsB,GAAG,EAAE,GAAG,CAAC,KAAK,SAAS,EAAE;YACrF,OAAO;SACR;KACF;AACH,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Obj, NumStrSym } from '../../';
|
|
2
|
+
/**
|
|
3
|
+
* Returns true if the object has the indicated property as its own property.
|
|
4
|
+
* If the property is inherited, or does not exist, the method returns false
|
|
5
|
+
* @param obj - any object
|
|
6
|
+
* @param property
|
|
7
|
+
*/
|
|
8
|
+
export declare function hasOwn(obj: Obj, property: NumStrSym): boolean;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns true if the object has the indicated property as its own property.
|
|
3
|
+
* If the property is inherited, or does not exist, the method returns false
|
|
4
|
+
* @param obj - any object
|
|
5
|
+
* @param property
|
|
6
|
+
*/
|
|
7
|
+
export function hasOwn(obj, property) {
|
|
8
|
+
// todo: change on 'Object.hasOwn' with ES2022
|
|
9
|
+
return Object.prototype.hasOwnProperty.call(obj, property);
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=has-own.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"has-own.js","sourceRoot":"","sources":["../../../../package/src/obj/has-own/has-own.ts"],"names":[],"mappings":"AAEA;;;;;GAKG;AACH,MAAM,UAAU,MAAM,CAAC,GAAQ,EAAE,QAAmB;IAClD,8CAA8C;IAC9C,OAAO,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC,IAAI,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC;AAC7D,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Obj } from '../../';
|
|
2
|
+
/**
|
|
3
|
+
* Returns a new object with the specified set of fields
|
|
4
|
+
* @param obj - any object
|
|
5
|
+
* @param fields - set of fields to be included
|
|
6
|
+
*/
|
|
7
|
+
export declare function include<T extends Obj, K extends keyof T>(obj: T, ...fields: K[]): Pick<T, K>;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { isDefined } from '../../';
|
|
2
|
+
import { hasOwn } from '../';
|
|
3
|
+
/**
|
|
4
|
+
* Returns a new object with the specified set of fields
|
|
5
|
+
* @param obj - any object
|
|
6
|
+
* @param fields - set of fields to be included
|
|
7
|
+
*/
|
|
8
|
+
export function include(obj, ...fields) {
|
|
9
|
+
const result = {};
|
|
10
|
+
fields.forEach(key => {
|
|
11
|
+
if (hasOwn(obj, key) && isDefined(obj[key])) {
|
|
12
|
+
result[key] = obj[key];
|
|
13
|
+
}
|
|
14
|
+
});
|
|
15
|
+
return result;
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=include.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"include.js","sourceRoot":"","sources":["../../../../package/src/obj/include/include.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,SAAS,EAAM,MAAM,QAAQ,CAAC;AACtC,OAAO,EAAC,MAAM,EAAC,MAAM,KAAK,CAAC;AAE3B;;;;GAIG;AACH,MAAM,UAAU,OAAO,CAAmC,GAAM,EAAE,GAAG,MAAW;IAC9E,MAAM,MAAM,GAAe,EAAE,CAAC;IAC9B,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE;QACnB,IAAI,MAAM,CAAC,GAAG,EAAE,GAAG,CAAC,IAAI,SAAS,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,EAAE;YAC3C,MAAM,CAAC,GAAG,CAAC,GAAG,GAAG,CAAC,GAAG,CAAC,CAAC;SACxB;IACH,CAAC,CAAC,CAAC;IACH,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
package/obj/index.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export * from './types';
|
|
2
|
+
export * from './has-own/has-own';
|
|
3
|
+
export * from './for-each-obj/for-each-obj';
|
|
4
|
+
export * from './keys/keys';
|
|
5
|
+
export * from './values/values';
|
|
6
|
+
export * from './include/include';
|
|
7
|
+
export * from './exclude/exclude';
|
|
8
|
+
export * from './constant/constant';
|
|
9
|
+
export * from './deep-constant/deep-constant';
|
|
10
|
+
export * from './map-obj/map-obj';
|
|
11
|
+
export * from './map-obj-to-arr/map-obj-to-arr';
|
|
12
|
+
export * from './diff-obj/diff-obj';
|
|
13
|
+
export * from './extend/extend';
|
package/obj/index.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export * from './types';
|
|
2
|
+
export * from './has-own/has-own';
|
|
3
|
+
export * from './for-each-obj/for-each-obj';
|
|
4
|
+
export * from './keys/keys';
|
|
5
|
+
export * from './values/values';
|
|
6
|
+
export * from './include/include';
|
|
7
|
+
export * from './exclude/exclude';
|
|
8
|
+
export * from './constant/constant';
|
|
9
|
+
export * from './deep-constant/deep-constant';
|
|
10
|
+
export * from './map-obj/map-obj';
|
|
11
|
+
export * from './map-obj-to-arr/map-obj-to-arr';
|
|
12
|
+
export * from './diff-obj/diff-obj';
|
|
13
|
+
export * from './extend/extend';
|
|
14
|
+
//# sourceMappingURL=index.js.map
|
package/obj/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../package/src/obj/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,cAAc,mBAAmB,CAAC;AAClC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,aAAa,CAAC;AAC5B,cAAc,iBAAiB,CAAC;AAChC,cAAc,mBAAmB,CAAC;AAClC,cAAc,mBAAmB,CAAC;AAClC,cAAc,qBAAqB,CAAC;AACpC,cAAc,+BAA+B,CAAC;AAC9C,cAAc,mBAAmB,CAAC;AAClC,cAAc,iCAAiC,CAAC;AAChD,cAAc,qBAAqB,CAAC;AACpC,cAAc,iBAAiB,CAAC"}
|
package/obj/keys/keys.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"keys.js","sourceRoot":"","sources":["../../../../package/src/obj/keys/keys.ts"],"names":[],"mappings":"AAEA;;;GAGG;AACH,MAAM,UAAU,IAAI,CAAgB,GAAM;IACxC,OAAO,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAC1B,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Obj, ValueUnion } from '../../';
|
|
2
|
+
/**
|
|
3
|
+
* Returns a new object, which has the mapped values of object fields
|
|
4
|
+
* @param obj - any object
|
|
5
|
+
* @param handler - function called for each field
|
|
6
|
+
*/
|
|
7
|
+
export declare function mapObj<T extends Obj, K extends keyof T, R>(obj: T, handler: (value: ValueUnion<T>, key: K, obj: T) => R): Record<K, R>;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { forEachObj } from '../';
|
|
2
|
+
/**
|
|
3
|
+
* Returns a new object, which has the mapped values of object fields
|
|
4
|
+
* @param obj - any object
|
|
5
|
+
* @param handler - function called for each field
|
|
6
|
+
*/
|
|
7
|
+
export function mapObj(obj, handler) {
|
|
8
|
+
const result = {};
|
|
9
|
+
forEachObj(obj, (value, key) => result[key] = handler(value, key, obj));
|
|
10
|
+
return result;
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=map-obj.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"map-obj.js","sourceRoot":"","sources":["../../../../package/src/obj/map-obj/map-obj.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,UAAU,EAAC,MAAM,KAAK,CAAC;AAE/B;;;;GAIG;AACH,MAAM,UAAU,MAAM,CAAsC,GAAM,EAChE,OAAoD;IACpD,MAAM,MAAM,GAAiB,EAAE,CAAC;IAChC,UAAU,CAAC,GAAG,EAAE,CAAC,KAAK,EAAE,GAAG,EAAE,EAAE,CAAC,MAAM,CAAI,GAAG,CAAC,GAAG,OAAO,CAAC,KAAK,EAAK,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC;IAC9E,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Obj, ValueUnion } from '../../';
|
|
2
|
+
/**
|
|
3
|
+
* Returns an array, which has the mapped values of object fields
|
|
4
|
+
* @param obj - any object
|
|
5
|
+
* @param handler - function called for each field
|
|
6
|
+
*/
|
|
7
|
+
export declare function mapObjToArr<T extends Obj, K extends keyof T, R>(obj: T, handler: (value: ValueUnion<T>, key: K, obj: T) => R): R[];
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { forEachObj } from '../';
|
|
2
|
+
/**
|
|
3
|
+
* Returns an array, which has the mapped values of object fields
|
|
4
|
+
* @param obj - any object
|
|
5
|
+
* @param handler - function called for each field
|
|
6
|
+
*/
|
|
7
|
+
export function mapObjToArr(obj, handler) {
|
|
8
|
+
const result = [];
|
|
9
|
+
forEachObj(obj, (value, key) => result.push(handler(value, key, obj)));
|
|
10
|
+
return result;
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=map-obj-to-arr.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"map-obj-to-arr.js","sourceRoot":"","sources":["../../../../package/src/obj/map-obj-to-arr/map-obj-to-arr.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,UAAU,EAAC,MAAM,KAAK,CAAC;AAE/B;;;;GAIG;AACH,MAAM,UAAU,WAAW,CAAsC,GAAM,EACrE,OAAoD;IACpD,MAAM,MAAM,GAAQ,EAAE,CAAC;IACvB,UAAU,CAAC,GAAG,EAAE,CAAC,KAAK,EAAE,GAAG,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,EAAK,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC;IAC1E,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
package/obj/types.d.ts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { Obj } from '../';
|
|
2
|
+
/**
|
|
3
|
+
* Represents response of the diffObj function
|
|
4
|
+
*/
|
|
5
|
+
export interface ObjDiff<T extends Obj> {
|
|
6
|
+
/**
|
|
7
|
+
* Contains equal fields for object 1 and object 2
|
|
8
|
+
*/
|
|
9
|
+
equal: Partial<T>;
|
|
10
|
+
/**
|
|
11
|
+
* Contains fields that are only in object 1 or are not equal to the fields of object 2
|
|
12
|
+
*/
|
|
13
|
+
notEqual1: Partial<T>;
|
|
14
|
+
/**
|
|
15
|
+
* Contains fields that are only in object 2 or are not equal to the fields of object 1
|
|
16
|
+
*/
|
|
17
|
+
notEqual2: Partial<T>;
|
|
18
|
+
/**
|
|
19
|
+
* Contains fields that are only in object 1
|
|
20
|
+
*/
|
|
21
|
+
only1: Partial<T>;
|
|
22
|
+
/**
|
|
23
|
+
* Contains fields that are only in object 2
|
|
24
|
+
*/
|
|
25
|
+
only2: Partial<T>;
|
|
26
|
+
/**
|
|
27
|
+
* True if notEqual1 and notEqual2 are empty, otherwise false
|
|
28
|
+
*/
|
|
29
|
+
isEqual: boolean;
|
|
30
|
+
}
|
package/obj/types.js
ADDED
package/obj/types.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../package/src/obj/types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { forEachObj } from '../';
|
|
2
|
+
/**
|
|
3
|
+
* Returns an array of values for each object's own enumerable property
|
|
4
|
+
* @param obj - any object
|
|
5
|
+
*/
|
|
6
|
+
export function values(obj) {
|
|
7
|
+
const result = [];
|
|
8
|
+
forEachObj(obj, value => result.push(value));
|
|
9
|
+
return result;
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=values.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"values.js","sourceRoot":"","sources":["../../../../package/src/obj/values/values.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,UAAU,EAAC,MAAM,KAAK,CAAC;AAE/B;;;GAGG;AACH,MAAM,UAAU,MAAM,CAAI,GAAW;IACnC,MAAM,MAAM,GAAQ,EAAE,CAAC;IACvB,UAAU,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;IAC7C,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@bitfiber/utils",
|
|
3
|
+
"description": "Collection of versatile utility functions for Javascript",
|
|
4
|
+
"version": "1.0.0",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"module": "./src/index.js",
|
|
7
|
+
"main": "./index.js",
|
|
8
|
+
"types": "./index.d.ts",
|
|
9
|
+
"typesVersions": {
|
|
10
|
+
">=4.8.2": {
|
|
11
|
+
"*": [
|
|
12
|
+
"*.d.ts"
|
|
13
|
+
]
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"sideEffects": false,
|
|
17
|
+
"exports": {
|
|
18
|
+
".": {
|
|
19
|
+
"types": "./index.d.ts",
|
|
20
|
+
"default": "./index.js"
|
|
21
|
+
},
|
|
22
|
+
"./arr": {
|
|
23
|
+
"types": "./arr/index.d.ts",
|
|
24
|
+
"default": "./arr/index.js"
|
|
25
|
+
},
|
|
26
|
+
"./obj": {
|
|
27
|
+
"types": "./obj/index.d.ts",
|
|
28
|
+
"default": "./obj/index.js"
|
|
29
|
+
},
|
|
30
|
+
"./str": {
|
|
31
|
+
"types": "./str/index.d.ts",
|
|
32
|
+
"default": "./str/index.js"
|
|
33
|
+
},
|
|
34
|
+
"./num": {
|
|
35
|
+
"types": "./num/index.d.ts",
|
|
36
|
+
"default": "./num/index.js"
|
|
37
|
+
},
|
|
38
|
+
"./dom": {
|
|
39
|
+
"types": "./dom/index.d.ts",
|
|
40
|
+
"default": "./dom/index.js"
|
|
41
|
+
},
|
|
42
|
+
"./env": {
|
|
43
|
+
"types": "./env/index.d.ts",
|
|
44
|
+
"default": "./env/index.js"
|
|
45
|
+
},
|
|
46
|
+
"./package.json": "./package.json"
|
|
47
|
+
},
|
|
48
|
+
"repository": {
|
|
49
|
+
"type": "git",
|
|
50
|
+
"url": "https://github.com/bitfiber/utils.git",
|
|
51
|
+
"directory": "utils"
|
|
52
|
+
},
|
|
53
|
+
"keywords": [
|
|
54
|
+
"Javascript",
|
|
55
|
+
"Typescript",
|
|
56
|
+
"Utils",
|
|
57
|
+
"Utilities",
|
|
58
|
+
"Helpers"
|
|
59
|
+
],
|
|
60
|
+
"author": {
|
|
61
|
+
"name": "Zmanovskyi Oleksandr",
|
|
62
|
+
"email": "bitfiber.web@gmail.com"
|
|
63
|
+
},
|
|
64
|
+
"license": "Apache 2.0",
|
|
65
|
+
"bugs": {
|
|
66
|
+
"url": "https://github.com/bitfiber/utils/issues"
|
|
67
|
+
},
|
|
68
|
+
"homepage": "https://github.com/bitfiber/utils",
|
|
69
|
+
"dependencies": {
|
|
70
|
+
"tslib": "^2.3.0"
|
|
71
|
+
},
|
|
72
|
+
"peerDependencies": {}
|
|
73
|
+
}
|
package/str/index.d.ts
ADDED
package/str/index.js
ADDED
package/str/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../package/src/str/index.ts"],"names":[],"mappings":"AAAA,cAAc,6BAA6B,CAAC;AAC5C,cAAc,+BAA+B,CAAC;AAC9C,cAAc,mBAAmB,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Converts a given string into camelCase format.
|
|
3
|
+
* CamelCase is a convention where a multi-word identifier is formed by joining words together,
|
|
4
|
+
* each starting with a capital letter except for the initial word.
|
|
5
|
+
* This function takes a string as input, which may be in various formats such as snake_case,
|
|
6
|
+
* kebab-case, or space-separated words, and transforms it into camelCase.
|
|
7
|
+
* @param str - the input string that needs to be converted to camelCase
|
|
8
|
+
* @param separators - an array of any separators, default '-', '_', ' '
|
|
9
|
+
*/
|
|
10
|
+
export declare function toCamelCase(str: string, separators?: string[]): string;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Converts a given string into camelCase format.
|
|
3
|
+
* CamelCase is a convention where a multi-word identifier is formed by joining words together,
|
|
4
|
+
* each starting with a capital letter except for the initial word.
|
|
5
|
+
* This function takes a string as input, which may be in various formats such as snake_case,
|
|
6
|
+
* kebab-case, or space-separated words, and transforms it into camelCase.
|
|
7
|
+
* @param str - the input string that needs to be converted to camelCase
|
|
8
|
+
* @param separators - an array of any separators, default '-', '_', ' '
|
|
9
|
+
*/
|
|
10
|
+
export function toCamelCase(str, separators = ['-', '_', ' ']) {
|
|
11
|
+
return separators.reduce((acc, separator) => {
|
|
12
|
+
const reg = new RegExp(separator + '([\\da-z])', 'gi');
|
|
13
|
+
return acc.replace(reg, (all, letter) => {
|
|
14
|
+
return letter.toUpperCase();
|
|
15
|
+
});
|
|
16
|
+
}, str);
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=to-camel-case.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"to-camel-case.js","sourceRoot":"","sources":["../../../../package/src/str/to-camel-case/to-camel-case.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,MAAM,UAAU,WAAW,CAAC,GAAW,EAAE,aAAuB,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC;IAC7E,OAAO,UAAU,CAAC,MAAM,CAAC,CAAC,GAAW,EAAE,SAAiB,EAAE,EAAE;QAC1D,MAAM,GAAG,GAAG,IAAI,MAAM,CAAC,SAAS,GAAG,YAAY,EAAE,IAAI,CAAC,CAAC;QACvD,OAAO,GAAG,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,GAAW,EAAE,MAAc,EAAE,EAAE;YACtD,OAAO,MAAM,CAAC,WAAW,EAAE,CAAC;QAC9B,CAAC,CAAC,CAAC;IACL,CAAC,EAAE,GAAG,CAAC,CAAC;AACV,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generates a hash value for a given input string for insecure purposes
|
|
3
|
+
* Hash functions are commonly used to convert input data into a fixed-length string of characters,
|
|
4
|
+
* providing a unique representation of the input
|
|
5
|
+
* @param str - The input string to be hashed
|
|
6
|
+
*/
|
|
7
|
+
export declare function toHash(str: string): string;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generates a hash value for a given input string for insecure purposes
|
|
3
|
+
* Hash functions are commonly used to convert input data into a fixed-length string of characters,
|
|
4
|
+
* providing a unique representation of the input
|
|
5
|
+
* @param str - The input string to be hashed
|
|
6
|
+
*/
|
|
7
|
+
export function toHash(str) {
|
|
8
|
+
if (str) {
|
|
9
|
+
let hash = 0;
|
|
10
|
+
for (let i = 0; i < str.length; i++) {
|
|
11
|
+
const char = str.charCodeAt(i);
|
|
12
|
+
hash = ((hash << 5) - hash) + char;
|
|
13
|
+
hash = hash & hash;
|
|
14
|
+
}
|
|
15
|
+
return hash < 0 ? 'hn' + Math.abs(hash) : 'hp' + hash;
|
|
16
|
+
}
|
|
17
|
+
else {
|
|
18
|
+
return '';
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=to-hash.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"to-hash.js","sourceRoot":"","sources":["../../../../package/src/str/to-hash/to-hash.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,UAAU,MAAM,CAAC,GAAW;IAChC,IAAI,GAAG,EAAE;QACP,IAAI,IAAI,GAAG,CAAC,CAAC;QAEb,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,GAAG,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;YACnC,MAAM,IAAI,GAAG,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;YAC/B,IAAI,GAAG,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,GAAG,IAAI,CAAC,GAAG,IAAI,CAAC;YACnC,IAAI,GAAG,IAAI,GAAG,IAAI,CAAC;SACpB;QAED,OAAO,IAAI,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,GAAG,IAAI,CAAC;KACvD;SAAM;QACL,OAAO,EAAE,CAAC;KACX;AACH,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Takes a string as input and returns a new string with the initial letter in uppercase,
|
|
3
|
+
* while preserving the rest of the string
|
|
4
|
+
* @param str - The input string whose first letter needs to be capitalized
|
|
5
|
+
*/
|
|
6
|
+
export declare function withCapital(str: string): string;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Takes a string as input and returns a new string with the initial letter in uppercase,
|
|
3
|
+
* while preserving the rest of the string
|
|
4
|
+
* @param str - The input string whose first letter needs to be capitalized
|
|
5
|
+
*/
|
|
6
|
+
export function withCapital(str) {
|
|
7
|
+
return str.charAt(0).toUpperCase() + str.substring(1);
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=with-capital.js.map
|