Compare commits
23 Commits
Author | SHA1 | Date | |
---|---|---|---|
29133238ef | |||
dbd0a23e33 | |||
5dd1a868c6 | |||
79a75f66cf | |||
3a8ccb72ef | |||
c23618dc6f | |||
5de0c7b8c5 | |||
a9ee39f92b | |||
ddfa5bfabc | |||
e85751a90d | |||
e6100e5bfc | |||
85ed6e8172 | |||
d7c1677c9d | |||
c4194bf037 | |||
fd0abaeb47 | |||
ab1c84f41f | |||
6f575e8516 | |||
d11f237221 | |||
16826ed337 | |||
c49b518b8a | |||
5f49532fc2 | |||
e7f06a7f44 | |||
491477da82 |
4
.gitignore
vendored
4
.gitignore
vendored
@ -15,8 +15,6 @@ node_modules/
|
||||
|
||||
# builds
|
||||
dist/
|
||||
dist_web/
|
||||
dist_serve/
|
||||
dist_ts_web/
|
||||
dist_*/
|
||||
|
||||
# custom
|
111
.gitlab-ci.yml
111
.gitlab-ci.yml
@ -3,75 +3,82 @@ image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||
|
||||
cache:
|
||||
paths:
|
||||
- .npmci_cache/
|
||||
key: "$CI_BUILD_STAGE"
|
||||
- .npmci_cache/
|
||||
key: '$CI_BUILD_STAGE'
|
||||
|
||||
stages:
|
||||
- security
|
||||
- test
|
||||
- release
|
||||
- metadata
|
||||
- security
|
||||
- test
|
||||
- release
|
||||
- metadata
|
||||
|
||||
before_script:
|
||||
- npm install -g @shipzone/npmci
|
||||
|
||||
# ====================
|
||||
# security stage
|
||||
# ====================
|
||||
mirror:
|
||||
stage: security
|
||||
script:
|
||||
- npmci git mirror
|
||||
tags:
|
||||
- docker
|
||||
- notpriv
|
||||
|
||||
snyk:
|
||||
auditProductionDependencies:
|
||||
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||
stage: security
|
||||
script:
|
||||
- npmci npm prepare
|
||||
- npmci command npm install -g snyk
|
||||
- npmci command npm install --ignore-scripts
|
||||
- npmci command snyk test
|
||||
- npmci command npm install --production --ignore-scripts
|
||||
- npmci command npm config set registry https://registry.npmjs.org
|
||||
- npmci command npm audit --audit-level=high --only=prod --production
|
||||
tags:
|
||||
- docker
|
||||
- notpriv
|
||||
- docker
|
||||
allow_failure: true
|
||||
|
||||
auditDevDependencies:
|
||||
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||
stage: security
|
||||
script:
|
||||
- npmci npm prepare
|
||||
- npmci command npm install --ignore-scripts
|
||||
- npmci command npm config set registry https://registry.npmjs.org
|
||||
- npmci command npm audit --audit-level=high --only=dev
|
||||
tags:
|
||||
- docker
|
||||
allow_failure: true
|
||||
|
||||
# ====================
|
||||
# test stage
|
||||
# ====================
|
||||
|
||||
testLTS:
|
||||
testStable:
|
||||
stage: test
|
||||
script:
|
||||
- npmci npm prepare
|
||||
- npmci node install lts
|
||||
- npmci npm install
|
||||
- npmci npm test
|
||||
- npmci npm prepare
|
||||
- npmci node install stable
|
||||
- npmci npm install
|
||||
- npmci npm test
|
||||
coverage: /\d+.?\d+?\%\s*coverage/
|
||||
tags:
|
||||
- docker
|
||||
- notpriv
|
||||
- docker
|
||||
|
||||
testBuild:
|
||||
stage: test
|
||||
script:
|
||||
- npmci npm prepare
|
||||
- npmci node install lts
|
||||
- npmci npm install
|
||||
- npmci command npm run build
|
||||
- npmci npm prepare
|
||||
- npmci node install stable
|
||||
- npmci npm install
|
||||
- npmci command npm run build
|
||||
coverage: /\d+.?\d+?\%\s*coverage/
|
||||
tags:
|
||||
- docker
|
||||
- notpriv
|
||||
- docker
|
||||
|
||||
release:
|
||||
stage: release
|
||||
script:
|
||||
- npmci node install lts
|
||||
- npmci npm publish
|
||||
- npmci node install stable
|
||||
- npmci npm publish
|
||||
only:
|
||||
- tags
|
||||
- tags
|
||||
tags:
|
||||
- docker
|
||||
- notpriv
|
||||
- lossless
|
||||
- docker
|
||||
- notpriv
|
||||
|
||||
# ====================
|
||||
# metadata stage
|
||||
@ -79,33 +86,37 @@ release:
|
||||
codequality:
|
||||
stage: metadata
|
||||
allow_failure: true
|
||||
only:
|
||||
- tags
|
||||
script:
|
||||
- npmci command npm install -g tslint typescript
|
||||
- npmci command npm install -g typescript
|
||||
- npmci npm prepare
|
||||
- npmci npm install
|
||||
- npmci command "tslint -c tslint.json ./ts/**/*.ts"
|
||||
tags:
|
||||
- docker
|
||||
- priv
|
||||
- lossless
|
||||
- docker
|
||||
- priv
|
||||
|
||||
trigger:
|
||||
stage: metadata
|
||||
script:
|
||||
- npmci trigger
|
||||
- npmci trigger
|
||||
only:
|
||||
- tags
|
||||
- tags
|
||||
tags:
|
||||
- docker
|
||||
- notpriv
|
||||
- lossless
|
||||
- docker
|
||||
- notpriv
|
||||
|
||||
pages:
|
||||
image: hosttoday/ht-docker-node:npmci
|
||||
stage: metadata
|
||||
script:
|
||||
- npmci command npm install -g @gitzone/tsdoc
|
||||
- npmci node install stable
|
||||
- npmci npm prepare
|
||||
- npmci npm install
|
||||
- npmci command tsdoc
|
||||
- npmci command npm run buildDocs
|
||||
tags:
|
||||
- lossless
|
||||
- docker
|
||||
- notpriv
|
||||
only:
|
||||
@ -113,5 +124,5 @@ pages:
|
||||
artifacts:
|
||||
expire_in: 1 week
|
||||
paths:
|
||||
- public
|
||||
- public
|
||||
allow_failure: true
|
||||
|
4
.snyk
4
.snyk
@ -1,4 +0,0 @@
|
||||
# Snyk (https://snyk.io) policy file, patches or ignores known vulnerabilities.
|
||||
version: v1.12.0
|
||||
ignore: {}
|
||||
patch: {}
|
11
.vscode/launch.json
vendored
Normal file
11
.vscode/launch.json
vendored
Normal file
@ -0,0 +1,11 @@
|
||||
{
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"command": "npm test",
|
||||
"name": "Run npm test",
|
||||
"request": "launch",
|
||||
"type": "node-terminal"
|
||||
}
|
||||
]
|
||||
}
|
26
.vscode/settings.json
vendored
Normal file
26
.vscode/settings.json
vendored
Normal file
@ -0,0 +1,26 @@
|
||||
{
|
||||
"json.schemas": [
|
||||
{
|
||||
"fileMatch": ["/npmextra.json"],
|
||||
"schema": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"npmci": {
|
||||
"type": "object",
|
||||
"description": "settings for npmci"
|
||||
},
|
||||
"gitzone": {
|
||||
"type": "object",
|
||||
"description": "settings for gitzone",
|
||||
"properties": {
|
||||
"projectType": {
|
||||
"type": "string",
|
||||
"enum": ["website", "element", "service", "npm", "wcc"]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
@ -4,13 +4,25 @@
|
||||
"npmAccessLevel": "public"
|
||||
},
|
||||
"gitzone": {
|
||||
"projectType": "npm",
|
||||
"module": {
|
||||
"githost": "gitlab.com",
|
||||
"gitscope": "pushrocks",
|
||||
"githost": "code.foss.global",
|
||||
"gitscope": "push.rocks",
|
||||
"gitrepo": "smartcsv",
|
||||
"shortDescription": "handle csv data | gitzone standard compliant",
|
||||
"npmPackagename": "@pushrocks/smartcsv",
|
||||
"license": "MIT"
|
||||
"description": "A module for handling CSV data compliant with Gitzone standard.",
|
||||
"npmPackagename": "@push.rocks/smartcsv",
|
||||
"license": "MIT",
|
||||
"keywords": [
|
||||
"CSV",
|
||||
"data parsing",
|
||||
"data conversion",
|
||||
"TypeScript",
|
||||
"CSV manipulation",
|
||||
"CSV to JSON"
|
||||
]
|
||||
}
|
||||
},
|
||||
"tsdoc": {
|
||||
"legal": "\n## License and Legal Information\n\nThis repository contains open-source code that is licensed under the MIT License. A copy of the MIT License can be found in the [license](license) file within this repository. \n\n**Please note:** The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.\n\n### Trademarks\n\nThis project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH and are not included within the scope of the MIT license granted herein. Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines, and any usage must be approved in writing by Task Venture Capital GmbH.\n\n### Company Information\n\nTask Venture Capital GmbH \nRegistered at District court Bremen HRB 35230 HB, Germany\n\nFor any legal inquiries or if you require further information, please contact us via email at hello@task.vc.\n\nBy using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.\n"
|
||||
}
|
||||
}
|
1588
package-lock.json
generated
1588
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
63
package.json
63
package.json
@ -1,37 +1,56 @@
|
||||
{
|
||||
"name": "@pushrocks/smartcsv",
|
||||
"version": "1.0.18",
|
||||
"name": "@push.rocks/smartcsv",
|
||||
"version": "2.0.2",
|
||||
"private": false,
|
||||
"description": "handle csv data | gitzone standard compliant",
|
||||
"main": "dist/index.js",
|
||||
"typings": "dist/index.d.ts",
|
||||
"description": "A module for handling CSV data compliant with Gitzone standard.",
|
||||
"main": "dist_ts/index.js",
|
||||
"typings": "dist_ts/index.d.ts",
|
||||
"type": "module",
|
||||
"author": "Lossless GmbH",
|
||||
"license": "MIT",
|
||||
"scripts": {
|
||||
"test": "(tstest test/)",
|
||||
"build": "(tsbuild)",
|
||||
"format": "(gitzone format)"
|
||||
"build": "(tsbuild --allowimplicitany)",
|
||||
"buildDocs": "tsdoc"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@gitzone/tsbuild": "^2.1.17",
|
||||
"@gitzone/tsrun": "^1.2.8",
|
||||
"@gitzone/tstest": "^1.0.28",
|
||||
"@pushrocks/smartfile": "^7.0.6",
|
||||
"@pushrocks/tapbundle": "^3.0.13",
|
||||
"@types/node": "^12.7.12"
|
||||
"@gitzone/tsbuild": "^2.1.65",
|
||||
"@gitzone/tsrun": "^1.2.37",
|
||||
"@gitzone/tstest": "^1.0.73",
|
||||
"@pushrocks/smartfile": "^10.0.4",
|
||||
"@pushrocks/tapbundle": "^5.0.4",
|
||||
"@types/node": "^18.6.4"
|
||||
},
|
||||
"dependencies": {
|
||||
"@pushrocks/smartpromise": "^3.0.6",
|
||||
"@pushrocks/smartstring": "^3.0.14"
|
||||
"@pushrocks/smartpromise": "^3.1.7",
|
||||
"@pushrocks/smartstring": "^4.0.2"
|
||||
},
|
||||
"files": [
|
||||
"ts/*",
|
||||
"ts_web/*",
|
||||
"dist/*",
|
||||
"dist_web/*",
|
||||
"assets/*",
|
||||
"ts/**/*",
|
||||
"ts_web/**/*",
|
||||
"dist/**/*",
|
||||
"dist_*/**/*",
|
||||
"dist_ts/**/*",
|
||||
"dist_ts_web/**/*",
|
||||
"assets/**/*",
|
||||
"cli.js",
|
||||
"npmextra.json",
|
||||
"readme.md"
|
||||
]
|
||||
}
|
||||
],
|
||||
"browserslist": [
|
||||
"last 1 chrome versions"
|
||||
],
|
||||
"keywords": [
|
||||
"CSV",
|
||||
"data parsing",
|
||||
"data conversion",
|
||||
"TypeScript",
|
||||
"CSV manipulation",
|
||||
"CSV to JSON"
|
||||
],
|
||||
"homepage": "https://code.foss.global/push.rocks/smartcsv",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://code.foss.global/push.rocks/smartcsv.git"
|
||||
}
|
||||
}
|
4341
pnpm-lock.yaml
generated
Normal file
4341
pnpm-lock.yaml
generated
Normal file
File diff suppressed because it is too large
Load Diff
1
readme.hints.md
Normal file
1
readme.hints.md
Normal file
@ -0,0 +1 @@
|
||||
|
128
readme.md
128
readme.md
@ -1,26 +1,118 @@
|
||||
# @pushrocks/smartcsv
|
||||
# @push.rocks/smartcsv
|
||||
handle csv data | gitzone standard compliant
|
||||
|
||||
## Availabililty and Links
|
||||
* [npmjs.org (npm package)](https://www.npmjs.com/package/@pushrocks/smartcsv)
|
||||
* [gitlab.com (source)](https://gitlab.com/pushrocks/smartcsv)
|
||||
* [github.com (source mirror)](https://github.com/pushrocks/smartcsv)
|
||||
* [docs (typedoc)](https://pushrocks.gitlab.io/smartcsv/)
|
||||
## Install
|
||||
|
||||
## Status for master
|
||||
[](https://gitlab.com/pushrocks/smartcsv/commits/master)
|
||||
[](https://gitlab.com/pushrocks/smartcsv/commits/master)
|
||||
[](https://www.npmjs.com/package/@pushrocks/smartcsv)
|
||||
[](https://snyk.io/test/npm/@pushrocks/smartcsv)
|
||||
[](https://nodejs.org/dist/latest-v10.x/docs/api/)
|
||||
[](https://nodejs.org/dist/latest-v10.x/docs/api/)
|
||||
[](https://prettier.io/)
|
||||
To install `@push.rocks/smartcsv`, use the following command with npm:
|
||||
|
||||
```sh
|
||||
npm install @push.rocks/smartcsv --save
|
||||
```
|
||||
|
||||
Or, if you prefer using Yarn:
|
||||
|
||||
```sh
|
||||
yarn add @push.rocks/smartcsv
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
For further information read the linked docs at the top of this readme.
|
||||
`@push.rocks/smartcsv` is a powerful library designed for handling CSV data efficiently and in a developer-friendly manner. This document will guide you through various use cases and demonstrate the flexibility and capabilities of `@push.rocks/smartcsv`.
|
||||
|
||||
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh)
|
||||
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy.html)
|
||||
### Importing the Module
|
||||
|
||||
[](https://maintainedby.lossless.com)
|
||||
First, import `Csv` from the `@push.rocks/smartcsv` package into your TypeScript file:
|
||||
|
||||
```typescript
|
||||
import { Csv } from '@push.rocks/smartcsv';
|
||||
```
|
||||
|
||||
### Creating a CSV Instance from a String
|
||||
|
||||
You can create a `Csv` instance directly from a string. This is particularly useful when you have CSV data as a string from a file or an API response:
|
||||
|
||||
```typescript
|
||||
const csvString = `Name, Age, Occupation\nJohn Doe, 28, Software Developer\nJane Smith, 32, Data Scientist`;
|
||||
|
||||
const csvOptions = {
|
||||
headers: true, // indicates the first row contains headers
|
||||
unquote: true, // unquote values if necessary
|
||||
trimSpace: true, // trim spaces around values
|
||||
removeBomMarkers: true // remove BOM markers if present
|
||||
};
|
||||
|
||||
const csvInstance = await Csv.createCsvFromString(csvString, csvOptions);
|
||||
```
|
||||
|
||||
### Exporting CSV Data as JSON
|
||||
|
||||
Once you have a `Csv` instance, you can convert the CSV data into JSON objects for easier manipulation and access:
|
||||
|
||||
```typescript
|
||||
const jsonData = await csvInstance.exportAsObject();
|
||||
console.log(jsonData);
|
||||
```
|
||||
|
||||
This will output:
|
||||
|
||||
```json
|
||||
[
|
||||
{ "Name": "John Doe", "Age": "28", "Occupation": "Software Developer" },
|
||||
{ "Name": "Jane Smith", "Age": "32", "Occupation": "Data Scientist" }
|
||||
]
|
||||
```
|
||||
|
||||
### Creating a CSV String from an Array of Objects
|
||||
|
||||
If you have an array of objects and wish to convert it into a CSV string, `@push.rocks/smartcsv` offers a straightforward approach:
|
||||
|
||||
```typescript
|
||||
const arrayOfObjects = [
|
||||
{ Name: "John Doe", Age: 28, Occupation: "Software Developer" },
|
||||
{ Name: "Jane Smith", Age: 32, Occupation: "Data Scientist" }
|
||||
];
|
||||
|
||||
const csvString = await Csv.createCsvStringFromArray(arrayOfObjects);
|
||||
console.log(csvString);
|
||||
```
|
||||
|
||||
This will generate a CSV string that represents the array of objects provided.
|
||||
|
||||
### Advanced Usage
|
||||
|
||||
#### Custom Separator Detection
|
||||
|
||||
By default, `@push.rocks/smartcsv` intelligently detects the separator used in the input CSV data (either a comma `,` or a semicolon `;`). You can rely on this automatic detection or specify preferred options for finer control over how your CSV data is handled.
|
||||
|
||||
#### Handling Quotes and BOM Markers
|
||||
|
||||
The library is capable of processing CSV files that include quoted fields, optionally removing quotes where necessary. Similarly, it can handle Byte Order Mark (BOM) markers at the start of UTF-8 encoded files, ensuring that the text is interpreted correctly.
|
||||
|
||||
#### Trimming Spaces
|
||||
|
||||
For data cleanliness, `@push.rocks/smartcsv` can trim leading and trailing spaces from values in the CSV, ensuring that the resulting data is neat and uniform.
|
||||
|
||||
### Conclusion
|
||||
|
||||
`@push.rocks/smartcsv` offers a comprehensive set of features for working with CSV data in TypeScript, providing flexibility, ease of use, and powerful data manipulation capabilities. Whether you're importing CSV data from a file, converting JSON to CSV, or manipulating CSV strings directly in your application, `@push.rocks/smartcsv` has you covered.
|
||||
|
||||
For detailed API documentation, please refer to the [official documentation](https://pushrocks.gitlab.io/smartcsv/).
|
||||
|
||||
## License and Legal Information
|
||||
|
||||
This repository contains open-source code that is licensed under the MIT License. A copy of the MIT License can be found in the [license](license) file within this repository.
|
||||
|
||||
**Please note:** The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.
|
||||
|
||||
### Trademarks
|
||||
|
||||
This project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH and are not included within the scope of the MIT license granted herein. Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines, and any usage must be approved in writing by Task Venture Capital GmbH.
|
||||
|
||||
### Company Information
|
||||
|
||||
Task Venture Capital GmbH
|
||||
Registered at District court Bremen HRB 35230 HB, Germany
|
||||
|
||||
For any legal inquiries or if you require further information, please contact us via email at hello@task.vc.
|
||||
|
||||
By using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.
|
||||
|
@ -1,14 +1,12 @@
|
||||
// tslint:disable-next-line:no-implicit-dependencies
|
||||
import { expect, tap } from '@pushrocks/tapbundle';
|
||||
import * as smartcsv from '../ts/index';
|
||||
import * as smartcsv from '../ts/index.js';
|
||||
|
||||
// tslint:disable-next-line:no-implicit-dependencies
|
||||
import * as smartfile from '@pushrocks/smartfile';
|
||||
|
||||
let fileString: string;
|
||||
let testCsv: smartcsv.Csv;
|
||||
|
||||
tap.test('should read a file', async tools => {
|
||||
tap.test('should read a file', async (tools) => {
|
||||
fileString = smartfile.fs.toStringSync('./test/sample.csv');
|
||||
});
|
||||
|
||||
@ -21,7 +19,7 @@ tap.test('should create a valid csv', async () => {
|
||||
tap.test('should create a valid csv string', async () => {
|
||||
const createdCsvString = await smartcsv.Csv.createCsvStringFromArray([
|
||||
{ wow: 'hi', wow2: 'there' },
|
||||
{ wow: 'really', wow3: 'yes' }
|
||||
{ wow: 'really', wow3: 'yes' },
|
||||
]);
|
||||
console.log(createdCsvString);
|
||||
});
|
||||
|
8
ts/00_commitinfo_data.ts
Normal file
8
ts/00_commitinfo_data.ts
Normal file
@ -0,0 +1,8 @@
|
||||
/**
|
||||
* autocreated commitinfo by @pushrocks/commitinfo
|
||||
*/
|
||||
export const commitinfo = {
|
||||
name: '@pushrocks/smartcsv',
|
||||
version: '2.0.2',
|
||||
description: 'handle csv data | gitzone standard compliant'
|
||||
}
|
45
ts/index.ts
45
ts/index.ts
@ -1,8 +1,10 @@
|
||||
import * as plugins from './smartcsv.plugins';
|
||||
import * as plugins from './smartcsv.plugins.js';
|
||||
|
||||
export interface ICsvConstructorOptions {
|
||||
headers: boolean;
|
||||
unquote: boolean;
|
||||
unquote?: boolean;
|
||||
trimSpace?: boolean;
|
||||
removeBomMarkers?: boolean;
|
||||
}
|
||||
|
||||
export class Csv {
|
||||
@ -55,23 +57,33 @@ export class Csv {
|
||||
public keyFrame: string = null;
|
||||
public data: any[];
|
||||
|
||||
private base64RecognitionPrefix = '####12345####';
|
||||
|
||||
public options: ICsvConstructorOptions = {
|
||||
headers: true,
|
||||
unquote: true
|
||||
unquote: true,
|
||||
trimSpace: true,
|
||||
removeBomMarkers: true,
|
||||
};
|
||||
|
||||
constructor(csvStringArg: string, optionsArg: ICsvConstructorOptions) {
|
||||
this.options = {
|
||||
...this.options,
|
||||
...optionsArg
|
||||
...optionsArg,
|
||||
};
|
||||
|
||||
let csvStringToParse = csvStringArg;
|
||||
if (this.options.removeBomMarkers) {
|
||||
csvStringToParse = csvStringToParse.replace(/^\uFEFF/, '');
|
||||
}
|
||||
|
||||
// Quotes allow separators to be contained in quoted strings.
|
||||
// To preserve them, when unquoting, we convert everything in between to base64 here
|
||||
if (this.options.unquote) {
|
||||
csvStringToParse = csvStringToParse.replace(
|
||||
/"(.*?)"/gi,
|
||||
(match, p1, offset, originalString) => {
|
||||
return plugins.smartstring.base64.encode(match);
|
||||
return this.base64RecognitionPrefix + plugins.smartstring.base64.encode(match);
|
||||
}
|
||||
);
|
||||
}
|
||||
@ -137,8 +149,9 @@ export class Csv {
|
||||
this.headers = headerRow.split(this.keyFrame);
|
||||
if (this.options.unquote) {
|
||||
const unquotedHeaders: string[] = [];
|
||||
for (const header of this.headers) {
|
||||
if (plugins.smartstring.type.isBase64(header)) {
|
||||
for (let header of this.headers) {
|
||||
if (header.startsWith(this.base64RecognitionPrefix)) {
|
||||
header = header.replace(this.base64RecognitionPrefix, '');
|
||||
unquotedHeaders.push(plugins.smartstring.base64.decode(header).replace(/['"]+/g, ''));
|
||||
} else {
|
||||
unquotedHeaders.push(header);
|
||||
@ -146,6 +159,13 @@ export class Csv {
|
||||
}
|
||||
this.headers = unquotedHeaders;
|
||||
}
|
||||
if (this.options.trimSpace) {
|
||||
const trimmedHeaders = [];
|
||||
for (const header of this.headers) {
|
||||
trimmedHeaders.push(header.trim());
|
||||
}
|
||||
this.headers = trimmedHeaders;
|
||||
}
|
||||
}
|
||||
return this.headers;
|
||||
}
|
||||
@ -155,8 +175,15 @@ export class Csv {
|
||||
let resultJson: any = {};
|
||||
for (let i = 0; i < neededIterations; i++) {
|
||||
let value = dataArray[i];
|
||||
if (this.options.unquote && plugins.smartstring.type.isBase64(value)) {
|
||||
value = plugins.smartstring.base64.decode(value).replace(/['"]+/g, '').replace(/['"]+/g, '');
|
||||
if (this.options.unquote && value.startsWith(this.base64RecognitionPrefix)) {
|
||||
value = value.replace(this.base64RecognitionPrefix, '');
|
||||
value = plugins.smartstring.base64
|
||||
.decode(value)
|
||||
.replace(/['"]+/g, '')
|
||||
.replace(/['"]+/g, '');
|
||||
}
|
||||
if (this.options.trimSpace) {
|
||||
value = value.trim();
|
||||
}
|
||||
resultJson[this.headers[i]] = value;
|
||||
}
|
||||
|
14
tsconfig.json
Normal file
14
tsconfig.json
Normal file
@ -0,0 +1,14 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"experimentalDecorators": true,
|
||||
"useDefineForClassFields": false,
|
||||
"target": "ES2022",
|
||||
"module": "NodeNext",
|
||||
"moduleResolution": "NodeNext",
|
||||
"esModuleInterop": true,
|
||||
"verbatimModuleSyntax": true
|
||||
},
|
||||
"exclude": [
|
||||
"dist_*/**/*.d.ts"
|
||||
]
|
||||
}
|
17
tslint.json
17
tslint.json
@ -1,17 +0,0 @@
|
||||
{
|
||||
"extends": ["tslint:latest", "tslint-config-prettier"],
|
||||
"rules": {
|
||||
"semicolon": [true, "always"],
|
||||
"no-console": false,
|
||||
"ordered-imports": false,
|
||||
"object-literal-sort-keys": false,
|
||||
"member-ordering": {
|
||||
"options":{
|
||||
"order": [
|
||||
"static-method"
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"defaultSeverity": "warning"
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user