lesca-comma-string
v1.0.1
Published
It can convert data between comma string and array
Downloads
6
Readme
Why use it?
It can convert data between comma-string
and object-in-array
or array
.
What is comma-string
?
It's a data format that can save into single tab of database.
// user data from API
const dataFromAPI = 'James,Hsu,41,male,Audrey,Chen,35,female';
Live Demo
Installation
npm install lesca-comma-string --save
Usage
1. CommaStringToList
import { CommaStringToList } from 'lesca-comma-string';
const dataFromAPI = 'james,41,male,Audrey,36,female';
const keys = ['name', 'age', 'gender'];
const data = CommaStringToList(dataFromAPI, dataFormat); // [{"name":"james","age":"41","gender":"male"},{"name":"Audrey","age":"35","gender":"female"}]
2. ListToCommaString
import { ListToCommaString } from 'lesca-comma-string';
const data = [
{ name: 'james', age: '41', gender: 'male' },
{ name: 'Audrey', age: '35', gender: 'female' },
];
const [commaString, keys] = ListToCommaString(data);
// commaString: 'james,41,male,Audrey,36,female'
// keys = ['name', 'age', 'gender']
3. CommaStringToArray
import { CommaStringToArray } from 'lesca-comma-string';
const dataFromAPI = 'james,audrey,ken,jenny';
const data = CommaStringToArray(dataFromAPI); // ['james', 'audrey', 'ken', 'jenny']
4. ArrayToCommaString
import { ArrayToCommaString } from 'lesca-comma-string';
const data = ['james', 'audrey', 'ken', 'jenny'];
const result = ArrayToCommaString(data); // james,audrey,ken,jenny
Features
- Code Linting (eslint)
- maintain if necessary