1.0.2 • Published 4 years ago

basic-csv-parser v1.0.2

Weekly downloads
13
License
SEE LICENSE IN LI...
Repository
github
Last release
4 years ago

basic-csv-parser

NPM

lightweight (1kb gzip, no dependencies) csv string parser for the browser, validated against an applicable subset of the PapaParse test suite.

Example

check this codesandbox

API v1

/**
 * @return a csv string parser as specified by the given `config` options object
 */
export declare function getCsvParser<T = string[]>(
  config?: Partial<CSV_PARSER_SPEC>
): (input: string) => T[]

export interface CSV_PARSER_SPEC {
  /**
   * when true, the first line is interpreted as a header (list of field names),
   * in which case the parsed entries are objects
   * instead of a list of field values.
   * default: false
   */
  header: boolean
  /**
   * field delimiter character,
   * default: `,`
   */
  delimiter: string
  /**
   * escape character,
   * default: `"`
   */
  escape: string
  /**
   * called for each parsed field,
   * with its index in the parsed record.
   * defaults to a function that unescapes the field string
   */
  postprocess: (field: string, index?: number) => string
}

TypeScript

although this library is written in TypeScript, it may also be imported into plain JavaScript code: code editors will still benefit from the available type definition, e.g. for helpful code completion.

License

Copyright 2019 ZenyWay S.A.S., Stephane M. Catala

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and Limitations under the License.

1.0.2

4 years ago

1.0.1

5 years ago

1.0.0

5 years ago