map-transform 0.4.0-alpha.2 → 0.4.0-alpha.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.
@@ -3,6 +3,7 @@ import compare from './compare';
3
3
  import explode from './explode';
4
4
  import get from './get';
5
5
  import { join, split } from './joinSplit';
6
+ import logical from './logical';
6
7
  import map from './map';
7
8
  import template from './template';
8
9
  declare const _default: {
@@ -11,6 +12,7 @@ declare const _default: {
11
12
  fixed: typeof fixed;
12
13
  get: typeof get;
13
14
  join: typeof join;
15
+ logical: typeof logical;
14
16
  map: typeof map;
15
17
  split: typeof split;
16
18
  template: typeof template;
@@ -5,6 +5,7 @@ const compare_1 = require("./compare");
5
5
  const explode_1 = require("./explode");
6
6
  const get_1 = require("./get");
7
7
  const joinSplit_1 = require("./joinSplit");
8
+ const logical_1 = require("./logical");
8
9
  const map_1 = require("./map");
9
10
  const template_1 = require("./template");
10
11
  exports.default = {
@@ -13,6 +14,7 @@ exports.default = {
13
14
  fixed: value_1.fixed,
14
15
  get: get_1.default,
15
16
  join: joinSplit_1.join,
17
+ logical: logical_1.default,
16
18
  map: map_1.default,
17
19
  split: joinSplit_1.split,
18
20
  template: template_1.default,
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/functions/index.ts"],"names":[],"mappings":";;AAAA,mCAAsC;AACtC,uCAA+B;AAC/B,uCAA+B;AAC/B,+BAAuB;AACvB,2CAAyC;AACzC,+BAAuB;AACvB,yCAAiC;AAEjC,kBAAe;IACb,OAAO,EAAP,iBAAO;IACP,OAAO,EAAP,iBAAO;IACP,KAAK,EAAL,aAAK;IACL,GAAG,EAAH,aAAG;IACH,IAAI,EAAJ,gBAAI;IACJ,GAAG,EAAH,aAAG;IACH,KAAK,EAAL,iBAAK;IACL,QAAQ,EAAR,kBAAQ;IACR,KAAK,EAAL,aAAK;CACN,CAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/functions/index.ts"],"names":[],"mappings":";;AAAA,mCAAsC;AACtC,uCAA+B;AAC/B,uCAA+B;AAC/B,+BAAuB;AACvB,2CAAyC;AACzC,uCAA+B;AAC/B,+BAAuB;AACvB,yCAAiC;AAEjC,kBAAe;IACb,OAAO,EAAP,iBAAO;IACP,OAAO,EAAP,iBAAO;IACP,KAAK,EAAL,aAAK;IACL,GAAG,EAAH,aAAG;IACH,IAAI,EAAJ,gBAAI;IACJ,OAAO,EAAP,iBAAO;IACP,GAAG,EAAH,aAAG;IACH,KAAK,EAAL,iBAAK;IACL,QAAQ,EAAR,kBAAQ;IACR,KAAK,EAAL,aAAK;CACN,CAAA"}
@@ -0,0 +1,7 @@
1
+ import { Operands, Path, DataMapper } from '../types';
2
+ interface CompareOperands extends Operands {
3
+ path?: Path | Path[];
4
+ operator?: string;
5
+ }
6
+ export default function compare({ path, operator, }: CompareOperands): DataMapper;
7
+ export {};
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const pathGetter_1 = require("../utils/pathGetter");
4
+ const pathSetter_1 = require("../utils/pathSetter");
5
+ function compare({ path = '.', operator = 'AND', }) {
6
+ const pathArr = [].concat(path);
7
+ const getFns = pathArr.map(pathGetter_1.default);
8
+ const setFns = pathArr.map(pathSetter_1.default);
9
+ const logicalOp = operator === 'OR'
10
+ ? (a, b) => Boolean(a) || Boolean(b)
11
+ : (a, b) => Boolean(a) && Boolean(b);
12
+ return (data, { rev }) => {
13
+ if (rev) {
14
+ let ret = {};
15
+ const value = Boolean(data);
16
+ setFns.forEach((setFn) => {
17
+ ret = setFn(value, ret);
18
+ });
19
+ return ret;
20
+ }
21
+ else {
22
+ const values = getFns.map((fn) => fn(data));
23
+ return values.reduce(logicalOp);
24
+ }
25
+ };
26
+ }
27
+ exports.default = compare;
28
+ //# sourceMappingURL=logical.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logical.js","sourceRoot":"","sources":["../../src/functions/logical.ts"],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"version": "0.4.0-alpha.2",
3
+ "version": "0.4.0-alpha.3",
4
4
  "description": "Map and transform objects with mapping definitions",
5
5
  "author": "Kjell-Morten Bratsberg Thorsen <post@kjellmorten.no>",
6
6
  "license": "ISC",
@@ -37,7 +37,7 @@
37
37
  "homepage": "https://github.com/integreat-io/map-transform#readme",
38
38
  "dependencies": {
39
39
  "@types/lodash.merge": "^4.6.6",
40
- "@types/ramda": "^0.27.44",
40
+ "@types/ramda": "^0.27.45",
41
41
  "ajv": "^6.12.6",
42
42
  "handlebars": "^4.7.7",
43
43
  "lodash.merge": "^4.6.2",
@@ -45,7 +45,7 @@
45
45
  "ramda": "^0.27.1"
46
46
  },
47
47
  "devDependencies": {
48
- "@integreat/ts-dev-setup": "^2.0.2",
48
+ "@integreat/ts-dev-setup": "^2.1.0",
49
49
  "@types/deep-freeze": "^0.1.2",
50
50
  "@types/sinon": "^9.0.11",
51
51
  "deep-freeze": "0.0.1",