Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| ddb8c5c77d | |||
| bfa20f38bd | |||
| 3f52942987 | |||
| 788572370a | |||
| c683df3c35 | |||
| 0de7b75dca |
@@ -12,6 +12,9 @@ stages:
|
|||||||
- release
|
- release
|
||||||
- metadata
|
- metadata
|
||||||
|
|
||||||
|
# ====================
|
||||||
|
# security stage
|
||||||
|
# ====================
|
||||||
mirror:
|
mirror:
|
||||||
stage: security
|
stage: security
|
||||||
script:
|
script:
|
||||||
@@ -30,6 +33,9 @@ snyk:
|
|||||||
- docker
|
- docker
|
||||||
- notpriv
|
- notpriv
|
||||||
|
|
||||||
|
# ====================
|
||||||
|
# test stage
|
||||||
|
# ====================
|
||||||
testLEGACY:
|
testLEGACY:
|
||||||
stage: test
|
stage: test
|
||||||
script:
|
script:
|
||||||
@@ -68,7 +74,6 @@ release:
|
|||||||
stage: release
|
stage: release
|
||||||
script:
|
script:
|
||||||
- npmci node install stable
|
- npmci node install stable
|
||||||
- npmci npm prepare
|
|
||||||
- npmci npm publish
|
- npmci npm publish
|
||||||
only:
|
only:
|
||||||
- tags
|
- tags
|
||||||
|
|||||||
6
dist/index.d.ts
vendored
6
dist/index.d.ts
vendored
@@ -1,6 +0,0 @@
|
|||||||
export declare class Csv {
|
|
||||||
static createCsvFromString(csvStringArg: string): Promise<Csv>;
|
|
||||||
csvString: string;
|
|
||||||
getHeaders(): void;
|
|
||||||
exportAsJson(): void;
|
|
||||||
}
|
|
||||||
28
dist/index.js
vendored
28
dist/index.js
vendored
@@ -1,28 +0,0 @@
|
|||||||
"use strict";
|
|
||||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
||||||
return new (P || (P = Promise))(function (resolve, reject) {
|
|
||||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
||||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
||||||
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
|
|
||||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
||||||
});
|
|
||||||
};
|
|
||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
|
||||||
class Csv {
|
|
||||||
static createCsvFromString(csvStringArg) {
|
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
|
||||||
const csvInstance = new Csv();
|
|
||||||
csvInstance.csvString = csvStringArg;
|
|
||||||
return csvInstance;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
getHeaders() {
|
|
||||||
}
|
|
||||||
exportAsJson() {
|
|
||||||
let json = {
|
|
||||||
[`key`]: 'hi'
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
exports.Csv = Csv;
|
|
||||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7Ozs7Ozs7O0FBRUE7SUFDUyxNQUFNLENBQU8sbUJBQW1CLENBQUUsWUFBb0I7O1lBQzNELE1BQU0sV0FBVyxHQUFHLElBQUksR0FBRyxFQUFFLENBQUM7WUFDOUIsV0FBVyxDQUFDLFNBQVMsR0FBRyxZQUFZLENBQUM7WUFDckMsT0FBTyxXQUFXLENBQUM7UUFDckIsQ0FBQztLQUFBO0lBR00sVUFBVTtJQUVqQixDQUFDO0lBRU0sWUFBWTtRQUNqQixJQUFJLElBQUksR0FBRztZQUNULENBQUMsS0FBSyxDQUFDLEVBQUUsSUFBSTtTQUNkLENBQUM7SUFDSixDQUFDO0NBRUY7QUFsQkQsa0JBa0JDIn0=
|
|
||||||
2
dist/smartcsv.plugins.d.ts
vendored
2
dist/smartcsv.plugins.d.ts
vendored
@@ -1,2 +0,0 @@
|
|||||||
import * as csv from 'csv';
|
|
||||||
export { csv };
|
|
||||||
5
dist/smartcsv.plugins.js
vendored
5
dist/smartcsv.plugins.js
vendored
@@ -1,5 +0,0 @@
|
|||||||
"use strict";
|
|
||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
|
||||||
const csv = require("csv");
|
|
||||||
exports.csv = csv;
|
|
||||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRjc3YucGx1Z2lucy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3NtYXJ0Y3N2LnBsdWdpbnMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7QUFBQSwyQkFBMkI7QUFHekIsa0JBQUcifQ==
|
|
||||||
@@ -3,6 +3,7 @@
|
|||||||
"npmGlobalTools": [
|
"npmGlobalTools": [
|
||||||
"@gitzone/npmts",
|
"@gitzone/npmts",
|
||||||
"ts-node"
|
"ts-node"
|
||||||
]
|
],
|
||||||
|
"npmAccessLevel": "public"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,13 +1,14 @@
|
|||||||
{
|
{
|
||||||
"name": "@pushrocks/smartcsv",
|
"name": "@pushrocks/smartcsv",
|
||||||
"version": "1.0.3",
|
"version": "1.0.6",
|
||||||
"description": "handle csv data",
|
"description": "handle csv data | gitzone standard compliant",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
"typings": "dist/index.d.ts",
|
"typings": "dist/index.d.ts",
|
||||||
"author": "Lossless GmbH",
|
"author": "Lossless GmbH",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "(ts-node -O '{\"lib\": [ \"es2015\" ]}' test/test.ts)",
|
"test": "(ts-node -O '{\"lib\": [ \"es2015\" ]}' test/test.ts)",
|
||||||
|
"build": "(npmts)",
|
||||||
"format": "(gitzone format)"
|
"format": "(gitzone format)"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import * as smartfile from 'smartfile';
|
|||||||
let fileString: string;
|
let fileString: string;
|
||||||
let testCsv: smartcsv.Csv;
|
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');
|
fileString = smartfile.fs.toStringSync('./test/sample.csv');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
31
ts/index.ts
31
ts/index.ts
@@ -5,18 +5,42 @@ export interface ICsvConstructorOptions {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export class Csv {
|
export class Csv {
|
||||||
public static async createCsvFromString (csvStringArg: string, options: ICsvConstructorOptions): Promise<Csv> {
|
public static async createCsvFromString(
|
||||||
|
csvStringArg: string,
|
||||||
|
options: ICsvConstructorOptions
|
||||||
|
): Promise<Csv> {
|
||||||
const csvInstance = new Csv();
|
const csvInstance = new Csv();
|
||||||
csvInstance.csvString = csvStringArg;
|
csvInstance.csvString = csvStringArg;
|
||||||
|
csvInstance.determineKeyframe();
|
||||||
return csvInstance;
|
return csvInstance;
|
||||||
}
|
}
|
||||||
public csvString: string;
|
public csvString: string;
|
||||||
public headers: string[];
|
public headers: string[];
|
||||||
|
public keyFrame: string = null;
|
||||||
|
|
||||||
public options: ICsvConstructorOptions = {
|
public options: ICsvConstructorOptions = {
|
||||||
headers: true
|
headers: true
|
||||||
};
|
};
|
||||||
|
|
||||||
|
public determineKeyframe() {
|
||||||
|
let commaLength = 0;
|
||||||
|
let semicolonLength = 0;
|
||||||
|
const commaRegexResult = this.csvString.match(/,/g);
|
||||||
|
const semicolonRegexResult = this.csvString.match(/;/g);
|
||||||
|
if (commaRegexResult) {
|
||||||
|
commaLength = commaRegexResult.length;
|
||||||
|
}
|
||||||
|
if (semicolonRegexResult) {
|
||||||
|
semicolonLength = semicolonRegexResult.length;
|
||||||
|
}
|
||||||
|
// tslint:disable-next-line:prefer-conditional-expression
|
||||||
|
if (commaLength < semicolonLength) {
|
||||||
|
this.keyFrame = ';';
|
||||||
|
} else {
|
||||||
|
this.keyFrame = ',';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public serializeCsvString() {
|
public serializeCsvString() {
|
||||||
const rowArray = this.getRows();
|
const rowArray = this.getRows();
|
||||||
const resultArray = [];
|
const resultArray = [];
|
||||||
@@ -25,7 +49,7 @@ export class Csv {
|
|||||||
rowArray.shift();
|
rowArray.shift();
|
||||||
}
|
}
|
||||||
for (const row of rowArray) {
|
for (const row of rowArray) {
|
||||||
resultArray.push(row.split(';'));
|
resultArray.push(row.split(this.keyFrame));
|
||||||
}
|
}
|
||||||
return resultArray;
|
return resultArray;
|
||||||
}
|
}
|
||||||
@@ -38,7 +62,7 @@ export class Csv {
|
|||||||
const rowArray = this.getRows();
|
const rowArray = this.getRows();
|
||||||
if (this.options.headers) {
|
if (this.options.headers) {
|
||||||
let headerRow = rowArray[0];
|
let headerRow = rowArray[0];
|
||||||
this.headers = headerRow.split(';');
|
this.headers = headerRow.split(this.keyFrame);
|
||||||
}
|
}
|
||||||
return this.headers;
|
return this.headers;
|
||||||
}
|
}
|
||||||
@@ -60,5 +84,4 @@ export class Csv {
|
|||||||
}
|
}
|
||||||
return dataObjects;
|
return dataObjects;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,3 @@
|
|||||||
import * as smartq from 'smartq';
|
import * as smartq from 'smartq';
|
||||||
|
|
||||||
export {
|
export { smartq };
|
||||||
smartq
|
|
||||||
};
|
|
||||||
|
|||||||
Reference in New Issue
Block a user