@dawntech/dwntbots-utils 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,11 @@
1
+ # utils
2
+
3
+ This library was generated with [Nx](https://nx.dev).
4
+
5
+ ## Building
6
+
7
+ Run `nx build utils` to build the library.
8
+
9
+ ## Running unit tests
10
+
11
+ Run `nx test utils` to execute the unit tests via [Jest](https://jestjs.io).
package/package.json ADDED
@@ -0,0 +1,12 @@
1
+ {
2
+ "name": "@dawntech/dwntbots-utils",
3
+ "version": "0.0.2",
4
+ "type": "commonjs",
5
+ "main": "./src/index.js",
6
+ "types": "./src/index.d.ts",
7
+ "dependencies": {},
8
+ "peerDependencies": {
9
+ "rxjs": "7.6.0",
10
+ "tslib": "2.4.1"
11
+ }
12
+ }
package/src/index.d.ts ADDED
@@ -0,0 +1 @@
1
+ export * from './lib/';
package/src/index.js ADDED
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ tslib_1.__exportStar(require("./lib/"), exports);
5
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../libs/utils/src/index.ts"],"names":[],"mappings":";;;AAAA,iDAAuB"}
@@ -0,0 +1,3 @@
1
+ export * from "./rxjs";
2
+ export * from "./storage";
3
+ export * from "./types";
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ tslib_1.__exportStar(require("./rxjs"), exports);
5
+ tslib_1.__exportStar(require("./storage"), exports);
6
+ tslib_1.__exportStar(require("./types"), exports);
7
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../libs/utils/src/lib/index.ts"],"names":[],"mappings":";;;AAAA,iDAAuB;AACvB,oDAA0B;AAC1B,kDAAwB"}
@@ -0,0 +1,26 @@
1
+ import { Subject, Observer, Observable, Subscriber, Subscription } from "rxjs";
2
+ export declare const fromMutationObserver: (target: HTMLElement, config: Object) => Observable<MutationRecord[]>;
3
+ export declare class AnonymousSubject<T> extends Subject<T> {
4
+ /** @deprecated Internal implementation detail, do not use directly. Will be made internal in v8. */
5
+ destination?: Observer<T> | undefined;
6
+ constructor(
7
+ /** @deprecated Internal implementation detail, do not use directly. Will be made internal in v8. */
8
+ destination?: Observer<T> | undefined, source?: Observable<T>);
9
+ next(value: T): void;
10
+ error(err: any): void;
11
+ complete(): void;
12
+ /** @internal */
13
+ protected _subscribe(subscriber: Subscriber<T>): Subscription;
14
+ }
15
+ /**
16
+ * FROM: https://github.com/w11k/rx-ninja/tree/99db3f8dbdecbc227014f97a06a407793ceb61ed/src/operators
17
+ * Emit only new values if the value changes in a deep equal comparison.
18
+ *
19
+ * @param maxDepth of iteration to determine if datastructures are equal. When you intend to iterate over all
20
+ * properties regardless of depth use INFINITY. A depth of 0 uses the same comparison as distinctUntilChanged.
21
+ *
22
+ * <img src="media://distinct-until-changed-deep.svg" alt="marble">
23
+ */
24
+ export declare function distinctUntilChangedDeep(maxDepth: number): <T>(source: Observable<T>) => Observable<T>;
25
+ /** thanks to Daniil Andreyevich Baunov https://stackoverflow.com/a/45683145/6081477 */
26
+ export declare function deepEqual(a: any, b: any, maxDepth: number, actualDepth?: number): boolean;
@@ -0,0 +1,92 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.deepEqual = exports.distinctUntilChangedDeep = exports.AnonymousSubject = exports.fromMutationObserver = void 0;
4
+ const rxjs_1 = require("rxjs");
5
+ const fromMutationObserver = (target, config) => {
6
+ return new rxjs_1.Observable((observer) => {
7
+ const mutation = new MutationObserver((mutations, instance) => {
8
+ observer.next(mutations);
9
+ });
10
+ mutation.observe(target, config);
11
+ const unsubscribe = () => {
12
+ mutation.disconnect();
13
+ };
14
+ return unsubscribe;
15
+ });
16
+ };
17
+ exports.fromMutationObserver = fromMutationObserver;
18
+ class AnonymousSubject extends rxjs_1.Subject {
19
+ constructor(
20
+ /** @deprecated Internal implementation detail, do not use directly. Will be made internal in v8. */
21
+ destination, source) {
22
+ super();
23
+ this.destination = destination;
24
+ this.source = source;
25
+ }
26
+ next(value) {
27
+ var _a, _b;
28
+ (_b = (_a = this.destination) === null || _a === void 0 ? void 0 : _a.next) === null || _b === void 0 ? void 0 : _b.call(_a, value);
29
+ }
30
+ error(err) {
31
+ var _a, _b;
32
+ (_b = (_a = this.destination) === null || _a === void 0 ? void 0 : _a.error) === null || _b === void 0 ? void 0 : _b.call(_a, err);
33
+ }
34
+ complete() {
35
+ var _a, _b;
36
+ (_b = (_a = this.destination) === null || _a === void 0 ? void 0 : _a.complete) === null || _b === void 0 ? void 0 : _b.call(_a);
37
+ }
38
+ /** @internal */
39
+ _subscribe(subscriber) {
40
+ var _a, _b;
41
+ return (_b = (_a = this.source) === null || _a === void 0 ? void 0 : _a.subscribe(subscriber)) !== null && _b !== void 0 ? _b : rxjs_1.Subscription.EMPTY;
42
+ }
43
+ }
44
+ exports.AnonymousSubject = AnonymousSubject;
45
+ /**
46
+ * FROM: https://github.com/w11k/rx-ninja/tree/99db3f8dbdecbc227014f97a06a407793ceb61ed/src/operators
47
+ * Emit only new values if the value changes in a deep equal comparison.
48
+ *
49
+ * @param maxDepth of iteration to determine if datastructures are equal. When you intend to iterate over all
50
+ * properties regardless of depth use INFINITY. A depth of 0 uses the same comparison as distinctUntilChanged.
51
+ *
52
+ * <img src="media://distinct-until-changed-deep.svg" alt="marble">
53
+ */
54
+ function distinctUntilChangedDeep(maxDepth) {
55
+ return function operatorFunction(source) {
56
+ if (maxDepth < 0) {
57
+ throw new Error(`use a positive max iteration depth or 0`);
58
+ }
59
+ return source.pipe((0, rxjs_1.distinctUntilChanged)((a, b) => deepEqual(a, b, maxDepth, 0)));
60
+ };
61
+ }
62
+ exports.distinctUntilChangedDeep = distinctUntilChangedDeep;
63
+ /** thanks to Daniil Andreyevich Baunov https://stackoverflow.com/a/45683145/6081477 */
64
+ function deepEqual(a, b, maxDepth, actualDepth = 0) {
65
+ if (a === b) {
66
+ return true;
67
+ }
68
+ if (isPrimitive(a) && isPrimitive(b)) {
69
+ return a === b;
70
+ }
71
+ if (actualDepth === maxDepth) {
72
+ return false;
73
+ }
74
+ if (Object.keys(a).length !== Object.keys(b).length) {
75
+ return false;
76
+ }
77
+ for (let key in a) {
78
+ if (!(key in b)) {
79
+ return false;
80
+ }
81
+ if (!deepEqual(a[key], b[key], maxDepth, actualDepth + 1)) {
82
+ return false;
83
+ }
84
+ }
85
+ return true;
86
+ }
87
+ exports.deepEqual = deepEqual;
88
+ //check if value is primitive
89
+ function isPrimitive(obj) {
90
+ return obj !== Object(obj);
91
+ }
92
+ //# sourceMappingURL=rxjs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rxjs.js","sourceRoot":"","sources":["../../../../../libs/utils/src/lib/rxjs.ts"],"names":[],"mappings":";;;AAAA,+BAOc;AAEP,MAAM,oBAAoB,GAAG,CAClC,MAAmB,EACnB,MAAc,EACgB,EAAE;IAChC,OAAO,IAAI,iBAAU,CAAC,CAAC,QAAQ,EAAE,EAAE;QACjC,MAAM,QAAQ,GAAG,IAAI,gBAAgB,CAAC,CAAC,SAAS,EAAE,QAAQ,EAAE,EAAE;YAC5D,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QAC3B,CAAC,CAAC,CAAC;QACH,QAAQ,CAAC,OAAO,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QACjC,MAAM,WAAW,GAAG,GAAG,EAAE;YACvB,QAAQ,CAAC,UAAU,EAAE,CAAC;QACxB,CAAC,CAAC;QACF,OAAO,WAAW,CAAC;IACrB,CAAC,CAAC,CAAC;AACL,CAAC,CAAC;AAdW,QAAA,oBAAoB,wBAc/B;AAEF,MAAa,gBAAoB,SAAQ,c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AW,CAAC,CAAC,CAAC,IAAI,WAAW,CAAC,CAAC,CAAC,EAAE;QACpC,OAAO,CAAC,KAAK,CAAC,CAAC;KAChB;IAED,IAAI,WAAW,KAAK,QAAQ,EAAE;QAC5B,OAAO,KAAK,CAAC;KACd;IAED,IAAI,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,MAAM,KAAK,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,MAAM,EAAE;QACnD,OAAO,KAAK,CAAC;KACd;IAED,KAAK,IAAI,GAAG,IAAI,CAAC,EAAE;QACjB,IAAI,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,EAAE;YACf,OAAO,KAAK,CAAC;SACd;QACD,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,GAAG,CAAC,EAAE,QAAQ,EAAE,WAAW,GAAG,CAAC,CAAC,EAAE;YACzD,OAAO,KAAK,CAAC;SACd;KACF;IAED,OAAO,IAAI,CAAC;AACd,CAAC;AAhCD,8BAgCC;AAED,6BAA6B;AAC7B,SAAS,WAAW,CAAC,GAAQ;IAC3B,OAAO,GAAG,KAAK,MAAM,CAAC,GAAG,CAAC,CAAC;AAC7B,CAAC"}
@@ -0,0 +1,4 @@
1
+ export declare const namespace: (key: string, id?: string) => string;
2
+ export declare const remove: (key: string) => void;
3
+ export declare const set: <T>(key: string, value: T) => void;
4
+ export declare const get: <T>(key: string) => T | null;
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.get = exports.set = exports.remove = exports.namespace = void 0;
4
+ const namespace = (key, id) => id ? `dawntech:${key}` : `dawntech:${id}/${key}`;
5
+ exports.namespace = namespace;
6
+ const remove = (key) => {
7
+ if (typeof window !== "undefined") {
8
+ window.localStorage.removeItem(key);
9
+ }
10
+ };
11
+ exports.remove = remove;
12
+ const set = (key, value) => {
13
+ if (typeof window !== "undefined") {
14
+ window.localStorage.setItem(key, JSON.stringify({ value }));
15
+ }
16
+ };
17
+ exports.set = set;
18
+ const get = (key) => {
19
+ if (typeof window !== "undefined") {
20
+ const item = window.localStorage.getItem(key);
21
+ if (!item)
22
+ return null;
23
+ try {
24
+ const obj = JSON.parse(item);
25
+ if ("value" in obj) {
26
+ return obj.value;
27
+ }
28
+ else {
29
+ return null;
30
+ }
31
+ }
32
+ catch (err) {
33
+ console.error(err);
34
+ return null;
35
+ }
36
+ }
37
+ return null;
38
+ };
39
+ exports.get = get;
40
+ //# sourceMappingURL=storage.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"storage.js","sourceRoot":"","sources":["../../../../../libs/utils/src/lib/storage.ts"],"names":[],"mappings":";;;AAAO,MAAM,SAAS,GAAG,CAAC,GAAW,EAAE,EAAW,EAAE,EAAE,CACpD,EAAE,CAAC,CAAC,CAAC,YAAY,GAAG,EAAE,CAAC,CAAC,CAAC,YAAY,EAAE,IAAI,GAAG,EAAE,CAAC;AADtC,QAAA,SAAS,aAC6B;AAE5C,MAAM,MAAM,GAAG,CAAC,GAAW,EAAE,EAAE;IACpC,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE;QACjC,MAAM,CAAC,YAAY,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;KACrC;AACH,CAAC,CAAC;AAJW,QAAA,MAAM,UAIjB;AAEK,MAAM,GAAG,GAAG,CAAI,GAAW,EAAE,KAAQ,EAAE,EAAE;IAC9C,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE;QACjC,MAAM,CAAC,YAAY,CAAC,OAAO,CAAC,GAAG,EAAE,IAAI,CAAC,SAAS,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC;KAC7D;AACH,CAAC,CAAC;AAJW,QAAA,GAAG,OAId;AAEK,MAAM,GAAG,GAAG,CAAI,GAAW,EAAY,EAAE;IAC9C,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE;QACjC,MAAM,IAAI,GAAG,MAAM,CAAC,YAAY,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;QAC9C,IAAI,CAAC,IAAI;YAAE,OAAO,IAAI,CAAC;QACvB,IAAI;YACF,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;YAC7B,IAAI,OAAO,IAAI,GAAG,EAAE;gBAClB,OAAO,GAAG,CAAC,KAAU,CAAC;aACvB;iBAAM;gBACL,OAAO,IAAI,CAAC;aACb;SACF;QAAC,OAAO,GAAG,EAAE;YACZ,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;YACnB,OAAO,IAAI,CAAC;SACb;KACF;IAED,OAAO,IAAI,CAAC;AACd,CAAC,CAAC;AAlBW,QAAA,GAAG,OAkBd"}
@@ -0,0 +1,2 @@
1
+ export declare type PartiallyOptional<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
2
+ export declare type PartiallyRequired<T, K extends keyof T> = Omit<T, K> & Required<Pick<T, K>>;
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../../libs/utils/src/lib/types.ts"],"names":[],"mappings":""}
@@ -0,0 +1 @@
1
+ export declare function utils(): string;
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.utils = void 0;
4
+ function utils() {
5
+ return 'utils';
6
+ }
7
+ exports.utils = utils;
8
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../../../libs/utils/src/lib/utils.ts"],"names":[],"mappings":";;;AAAA,SAAgB,KAAK;IACnB,OAAO,OAAO,CAAC;AACjB,CAAC;AAFD,sBAEC"}