@thi.ng/csv 2.2.32 → 2.3.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
@@ -1,6 +1,6 @@
1
1
  # Change Log
2
2
 
3
- - **Last updated**: 2022-12-22T21:47:07Z
3
+ - **Last updated**: 2023-02-05T14:42:21Z
4
4
  - **Generator**: [thi.ng/monopub](https://thi.ng/monopub)
5
5
 
6
6
  All notable changes to this project will be documented in this file.
@@ -9,6 +9,12 @@ See [Conventional Commits](https://conventionalcommits.org/) for commit guidelin
9
9
  **Note:** Unlisted _patch_ versions only involve non-code or otherwise excluded changes
10
10
  and/or version bumps of transitive dependencies.
11
11
 
12
+ ## [2.3.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/csv@2.3.0) (2023-02-05)
13
+
14
+ #### 🚀 Features
15
+
16
+ - add oneOff() cell transform for enum like values ([7c297db](https://github.com/thi-ng/umbrella/commit/7c297db))
17
+
12
18
  ## [2.2.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/csv@2.2.0) (2021-12-02)
13
19
 
14
20
  #### 🚀 Features
package/README.md CHANGED
@@ -136,4 +136,4 @@ If this project contributes to an academic publication, please cite it as:
136
136
 
137
137
  ## License
138
138
 
139
- © 2014 - 2022 Karsten Schmidt // Apache License 2.0
139
+ © 2014 - 2023 Karsten Schmidt // Apache License 2.0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thi.ng/csv",
3
- "version": "2.2.32",
3
+ "version": "2.3.0",
4
4
  "description": "Customizable, transducer-based CSV parser/object mapper and transformer",
5
5
  "type": "module",
6
6
  "module": "./index.js",
@@ -34,18 +34,18 @@
34
34
  "test": "testament test"
35
35
  },
36
36
  "dependencies": {
37
- "@thi.ng/api": "^8.6.2",
38
- "@thi.ng/checks": "^3.3.6",
39
- "@thi.ng/strings": "^3.3.22",
40
- "@thi.ng/transducers": "^8.3.29"
37
+ "@thi.ng/api": "^8.7.0",
38
+ "@thi.ng/checks": "^3.3.8",
39
+ "@thi.ng/strings": "^3.3.24",
40
+ "@thi.ng/transducers": "^8.3.31"
41
41
  },
42
42
  "devDependencies": {
43
- "@microsoft/api-extractor": "^7.33.7",
44
- "@thi.ng/testament": "^0.3.8",
45
- "rimraf": "^3.0.2",
43
+ "@microsoft/api-extractor": "^7.34.2",
44
+ "@thi.ng/testament": "^0.3.10",
45
+ "rimraf": "^4.1.2",
46
46
  "tools": "^0.0.1",
47
- "typedoc": "^0.23.22",
48
- "typescript": "^4.9.4"
47
+ "typedoc": "^0.23.24",
48
+ "typescript": "^4.9.5"
49
49
  },
50
50
  "keywords": [
51
51
  "csv",
@@ -85,5 +85,5 @@
85
85
  "thi.ng": {
86
86
  "year": 2014
87
87
  },
88
- "gitHead": "28bb74c67217a352d673b6efdab234921d4a370e\n"
88
+ "gitHead": "50ba9c87676fac60c46d2bc0e4d2c7711a374a68\n"
89
89
  }
package/transforms.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import type { IObjectOf } from "@thi.ng/api";
1
2
  import type { CellTransform } from "./api.js";
2
3
  /**
3
4
  * Cell parse value transform. Returns uppercased version of given input.
@@ -54,6 +55,15 @@ export declare const date: (defaultVal?: Date) => CellTransform;
54
55
  * @param x -
55
56
  */
56
57
  export declare const url: CellTransform;
58
+ /**
59
+ * Cell parse value transform. Accepts an object of mappings with original cell
60
+ * values as keys which are then mapped to arbitrary new values in an enum like
61
+ * fashion.
62
+ *
63
+ * @param mappings
64
+ * @param defaultVal
65
+ */
66
+ export declare const oneOf: <T>(mappings: IObjectOf<T>, defaultVal: T) => CellTransform;
57
67
  export declare const zeroPad: (digits: number) => (x: any, length?: number | undefined) => string;
58
68
  export declare const formatFloat: (prec?: number) => (x: number) => string;
59
69
  /**
package/transforms.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { padLeft } from "@thi.ng/strings/pad-left";
2
- import { percent as $percent } from "@thi.ng/strings/percent";
3
2
  import { maybeParseFloat, maybeParseInt } from "@thi.ng/strings/parse";
3
+ import { percent as $percent } from "@thi.ng/strings/percent";
4
4
  /**
5
5
  * Cell parse value transform. Returns uppercased version of given input.
6
6
  *
@@ -66,6 +66,15 @@ export const date = (defaultVal) => (x) => {
66
66
  * @param x -
67
67
  */
68
68
  export const url = (x) => new URL(x);
69
+ /**
70
+ * Cell parse value transform. Accepts an object of mappings with original cell
71
+ * values as keys which are then mapped to arbitrary new values in an enum like
72
+ * fashion.
73
+ *
74
+ * @param mappings
75
+ * @param defaultVal
76
+ */
77
+ export const oneOf = (mappings, defaultVal) => (x) => mappings[x] ?? defaultVal;
69
78
  // formatters
70
79
  export const zeroPad = (digits) => padLeft(digits, "0");
71
80
  export const formatFloat = (prec = 2) => (x) => x.toFixed(prec);