Socket
Socket
Sign inDemoInstall

evalcsv

Package Overview
Dependencies
17
Maintainers
1
Versions
26
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    evalcsv

Eval Csv is a command line tool for converting csv files to json object.


Version published
Weekly downloads
32
increased by966.67%
Maintainers
1
Install size
1.48 MB
Created
Weekly downloads
 

Readme

Source

EvalCsv

EvalCsv是一个可以把csv文件转换为json文件的命令行工具。
csv里面可以填一个对象:
	p
	{x:0,y:1}
还可以填一个数组:
	arr
	[{x:0,y:1}, {x:2,y:3}]
new一个对象也可以:
	m
	new Map()
支持javascript代码,语法简洁,错误提示全面, 因为这个程序仅仅是把csv里面的元素读取出来eval而已……


Solution

对于csv文件中的每一个元素value, 假定key为标题行对应列的值, evalcsv使用了一个很简单的办法来把csv文件转换为json对象:

		eval("row." + key + " = " + value + ";");
        
有木有感觉到用csv表示对象, 数组等复杂数据原来是这么容易的事情?
用node.js的小伙伴们, 直接require这个json文件开始愉快的工作吧。

想要把csv资源打包的朋友们, 可以使用json2pb把json对象用protobuf打包。

Install

  1. Install node.js

  2. Install with npm

    npm install -g evalcsv

Usage

Usage: evalcsv [options] files
Options:
  -h, --help                   Display this information.
  -v, --version                Print the compiler version.
  -e, --encoding               Set input file encoding, default encoding is 'gbk'.
  -k, --key                    Set the line number of keys, default is 2.
  -s, --start                  Set the starting line number for parsing, default is 3.
  -f, --format                 Set the output format, default is {"rows":%s}

Example

motion.csv
    motion_id,name,privileges,type,category
    motion_id,name,privileges,type,category
    11001,"""跪姿肩部下沉""","['owner', 'admin', 'user', 'guest']","""热身""","""胸"""
    11002,"""直体肩部下沉""","['owner', 'admin', 'user', 'guest']","""热身""","""胸"""

command line
    evalcsv motion.csv
    
motion.json
	{
		"rows": [
			{
				"motion_id": 11001,
				"name": "跪姿肩部下沉",
				"privileges": [
					"owner",
					"admin",
					"user",
					"guest"
				],
				"type": "热身",
				"category": "胸",
			},
			{
				"motion_id": 11002,
				"name": "直体肩部下沉",
				"privileges": [
					"owner",
					"admin",
					"user",
					"guest"
				],
				"type": "热身",
				"category": "胸",
			}
		]
	}

Author

@randyliu

Licence

See the MIT License

Keywords

FAQs

Last updated on 04 Jul 2016

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc