UNPKG

@coolgk/utils

Version:

javascript, typescript utility and wrapper functions and classes: array, string, base64, ampq, bcrypt, cache, captcha, csv, email, jwt, number, pdf, tmp, token, unit conversion, url params, session, form data, google sign in, facebook sign in

55 lines (53 loc) 1.77 kB
/*! * @package @coolgk/utils * @version 3.1.4 * @link https://github.com/coolgk/node-utils * @license MIT * @author Daniel Gong <daniel.k.gong@gmail.com> * * Copyright (c) 2017 Daniel Gong <daniel.k.gong@gmail.com>. All rights reserved. * Licensed under the MIT License. */ /// <reference types="csv-stringify" /> /*! * Copyright (c) 2017 Daniel Gong <daniel.k.gong@gmail.com>. All rights reserved. * Licensed under the MIT License. */ import csvParse = require('csv-parse'); import csvStringify = require('csv-stringify'); import { generateFile, ITmpConfig } from '@coolgk/tmp'; import { Cursor } from 'mongodb'; export interface ICsvConfig { readonly generateFile?: typeof generateFile; readonly csvStringify?: typeof csvStringify; readonly csvParse?: typeof csvParse; readonly tmpConfig?: ITmpConfig; } export interface ICsvReadConfig { columns?: string[]; limit?: number; delimiter?: string; } export interface ICsvWriteConfig { columns?: string[]; delimiter?: string; filepath?: string; formatter?: (data: { [propName: string]: any; } | any[]) => string[]; } export interface IReadFileResponse { forEach: (callback: (row: any, index: number) => void, endCallback: (rowCount: number) => void) => void; } export declare class Csv { private _csvParse; private _csvStringify; private _generateFile; private _tmpConfig; constructor(options?: ICsvConfig); parse(value: string, options?: ICsvReadConfig): Promise<any[]>; readFile(file: string, options?: ICsvReadConfig): IReadFileResponse; createFile(data: any[] | Cursor, options?: ICsvWriteConfig): Promise<string>; private _writeCsvStream(writableStream, rowData, options, isHeader?); } export default Csv;