13 Star 0 Fork 13

OpenHarmony-TPC / node-csv

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

node-csv

简介

该项目使用node-csv解析csv文件,生成csv文件。

功能说明

1.csv-generate, CSV 字符串和 Javascript 对象的灵活生成器。

2.csv-parse,将 CSV 文本转换为数组或对象的解析器。

3.csv-stringify,将记录转换为 CSV 文本的字符串化器。

4.stream-transform,简单对象转换框架,扩展原生 Node.js转换流 API。

下载安装

1.安装命令如下:

cd entry
ohpm install csv

使用说明

csv-stringify

import {stringify} from 'csv-stringify/browser/esm'
let content = "1 2 3 4 5"
stringify(content, (err, output) => {
    //output ->csv格式的字符串
    let filePath = parentPath + '/temp.csv';
    console.log(TAG + "stringify filePath::" + filePath)
    let csvStr = '\ufeff' + output
    let openSync = fileio.openSync(filePath, 0o102, 0o666);
    try {
        //使用os文件读写功能生成csv文件
        let bytesWritten = fileio.writeSync(openSync, csvStr);
        this.text1 = "生成值: " + JSON.stringify(csvStr);
    } catch (err) {
        console.log(TAG + 'stringify write error :' + err)
    }
});

csv-parse

import {parse} from 'csv-parse/browser/esm'
parseToCsvString(filePath) {
    fileio.readText(filePath)
        .then((input) => {
            parse(input, {
                relax_column_count: true,
                skip_empty_lines: true
            }, (err, records) => {
                this.text2 = "解析值: " + JSON.stringify(records);
            });
        }).catch((e) => {
        console.log(TAG + 'parse read error :' + e)
    })
}

csv-generate

import {generate} from 'csv-generate/browser/esm'
generateCsArray(){
    generate({
        seed: 1,
        objectMode: true,
        columns: 2,
        length: 2
    }, (err, records) => {
        this.text3 = "生成CSV数据集: " + JSON.stringify(records);
    });
}

csv-transform

import {transform} from 'csv-generate/browser/esm'
transformArry() {
    transform([['1', '2', '3', '4'], ['a', 'b', 'c', 'd']], (record) => {
        record.push(record.shift());
        return record;
    }, (err, output) => {
        this.text4 = "转变CSV数据集: " + JSON.stringify(output);
    });
}

注意: 由于OpenHarmony当前不支持emoji表情显示,所以当前并不支持emoji表情存储到csv中。

项目目录

/node-csv #三方库源代码
|---- entry  #框架代码
|   |---- src   
|       |---- main  
|           |---- ets  
|               |---- MainAbility  # demo代码
|                   |---- pages
|                   |---- test                    

约束与限制

在下述版本验证通过:

DevEco Studio 版本: 4.1 Canary(4.1.3.317),OpenHarmony SDK:API11 (4.1.0.36)

开源协议

本项目基于 MIT License ,请自由地享受和参与开源。

参与贡献

使用过程中发现任何问题都可以提 Issue 给我们,当然,我们也非常欢迎你给我们发 PR

The MIT License (MIT) Copyright (c) 2010 Adaltas Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

暂无描述 展开 收起
TypeScript 等 3 种语言
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
1
https://gitee.com/openharmony-tpc/node-csv.git
git@gitee.com:openharmony-tpc/node-csv.git
openharmony-tpc
node-csv
node-csv
master

搜索帮助