Skip to content

Commit 38e2b25

Browse files
authored
Merge pull request #30 from vizzuhq/csv-parser-types
Csv parser types export
2 parents fb4ead4 + f7499fe commit 38e2b25

File tree

8 files changed

+138
-4
lines changed

8 files changed

+138
-4
lines changed

plugins/csv-parser/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
## [Unreleased]
44

5+
## [0.1.3]
6+
7+
- Add root module type export
8+
59
## [0.1.2]
610

711
### Fixed

plugins/csv-parser/build/build.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import * as esbuild from 'esbuild'
22
import { polyfillNode } from 'esbuild-plugin-polyfill-node'
3+
import { copy } from 'esbuild-plugin-copy'
34

45
await esbuild.build({
56
entryPoints: ['src/index.ts'],
@@ -14,6 +15,14 @@ await esbuild.build({
1415
process: true,
1516
Buffer: true
1617
}
18+
}),
19+
copy({
20+
resolveFrom: 'cwd',
21+
assets: {
22+
from: ['./src/*.d.ts'],
23+
to: ['./dist/types']
24+
},
25+
watch: true
1726
})
1827
],
1928
outfile: 'dist/mjs/index.js'

plugins/csv-parser/package.json

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@vizzu/csv-parser",
33
"description": "Vizzu plugin for CSV parsing",
4-
"version": "0.1.2",
4+
"version": "0.1.3",
55
"type": "module",
66
"exports": {
77
".": {
@@ -19,10 +19,9 @@
1919
"module": "dist/mjs/index.js",
2020
"types": "dist/types/index.d.ts",
2121
"scripts": {
22-
"build": "run clear && node build/build.js && run types",
22+
"build": "run clear && node build/build.js",
2323
"clear": "node build/clear.js",
24-
"test": "vitest",
25-
"types": "npx -p typescript tsc src/*.ts --declaration --allowJs --emitDeclarationOnly --outDir dist/types"
24+
"test": "vitest"
2625
},
2726
"repository": {
2827
"type": "git",
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
/// <reference types="node" />
2+
import { Options } from 'csv-parse/sync'
3+
import { Anim, Data, Config, Styles } from 'vizzu'
4+
import * as CA from 'vizzu/dist/module/canimctrl.js'
5+
import * as CC from 'vizzu/dist/module/cchart'
6+
import { Plugin, PluginHooks } from 'vizzu/dist/plugins.js'
7+
import { AnimCompleting } from 'vizzu/dist/animcompleting'
8+
export interface optionsTypes {
9+
delimiter?: string
10+
encoding?: BufferEncoding
11+
headers?: boolean
12+
autoheader?: boolean
13+
emptyColumnPrefix?: string
14+
hasHeader?: boolean | null
15+
}
16+
export interface detectedTypes {
17+
delimiter: string
18+
probability: number
19+
headers: string[]
20+
hasHeader: boolean
21+
}
22+
export interface csvTypes {
23+
url?: string
24+
content?: string
25+
options?: optionsTypes
26+
}
27+
export interface csvTarget {
28+
target: {
29+
data: {
30+
csv: csvTypes
31+
}
32+
}
33+
}
34+
export interface csvDataType extends Data.Filter {
35+
csv: csvTypes
36+
}
37+
export interface Target {
38+
data?: Data.Set | csvDataType
39+
config?: Config.Chart
40+
style?: Styles.Chart | null
41+
}
42+
export interface Keyframe {
43+
target: Target | CC.Snapshot
44+
options?: Options
45+
}
46+
export type Keyframes = Keyframe[]
47+
export type AnimTarget = Keyframes | CA.CAnimation
48+
declare module 'vizzu' {
49+
interface Vizzu {
50+
animate(target: AnimTarget, options?: Anim.ControlOptions): AnimCompleting
51+
}
52+
}
53+
export interface dataSeries {
54+
name: string
55+
values: number[] | string[]
56+
}
57+
export interface dataType {
58+
series: dataSeries[]
59+
}
60+
export interface ConstructorParams {
61+
options?: optionsTypes
62+
}
63+
export declare class DataParser implements Plugin {
64+
private _data
65+
private _headers
66+
private _autoheader
67+
private _hasHeader
68+
private _emptyColumnPrefix
69+
private _probabilityVariable
70+
private _debug
71+
detected: detectedTypes
72+
parserOptions: Options
73+
meta: {
74+
name: string
75+
version: string
76+
depends: string[]
77+
}
78+
constructor(params?: ConstructorParams)
79+
get hasHeader(): boolean | null
80+
get data(): dataType | null
81+
get delimiter(): string
82+
get detectedDelimiter(): string
83+
get api(): {
84+
hasHeader: boolean
85+
detectedDelimiter: string
86+
delimiter: string
87+
data: dataType
88+
}
89+
get hooks(): PluginHooks
90+
private _setOptions
91+
convertNumbers(data: dataType): dataType
92+
parse(input: string, options?: optionsTypes, convert?: boolean): Promise<dataType | null>
93+
setSource(source: string): Promise<void>
94+
fetchData(url: string): Promise<string>
95+
getDelimiter(data: string): string
96+
private _buildData
97+
private _getHeader
98+
private _log
99+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export declare const delimiterDetect: (data: string) => string
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export declare const headerDetect: (data: string, delimiter?: string) => number

plugins/csv-parser/src/index.d.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { DataParser } from './dataParser'
2+
3+
export * from './dataParser'
4+
export * from './delimiterDetect'
5+
export * from './headerDetect'
6+
7+
export declare class CSVParser extends DataParser {}
8+
export default CSVParser

plugins/csv-parser/src/node.d.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { DataParser } from './dataParser'
2+
import { Options } from 'csv-parse/.'
3+
interface dataType {
4+
series: {
5+
name: string
6+
values: string[] | number[]
7+
}[]
8+
}
9+
export declare class CSVParser extends DataParser {
10+
parse(input: string, options?: Options): Promise<dataType | null>
11+
readCSVFile(fileName: string): string
12+
}
13+
export default CSVParser

0 commit comments

Comments
 (0)