@dereekb/util 7.4.0 → 7.5.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/CHANGELOG.md CHANGED
@@ -2,6 +2,15 @@
2
2
 
3
3
  This file was generated using [@jscutlery/semver](https://github.com/jscutlery/semver).
4
4
 
5
+ # [7.5.0](https://github.com/dereekb/dbx-components/compare/v7.4.0-dev...v7.5.0) (2022-06-08)
6
+
7
+
8
+ ### Features
9
+
10
+ * added UseFunction, MappedUseFunction ([84b6cbe](https://github.com/dereekb/dbx-components/commit/84b6cbe23b7e020ad7de49633642429d7e32f7d4))
11
+
12
+
13
+
5
14
  # [7.4.0](https://github.com/dereekb/dbx-components/compare/v7.3.0-dev...v7.4.0) (2022-06-08)
6
15
 
7
16
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dereekb/util",
3
- "version": "7.4.0",
3
+ "version": "7.5.0",
4
4
  "type": "commonjs",
5
5
  "exports": {
6
6
  ".": {
@@ -5,3 +5,4 @@ export * from './maybe.type';
5
5
  export * from './maybe';
6
6
  export * from './modifier';
7
7
  export * from './url';
8
+ export * from './use';
@@ -8,4 +8,5 @@ tslib_1.__exportStar(require("./maybe.type"), exports);
8
8
  tslib_1.__exportStar(require("./maybe"), exports);
9
9
  tslib_1.__exportStar(require("./modifier"), exports);
10
10
  tslib_1.__exportStar(require("./url"), exports);
11
+ tslib_1.__exportStar(require("./use"), exports);
11
12
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../packages/util/src/lib/value/index.ts"],"names":[],"mappings":";;;AAAA,kDAAwB;AACxB,kDAAwB;AACxB,gDAAsB;AACtB,uDAA6B;AAC7B,kDAAwB;AACxB,qDAA2B;AAC3B,gDAAsB"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../packages/util/src/lib/value/index.ts"],"names":[],"mappings":";;;AAAA,kDAAwB;AACxB,kDAAwB;AACxB,gDAAsB;AACtB,uDAA6B;AAC7B,kDAAwB;AACxB,qDAA2B;AAC3B,gDAAsB;AACtB,gDAAsB"}
@@ -0,0 +1,22 @@
1
+ import { GetterOrValue } from '../getter';
2
+ import { MapFunction } from './map';
3
+ import { Maybe } from './maybe.type';
4
+ /**
5
+ * A map function with the intent of using the input value, and returning another value.
6
+ */
7
+ export declare type UseValue<I, O = void> = MapFunction<I, O>;
8
+ export declare function useValue<I, O = void>(input: Maybe<I>, use: UseValue<I, O>, defaultValue?: Maybe<GetterOrValue<O>>): Maybe<O>;
9
+ export declare type UseFunction<I> = MappedUseFunction<I, I>;
10
+ export declare type MappedUseFunction<A, I> = <O = void>(input: Maybe<A>, use: UseValue<I, O>, defaultValue?: Maybe<GetterOrValue<O>>) => Maybe<O>;
11
+ /**
12
+ * Creates a MappedUseFunction.
13
+ */
14
+ export declare function mappedUseFunction<A, I>(map: MapFunction<A, Maybe<I>>): MappedUseFunction<A, I>;
15
+ /**
16
+ * Runs a pre-determined function on the input to return a value.
17
+ */
18
+ export declare type UseContextFunction<I> = <O>(input: Maybe<I>) => Maybe<O>;
19
+ /**
20
+ * Creates a UseContextFunction.
21
+ */
22
+ export declare function useContextFunction<I, O>(use: UseValue<I, O>, defaultValue?: GetterOrValue<O>): UseContextFunction<I>;
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useContextFunction = exports.mappedUseFunction = exports.useValue = void 0;
4
+ const getter_1 = require("../getter");
5
+ function useValue(input, use, defaultValue) {
6
+ let result;
7
+ if (input != null) {
8
+ result = use(input);
9
+ }
10
+ else {
11
+ result = (0, getter_1.getValueFromGetter)(defaultValue);
12
+ }
13
+ return result;
14
+ }
15
+ exports.useValue = useValue;
16
+ /**
17
+ * Creates a MappedUseFunction.
18
+ */
19
+ function mappedUseFunction(map) {
20
+ return ((input, useFn, defaultValue) => {
21
+ return useValue(input, ((value) => useValue(map(value), useFn, defaultValue)), defaultValue);
22
+ });
23
+ }
24
+ exports.mappedUseFunction = mappedUseFunction;
25
+ /**
26
+ * Creates a UseContextFunction.
27
+ */
28
+ function useContextFunction(use, defaultValue) {
29
+ return ((input) => {
30
+ let result;
31
+ if (input != null) {
32
+ result = use(input);
33
+ }
34
+ else {
35
+ result = (0, getter_1.getValueFromGetter)(defaultValue);
36
+ }
37
+ return result;
38
+ });
39
+ }
40
+ exports.useContextFunction = useContextFunction;
41
+ //# sourceMappingURL=use.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use.js","sourceRoot":"","sources":["../../../../../../packages/util/src/lib/value/use.ts"],"names":[],"mappings":";;;AAAA,sCAA8D;AAU9D,SAAgB,QAAQ,CAAc,KAAe,EAAE,GAAmB,EAAE,YAAsC;IAChH,IAAI,MAAgB,CAAC;IAErB,IAAI,KAAK,IAAI,IAAI,EAAE;QACjB,MAAM,GAAG,GAAG,CAAC,KAAK,CAAa,CAAC;KACjC;SAAM;QACL,MAAM,GAAG,IAAA,2BAAkB,EAAC,YAAY,CAAC,CAAC;KAC3C;IAED,OAAO,MAAM,CAAC;AAChB,CAAC;AAVD,4BAUC;AAKD;;GAEG;AACH,SAAgB,iBAAiB,CAAO,GAA6B;IACnE,OAAO,CAAC,CAAW,KAAe,EAAE,KAAqB,EAAE,YAAsC,EAAE,EAAE;QACnG,OAAO,QAAQ,CAAO,KAAK,EAAE,CAAC,CAAC,KAAQ,EAAE,EAAE,CAAC,QAAQ,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,KAAK,EAAE,YAAY,CAAC,CAAmB,EAAE,YAAY,CAAC,CAAC;IAC1H,CAAC,CAA4B,CAAC;AAChC,CAAC;AAJD,8CAIC;AAOD;;GAEG;AACH,SAAgB,kBAAkB,CAAO,GAAmB,EAAE,YAA+B;IAC3F,OAAO,CAAC,CAAC,KAAe,EAAE,EAAE;QAC1B,IAAI,MAAgB,CAAC;QAErB,IAAI,KAAK,IAAI,IAAI,EAAE;YACjB,MAAM,GAAG,GAAG,CAAC,KAAK,CAAC,CAAC;SACrB;aAAM;YACL,MAAM,GAAG,IAAA,2BAAkB,EAAC,YAAY,CAAC,CAAC;SAC3C;QAED,OAAO,MAAM,CAAC;IAChB,CAAC,CAA0B,CAAC;AAC9B,CAAC;AAZD,gDAYC"}
package/test/CHANGELOG.md CHANGED
@@ -2,6 +2,10 @@
2
2
 
3
3
  This file was generated using [@jscutlery/semver](https://github.com/jscutlery/semver).
4
4
 
5
+ # [7.5.0](https://github.com/dereekb/dbx-components/compare/v7.4.0-dev...v7.5.0) (2022-06-08)
6
+
7
+
8
+
5
9
  # [7.4.0](https://github.com/dereekb/dbx-components/compare/v7.3.0-dev...v7.4.0) (2022-06-08)
6
10
 
7
11
 
package/test/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "@dereekb/util/test",
3
- "version": "7.4.0",
3
+ "version": "7.5.0",
4
4
  "main": "./src/index.js",
5
5
  "typings": "./src/index.d.ts",
6
6
  "dependencies": {},
7
7
  "peerDependencies": {
8
- "@dereekb/util": "7.4.0",
8
+ "@dereekb/util": "7.5.0",
9
9
  "make-error": "^1.3.0",
10
10
  "ts-essentials": "^9.1.2",
11
11
  "extra-set": "^2.2.11",