@truedat/core 4.48.6 → 4.48.9
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
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@truedat/core",
|
|
3
|
-
"version": "4.48.
|
|
3
|
+
"version": "4.48.9",
|
|
4
4
|
"description": "Truedat Web Core",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"jsnext:main": "src/index.js",
|
|
@@ -112,5 +112,5 @@
|
|
|
112
112
|
"react-dom": ">= 16.8.6 < 17",
|
|
113
113
|
"semantic-ui-react": ">= 0.88.2 < 2.1"
|
|
114
114
|
},
|
|
115
|
-
"gitHead": "
|
|
115
|
+
"gitHead": "82d6ab8fb0b3000bf4b8975670d3e5cf15b14487"
|
|
116
116
|
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import _ from "lodash/fp";
|
|
2
|
+
import { isValue, columnPredicate } from "../columnPredicate";
|
|
3
|
+
|
|
4
|
+
describe("isValue", () => {
|
|
5
|
+
it("returns false for 'empty' values", () => {
|
|
6
|
+
expect(isValue(null)).toBe(false);
|
|
7
|
+
expect(isValue(undefined)).toBe(false);
|
|
8
|
+
expect(isValue({ a: null })).toBe(false);
|
|
9
|
+
expect(isValue([])).toBe(false);
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
it("returns true for 'non-empty' values", () => {
|
|
13
|
+
expect(isValue("a")).toBe(true);
|
|
14
|
+
expect(isValue(1)).toBe(true);
|
|
15
|
+
expect(isValue(false)).toBe(true);
|
|
16
|
+
expect(isValue([1])).toBe(true);
|
|
17
|
+
expect(isValue({ a: 1 })).toBe(true);
|
|
18
|
+
});
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
describe("columnPredicate", () => {
|
|
22
|
+
it("returns a function to check whether a column value is 'empty'", () => {
|
|
23
|
+
const pred = columnPredicate({ name: "foo" });
|
|
24
|
+
expect(pred({ foo: 1 })).toBe(true);
|
|
25
|
+
expect(pred({ foo: false })).toBe(true);
|
|
26
|
+
expect(pred({ bar: 1 })).toBe(false);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it("uses fieldSelector as a function", () => {
|
|
30
|
+
const pred = columnPredicate({ fieldSelector: _.pick(["foo"]) });
|
|
31
|
+
expect(pred({ foo: 1 })).toBe(true);
|
|
32
|
+
expect(pred({ foo: null })).toBe(false);
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it("uses fieldSelector as a path", () => {
|
|
36
|
+
const pred = columnPredicate({ fieldSelector: "foo.bar" });
|
|
37
|
+
expect(pred({ foo: { bar: 1 } })).toBe(true);
|
|
38
|
+
expect(pred({ foo: { bar: null } })).toBe(false);
|
|
39
|
+
});
|
|
40
|
+
});
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import _ from "lodash/fp";
|
|
2
|
+
|
|
3
|
+
const notEmpty = _.negate(_.isEmpty);
|
|
4
|
+
|
|
5
|
+
export const isValue = _.cond([
|
|
6
|
+
[_.isBoolean, _.stubTrue],
|
|
7
|
+
[_.isNumber, _.stubTrue],
|
|
8
|
+
[
|
|
9
|
+
_.isObject,
|
|
10
|
+
_.flow(_.values, _.some(_.overSome([_.isBoolean, _.isNumber, notEmpty]))),
|
|
11
|
+
],
|
|
12
|
+
[_.stubTrue, notEmpty],
|
|
13
|
+
]);
|
|
14
|
+
|
|
15
|
+
export const columnPredicate = ({ name, fieldSelector }) =>
|
|
16
|
+
_.flow(
|
|
17
|
+
_.isFunction(fieldSelector)
|
|
18
|
+
? fieldSelector
|
|
19
|
+
: _.path(_.defaultTo(name)(fieldSelector)),
|
|
20
|
+
isValue
|
|
21
|
+
);
|
|
22
|
+
|
|
23
|
+
export default columnPredicate;
|
package/src/services/index.js
CHANGED
|
@@ -7,12 +7,14 @@ import * as sort from "./sort";
|
|
|
7
7
|
import * as format from "./format";
|
|
8
8
|
import columnDecorator from "./columnDecorator";
|
|
9
9
|
import columnDecoratorComponent from "./columnDecoratorComponent";
|
|
10
|
+
import columnPredicate from "./columnPredicate";
|
|
10
11
|
|
|
11
12
|
export {
|
|
12
13
|
api,
|
|
13
14
|
arrays,
|
|
14
15
|
columnDecorator,
|
|
15
16
|
columnDecoratorComponent,
|
|
17
|
+
columnPredicate,
|
|
16
18
|
fieldType,
|
|
17
19
|
filters,
|
|
18
20
|
format,
|