@0xtorch/csv 0.0.50 → 0.0.52
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/_cjs/parseRowsToActions/allValue.js +8 -0
- package/_cjs/parseRowsToActions/allValue.js.map +1 -1
- package/_cjs/parseRowsToActions/joinValue.js +8 -0
- package/_cjs/parseRowsToActions/joinValue.js.map +1 -1
- package/_cjs/parseRowsToActions/matchValue.js +11 -0
- package/_cjs/parseRowsToActions/matchValue.js.map +1 -0
- package/_cjs/parseRowsToActions/mathValue.js +8 -0
- package/_cjs/parseRowsToActions/mathValue.js.map +1 -1
- package/_cjs/parseRowsToActions/splitValue.js +15 -1
- package/_cjs/parseRowsToActions/splitValue.js.map +1 -1
- package/_cjs/schemas/parser.js +19 -2
- package/_cjs/schemas/parser.js.map +1 -1
- package/_esm/parseRowsToActions/allValue.js +8 -0
- package/_esm/parseRowsToActions/allValue.js.map +1 -1
- package/_esm/parseRowsToActions/joinValue.js +8 -0
- package/_esm/parseRowsToActions/joinValue.js.map +1 -1
- package/_esm/parseRowsToActions/matchValue.js +7 -0
- package/_esm/parseRowsToActions/matchValue.js.map +1 -0
- package/_esm/parseRowsToActions/mathValue.js +8 -0
- package/_esm/parseRowsToActions/mathValue.js.map +1 -1
- package/_esm/parseRowsToActions/splitValue.js +15 -1
- package/_esm/parseRowsToActions/splitValue.js.map +1 -1
- package/_esm/schemas/parser.js +21 -1
- package/_esm/schemas/parser.js.map +1 -1
- package/_types/parseRowsToActions/allValue.d.ts.map +1 -1
- package/_types/parseRowsToActions/joinValue.d.ts.map +1 -1
- package/_types/parseRowsToActions/matchValue.d.ts +9 -0
- package/_types/parseRowsToActions/matchValue.d.ts.map +1 -0
- package/_types/parseRowsToActions/mathValue.d.ts.map +1 -1
- package/_types/parseRowsToActions/splitValue.d.ts.map +1 -1
- package/_types/schemas/format.d.ts +25467 -1843
- package/_types/schemas/format.d.ts.map +1 -1
- package/_types/schemas/parser.d.ts +58243 -4338
- package/_types/schemas/parser.d.ts.map +1 -1
- package/package.json +2 -2
- package/parseRowsToActions/allValue.ts +8 -0
- package/parseRowsToActions/joinValue.ts +8 -0
- package/parseRowsToActions/matchValue.ts +18 -0
- package/parseRowsToActions/mathValue.ts +8 -0
- package/parseRowsToActions/splitValue.ts +17 -1
- package/schemas/parser.ts +23 -1
|
@@ -10,6 +10,7 @@ import type { z } from 'zod'
|
|
|
10
10
|
import type { mathValueSchema } from '../schemas/parser'
|
|
11
11
|
import type { FormattedRow } from '../types'
|
|
12
12
|
import { getCellValue } from './cellValue'
|
|
13
|
+
import { getMatchValue } from './matchValue'
|
|
13
14
|
import { getSliceValue } from './sliceValue'
|
|
14
15
|
import { getSplitValue } from './splitValue'
|
|
15
16
|
|
|
@@ -105,6 +106,13 @@ const getValue = ({
|
|
|
105
106
|
rows,
|
|
106
107
|
})
|
|
107
108
|
}
|
|
109
|
+
case 'match': {
|
|
110
|
+
return getMatchValue({
|
|
111
|
+
schema,
|
|
112
|
+
rows,
|
|
113
|
+
service,
|
|
114
|
+
})
|
|
115
|
+
}
|
|
108
116
|
case 'service': {
|
|
109
117
|
return service
|
|
110
118
|
}
|
|
@@ -2,6 +2,7 @@ import { stringify } from '@0xtorch/core'
|
|
|
2
2
|
import type { z } from 'zod'
|
|
3
3
|
import type { splitValueSchema } from '../schemas/parser'
|
|
4
4
|
import type { FormattedRow } from '../types'
|
|
5
|
+
import { getCellValue } from './cellValue'
|
|
5
6
|
import { getSimpleValue } from './simpleValue'
|
|
6
7
|
|
|
7
8
|
export const getSplitValue = ({
|
|
@@ -14,5 +15,20 @@ export const getSplitValue = ({
|
|
|
14
15
|
service: string
|
|
15
16
|
}) => {
|
|
16
17
|
const value = getSimpleValue({ schema: schema.value, rows, service })
|
|
17
|
-
|
|
18
|
+
const stringifyValue = stringify(value)
|
|
19
|
+
|
|
20
|
+
if (typeof schema.splitter === 'string') {
|
|
21
|
+
return stringifyValue.split(schema.splitter)[schema.index]
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
switch (schema.splitter.type) {
|
|
25
|
+
case 'cell': {
|
|
26
|
+
const splitter = getCellValue({ schema: schema.splitter, rows })
|
|
27
|
+
return stringifyValue.split(stringify(splitter))[schema.index]
|
|
28
|
+
}
|
|
29
|
+
case 'reg-exp': {
|
|
30
|
+
const splitter = new RegExp(schema.splitter.pattern)
|
|
31
|
+
return stringifyValue.split(splitter)[schema.index]
|
|
32
|
+
}
|
|
33
|
+
}
|
|
18
34
|
}
|
package/schemas/parser.ts
CHANGED
|
@@ -22,10 +22,22 @@ export const simpleValueSchema = z.union([
|
|
|
22
22
|
serviceValueSchema,
|
|
23
23
|
])
|
|
24
24
|
|
|
25
|
+
const splitterSchema = z.union([
|
|
26
|
+
// string
|
|
27
|
+
z.string(),
|
|
28
|
+
// reg-exp
|
|
29
|
+
z.object({
|
|
30
|
+
type: z.literal('reg-exp'),
|
|
31
|
+
pattern: z.string(),
|
|
32
|
+
}),
|
|
33
|
+
// cell
|
|
34
|
+
cellValueSchema,
|
|
35
|
+
])
|
|
36
|
+
|
|
25
37
|
export const splitValueSchema = z.object({
|
|
26
38
|
type: z.literal('split'),
|
|
27
39
|
value: simpleValueSchema,
|
|
28
|
-
splitter:
|
|
40
|
+
splitter: splitterSchema,
|
|
29
41
|
index: indexSchema,
|
|
30
42
|
})
|
|
31
43
|
|
|
@@ -36,6 +48,13 @@ export const sliceValueSchema = z.object({
|
|
|
36
48
|
end: z.number().int().optional(),
|
|
37
49
|
})
|
|
38
50
|
|
|
51
|
+
export const matchValueSchema = z.object({
|
|
52
|
+
type: z.literal('match'),
|
|
53
|
+
value: simpleValueSchema,
|
|
54
|
+
pattern: z.string(),
|
|
55
|
+
index: indexSchema,
|
|
56
|
+
})
|
|
57
|
+
|
|
39
58
|
export const mathValueSchema = z.object({
|
|
40
59
|
type: z.literal('math'),
|
|
41
60
|
values: z
|
|
@@ -48,6 +67,7 @@ export const mathValueSchema = z.object({
|
|
|
48
67
|
simpleValueSchema,
|
|
49
68
|
splitValueSchema,
|
|
50
69
|
sliceValueSchema,
|
|
70
|
+
matchValueSchema,
|
|
51
71
|
]),
|
|
52
72
|
)
|
|
53
73
|
.min(3),
|
|
@@ -61,6 +81,7 @@ export const joinValueSchema = z.object({
|
|
|
61
81
|
simpleValueSchema,
|
|
62
82
|
splitValueSchema,
|
|
63
83
|
sliceValueSchema,
|
|
84
|
+
matchValueSchema,
|
|
64
85
|
mathValueSchema,
|
|
65
86
|
]),
|
|
66
87
|
)
|
|
@@ -71,6 +92,7 @@ export const allValueSchema = z.union([
|
|
|
71
92
|
simpleValueSchema,
|
|
72
93
|
splitValueSchema,
|
|
73
94
|
sliceValueSchema,
|
|
95
|
+
matchValueSchema,
|
|
74
96
|
mathValueSchema,
|
|
75
97
|
joinValueSchema,
|
|
76
98
|
])
|