Skip to content

Commit

Permalink
Merge pull request #42 from vizzuhq/csv-parser-type-typo
Browse files Browse the repository at this point in the history
Csv parser type typo
  • Loading branch information
dovicsin authored Mar 27, 2024
2 parents 4b5a27c + 52f6480 commit 61b308f
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 45 deletions.
4 changes: 4 additions & 0 deletions plugins/csv-parser/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## [Unreleased]

## [0.2.3]

- Update ts types names

## [0.2.2]

- Fixed: The empty series list type is dimension
Expand Down
2 changes: 1 addition & 1 deletion plugins/csv-parser/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@vizzu/csv-parser",
"description": "Vizzu plugin for CSV parsing",
"version": "0.2.2",
"version": "0.2.3",
"type": "module",
"exports": {
".": {
Expand Down
36 changes: 18 additions & 18 deletions plugins/csv-parser/src/dataParser.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,37 +5,37 @@ import * as CA from 'vizzu/dist/module/canimctrl.js'
import * as CC from 'vizzu/dist/module/cchart'
import { Plugin, PluginHooks } from 'vizzu/dist/plugins.js'
import { AnimCompleting } from 'vizzu/dist/animcompleting'
export interface optionsTypes {
export interface OptionsTypes {
delimiter?: string
encoding?: BufferEncoding
headers?: boolean
autoheader?: boolean
emptyColumnPrefix?: string
hasHeader?: boolean | null
}
export interface detectedTypes {
export interface DetectedTypes {
delimiter: string
probability: number
headers: string[]
hasHeader: boolean
}
export interface csvTypes {
export interface CSVTypes {
url?: string
content?: string
options?: optionsTypes
options?: OptionsTypes
}
export interface csvTarget {
export interface CSVTarget {
target: {
data: {
csv: csvTypes
csv: CSVTypes
}
}
}
export interface csvDataType extends Data.Filter {
csv: csvTypes
export interface CSVDataType extends Data.Filter {
csv: CSVTypes
}
export interface Target {
data?: Data.Set | csvDataType
data?: Data.Set | CSVDataType
config?: Config.Chart
style?: Styles.Chart | null
}
Expand All @@ -50,15 +50,15 @@ declare module 'vizzu' {
animate(target: AnimTarget, options?: Anim.ControlOptions): AnimCompleting
}
}
export interface dataSeries {
export interface DataSeries {
name: string
values: number[] | string[]
}
export interface dataType {
series: dataSeries[]
export interface DataType {
series: DataSeries[]
}
export interface ConstructorParams {
options?: optionsTypes
options?: OptionsTypes
}
export declare class DataParser implements Plugin {
private _data
Expand All @@ -68,7 +68,7 @@ export declare class DataParser implements Plugin {
private _emptyColumnPrefix
private _probabilityVariable
private _debug
detected: detectedTypes
detected: DetectedTypes
parserOptions: Options
meta: {
name: string
Expand All @@ -77,19 +77,19 @@ export declare class DataParser implements Plugin {
}
constructor(params?: ConstructorParams)
get hasHeader(): boolean | null
get data(): dataType | null
get data(): DataType | null
get delimiter(): string
get detectedDelimiter(): string
get api(): {
hasHeader: boolean
detectedDelimiter: string
delimiter: string
data: dataType
data: DataType
}
get hooks(): PluginHooks
private _setOptions
convertNumbers(data: dataType): dataType
parse(input: string, options?: optionsTypes, convert?: boolean): Promise<dataType | null>
convertNumbers(data: DataType): DataType
parse(input: string, options?: OptionsTypes, convert?: boolean): Promise<DataType | null>
setSource(source: string): Promise<void>
fetchData(url: string): Promise<string>
getDelimiter(data: string): string
Expand Down
44 changes: 22 additions & 22 deletions plugins/csv-parser/src/dataParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import * as CC from 'vizzu/dist/module/cchart'
import { Plugin, PluginHooks, PrepareAnimationContext } from 'vizzu/dist/plugins.js'
import { AnimCompleting } from 'vizzu/dist/animcompleting'

export interface optionsTypes {
export interface OptionsTypes {
delimiter?: string
encoding?: BufferEncoding
headers?: boolean
Expand All @@ -17,32 +17,32 @@ export interface optionsTypes {
hasHeader?: boolean | null
}

export interface detectedTypes {
export interface DetectedTypes {
delimiter: string
probability: number
headers: string[]
hasHeader: boolean
}
export interface csvTypes {
export interface CSVTypes {
url?: string
content?: string
options?: optionsTypes
options?: OptionsTypes
}

export interface csvTarget {
export interface CSVTarget {
target: {
data: {
csv: csvTypes
csv: CSVTypes
}
}
}

export interface csvDataType extends Data.Filter {
csv: csvTypes
export interface CSVDataType extends Data.Filter {
csv: CSVTypes
}

export interface Target {
data?: Data.Set | csvDataType
data?: Data.Set | CSVDataType
config?: Config.Chart
style?: Styles.Chart | null
}
Expand All @@ -58,16 +58,16 @@ declare module 'vizzu' {
animate(target: AnimTarget, options?: Anim.ControlOptions): AnimCompleting
}
}
export interface dataSeries {
export interface DataSeries {
name: string
values: (number | null | string)[]
}
export interface dataType {
series: dataSeries[]
export interface DataType {
series: DataSeries[]
}

export interface ConstructorParams {
options?: optionsTypes
options?: OptionsTypes
}

const LOG_PREFIX = [
Expand All @@ -77,15 +77,15 @@ const LOG_PREFIX = [
]

export class DataParser implements Plugin {
private _data: dataType | null = null
private _data: DataType | null = null
private _headers: string[] | null = null
private _autoheader = true
private _hasHeader: boolean | null = null
private _emptyColumnPrefix = 'Column'
private _probabilityVariable = 0.5
private _debug = false

public detected: detectedTypes = {
public detected: DetectedTypes = {
delimiter: ',',
probability: 1,
headers: [],
Expand All @@ -112,7 +112,7 @@ export class DataParser implements Plugin {
return this._hasHeader === null ? this.detected.hasHeader : this._hasHeader
}

get data(): dataType | null {
get data(): DataType | null {
return this._data
}

Expand Down Expand Up @@ -155,7 +155,7 @@ export class DataParser implements Plugin {

if (!('csv' in target.data) || !target.data.csv) continue

const csvOptions: csvTypes = target.data.csv
const csvOptions: CSVTypes = target.data.csv
if (!('url' in csvOptions) && !('content' in csvOptions)) continue

if ('options' in csvOptions && csvOptions.options) {
Expand Down Expand Up @@ -187,7 +187,7 @@ export class DataParser implements Plugin {
}
}

private _setOptions(options: optionsTypes) {
private _setOptions(options: OptionsTypes) {
if ('delimiter' in options && options.delimiter) {
this.parserOptions.delimiter = options.delimiter
}
Expand Down Expand Up @@ -216,7 +216,7 @@ export class DataParser implements Plugin {
}
}

public convertNumbers(data: dataType): dataType {
public convertNumbers(data: DataType): DataType {
if (!data || !('series' in data) || !data.series) return data

data.series = data.series.map(
Expand All @@ -242,9 +242,9 @@ export class DataParser implements Plugin {

public async parse(
input: string,
options: optionsTypes = {},
options: OptionsTypes = {},
convert = true
): Promise<dataType | null> {
): Promise<DataType | null> {
if (!input) return null

if (options) {
Expand Down Expand Up @@ -309,7 +309,7 @@ export class DataParser implements Plugin {
return this.parserOptions.delimiter?.toString() || this.detected.delimiter
}

private _buildData(records: string[][]): dataType | null {
private _buildData(records: string[][]): DataType | null {
if (records.length === 0) {
return null
}
Expand Down
4 changes: 2 additions & 2 deletions plugins/csv-parser/src/node.d.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { DataParser } from './dataParser'
import { Options } from 'csv-parse/.'
interface dataType {
interface DataType {
series: {
name: string
values: string[] | number[]
}[]
}
export declare class CSVParser extends DataParser {
parse(input: string, options?: Options): Promise<dataType | null>
parse(input: string, options?: Options): Promise<DataType | null>
readCSVFile(fileName: string): string
}
export default CSVParser
4 changes: 2 additions & 2 deletions plugins/csv-parser/src/node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ import * as fs from 'fs'
import { DataParser } from './dataParser'
import { Options } from 'csv-parse/.'

interface dataType {
interface DataType {
series: {
name: string
values: string[] | number[]
}[]
}

export class CSVParser extends DataParser {
public async parse(input: string, options: Options = {}): Promise<dataType | null> {
public async parse(input: string, options: Options = {}): Promise<DataType | null> {
if (!input) return null

if (options) {
Expand Down

0 comments on commit 61b308f

Please sign in to comment.