![PyPI Now Supports iOS and Android Wheels for Mobile Python Development](https://cdn.sanity.io/images/cgdhsj6q/production/96416c872705517a6a65ad9646ce3e7caef623a0-1024x1024.webp?w=400&fit=max&auto=format)
Security News
PyPI Now Supports iOS and Android Wheels for Mobile Python Development
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
@tailored-apps/data2csv
Advanced tools
data2csv is a generic data to custom separated value exporter library.
npm install @tailored-apps/data2csv
The map is always an array of map objects.
Name | Type | Mandatory | Description |
---|---|---|---|
index | String | [x] | The index of the data field in the incoming object |
name | String | An optional header name for this field | |
length | Number | A max length check, if the value is too long it will be trimmed | |
mandatory | Boolean | Marks this field as required |
Joins the whole CSV-String
on one variable and return the whole prepared string at once.
Example:
const { createData, presenters } = require('@tailored-apps/data2csv')
...
const dataString = await createData({ data, map, presenterFn: presenters.textPresenter })
Writes line per line of the CSV-String
into the configured file.
filePath = 'test', fileName = 'test.csv', ...options
Name | Type | Default | Description |
---|---|---|---|
filePath | String | 'test' | The path for the generated file |
fileName | String | 'test.csv' | The name of the generated file |
...options | Object | {} | These options will be forwarded to fs.createWriteStream |
Example:
const { createData, presenters } = require('@tailored-apps/data2csv')
...
const dataString = await createData({ data, map, presenterFn: presenters.textPresenter, fileName: 'file.csv', flags: 'a' })
Note:
The flags
option will be forwarded to fs.createWriteStream
Returns the header as CSV-String
and is used in createData
if writeHeaders
is set to true
.
Name | Type | Mandatory | Description |
---|---|---|---|
map | Map | [x] | Array of map objects |
separator | String | [x] | The value with which the tables should be separated |
enclosure | String | [x] | The value with which a set of data should be enclosed with |
endOfLine | String | [x] | The value with which a row should be ended |
Example
const { getHeader } = require(('@tailored-apps/data2csv')
const map = [{
index: 'firstname',
name: 'Firstname'
},{
index: 'lastname',
name: 'Lastname'
}]
const headerString = getHeader({ map, separator: ',', enclosure: '"', endOfLine: '\n' })
Returns:
"Firstname","Lastname",\n
Returns the full CSV-String
of the incoming data list.
Name | Type | Mandatory | Default | Description |
---|---|---|---|---|
data | Array | [x] | Data list, which should be mapped | |
map | Map | [x] | Array of map objects | |
writeHeaders | Boolean | true | If the header information should be added as first line | |
shouldPad | Boolean | false | If the values should be padded to the defined max length, number with '0' and other types with ' ' | |
propertyToLog | Number | 0 | Defines the property that should be logged if an error occurs (Default value is the first element) | |
failedItems | Array | [] | Defines a failedItems array which failed items will be pushed to | |
separator | String | ',' | The value with which the tables should be separated | |
enclosure | String | '"' | The value with which a set of data should be enclosed with | |
endOfLine | String | '\n' | The value with which a row should be ended | |
logger | Object | console | A logger instance passed to the exporter | |
presenterFn | Function | textPresenter | The presenter which outputs the parsed CSV-String | |
...other | Object | {} | Optional presenter function options |
Example:
const { createData } = require('@tailored-apps/data2csv')
const map = [{
index: 'id',
length: 10
}, {
index: 'firstname',
length: 8
}, {
index: 'lastname',
length: 10
}]
const data = [{
id: 'abc-def-gh',
firstname: 'TestToLong',
lastname: 'someName',
middlename: 'somerndmiddlename'
}]
const dataString = await createData({ data, map, writeHeaders: false, separator: '\t', enclosure: '' })
Returns:
abc-def-gh\tTestToLo\tsomeName\t\n
Note:
The value middlename
that is not given in the map will be excluded in the returned string
The value firstname
will be trimmed to the given length of 8
The created data string is sorted by the map indices
Is an alias for createData
which preset the textPresenter
.
Is an alias for createData
which preset the filePresenter
.
FAQs
Tailored data to character separated values.
The npm package @tailored-apps/data2csv receives a total of 2 weekly downloads. As such, @tailored-apps/data2csv popularity was classified as not popular.
We found that @tailored-apps/data2csv demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 3 open source maintainers collaborating on the project.
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.
Security News
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.