Compare commits
18 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| c7324f0240 | |||
| be44a1354b | |||
| 13f3f7b2f6 | |||
| 94f2620161 | |||
| bdebb3308c | |||
| cb5ac7618b | |||
| 00aed79e18 | |||
| 438053a2f9 | |||
| 7479328e13 | |||
| 56d7ae8952 | |||
| feb41df3e2 | |||
| 1474cb1665 | |||
| 6e289a01b1 | |||
| c08aa1959f | |||
| 0dd0d31f41 | |||
| ee1f5036aa | |||
| 987cb9593e | |||
| d6ff7c54e2 |
18
.gitignore
vendored
18
.gitignore
vendored
@@ -1,6 +1,22 @@
|
||||
.nogit/
|
||||
node_modules/
|
||||
|
||||
# artifacts
|
||||
coverage/
|
||||
public/
|
||||
pages/
|
||||
|
||||
# installs
|
||||
node_modules/
|
||||
|
||||
# caches
|
||||
.yarn/
|
||||
.cache/
|
||||
.rpt2_cache
|
||||
|
||||
# builds
|
||||
dist/
|
||||
dist_web/
|
||||
dist_serve/
|
||||
dist_ts_web/
|
||||
|
||||
# custom
|
||||
@@ -1,5 +1,5 @@
|
||||
# gitzone standard
|
||||
image: hosttoday/ht-docker-node:npmci
|
||||
# gitzone ci_default
|
||||
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||
|
||||
cache:
|
||||
paths:
|
||||
@@ -26,6 +26,7 @@ mirror:
|
||||
snyk:
|
||||
stage: security
|
||||
script:
|
||||
- npmci npm prepare
|
||||
- npmci command npm install -g snyk
|
||||
- npmci command npm install --ignore-scripts
|
||||
- npmci command snyk test
|
||||
@@ -36,21 +37,11 @@ snyk:
|
||||
# ====================
|
||||
# test stage
|
||||
# ====================
|
||||
testLEGACY:
|
||||
stage: test
|
||||
script:
|
||||
- npmci node install legacy
|
||||
- npmci npm install
|
||||
- npmci npm test
|
||||
coverage: /\d+.?\d+?\%\s*coverage/
|
||||
tags:
|
||||
- docker
|
||||
- notpriv
|
||||
allow_failure: true
|
||||
|
||||
testLTS:
|
||||
stage: test
|
||||
script:
|
||||
- npmci npm prepare
|
||||
- npmci node install lts
|
||||
- npmci npm install
|
||||
- npmci npm test
|
||||
@@ -59,12 +50,13 @@ testLTS:
|
||||
- docker
|
||||
- notpriv
|
||||
|
||||
testSTABLE:
|
||||
testBuild:
|
||||
stage: test
|
||||
script:
|
||||
- npmci node install stable
|
||||
- npmci npm prepare
|
||||
- npmci node install lts
|
||||
- npmci npm install
|
||||
- npmci npm test
|
||||
- npmci command npm run build
|
||||
coverage: /\d+.?\d+?\%\s*coverage/
|
||||
tags:
|
||||
- docker
|
||||
@@ -73,7 +65,7 @@ testSTABLE:
|
||||
release:
|
||||
stage: release
|
||||
script:
|
||||
- npmci node install stable
|
||||
- npmci node install lts
|
||||
- npmci npm publish
|
||||
only:
|
||||
- tags
|
||||
@@ -86,19 +78,11 @@ release:
|
||||
# ====================
|
||||
codequality:
|
||||
stage: metadata
|
||||
image: docker:stable
|
||||
allow_failure: true
|
||||
services:
|
||||
- docker:stable-dind
|
||||
script:
|
||||
- export SP_VERSION=$(echo "$CI_SERVER_VERSION" | sed 's/^\([0-9]*\)\.\([0-9]*\).*/\1-\2-stable/')
|
||||
- docker run
|
||||
--env SOURCE_CODE="$PWD"
|
||||
--volume "$PWD":/code
|
||||
--volume /var/run/docker.sock:/var/run/docker.sock
|
||||
"registry.gitlab.com/gitlab-org/security-products/codequality:$SP_VERSION" /code
|
||||
artifacts:
|
||||
paths: [codeclimate.json]
|
||||
- npmci command npm install -g tslint typescript
|
||||
- npmci npm install
|
||||
- npmci command "tslint -c tslint.json ./ts/**/*.ts"
|
||||
tags:
|
||||
- docker
|
||||
- priv
|
||||
@@ -117,8 +101,10 @@ pages:
|
||||
image: hosttoday/ht-docker-node:npmci
|
||||
stage: metadata
|
||||
script:
|
||||
- npmci command npm install -g npmpage
|
||||
- npmci command npmpage
|
||||
- npmci command npm install -g @gitzone/tsdoc
|
||||
- npmci npm prepare
|
||||
- npmci npm install
|
||||
- npmci command tsdoc
|
||||
tags:
|
||||
- docker
|
||||
- notpriv
|
||||
@@ -128,3 +114,4 @@ pages:
|
||||
expire_in: 1 week
|
||||
paths:
|
||||
- public
|
||||
allow_failure: true
|
||||
|
||||
4
.snyk
Normal file
4
.snyk
Normal file
@@ -0,0 +1,4 @@
|
||||
# Snyk (https://snyk.io) policy file, patches or ignores known vulnerabilities.
|
||||
version: v1.12.0
|
||||
ignore: {}
|
||||
patch: {}
|
||||
@@ -1,8 +1,16 @@
|
||||
{
|
||||
"npmci": {
|
||||
"npmGlobalTools": [
|
||||
"@gitzone/npmts"
|
||||
],
|
||||
"npmGlobalTools": [],
|
||||
"npmAccessLevel": "public"
|
||||
},
|
||||
"gitzone": {
|
||||
"module": {
|
||||
"githost": "gitlab.com",
|
||||
"gitscope": "pushrocks",
|
||||
"gitrepo": "smartcsv",
|
||||
"shortDescription": "handle csv data | gitzone standard compliant",
|
||||
"npmPackagename": "@pushrocks/smartcsv",
|
||||
"license": "MIT"
|
||||
}
|
||||
}
|
||||
}
|
||||
1265
package-lock.json
generated
1265
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
31
package.json
31
package.json
@@ -1,23 +1,36 @@
|
||||
{
|
||||
"name": "@pushrocks/smartcsv",
|
||||
"version": "1.0.8",
|
||||
"private": true,
|
||||
"version": "1.0.17",
|
||||
"private": false,
|
||||
"description": "handle csv data | gitzone standard compliant",
|
||||
"main": "dist/index.js",
|
||||
"typings": "dist/index.d.ts",
|
||||
"author": "Lossless GmbH",
|
||||
"license": "MIT",
|
||||
"scripts": {
|
||||
"test": "(tsrun test/test.ts)",
|
||||
"build": "(npmts)",
|
||||
"test": "(tstest test/)",
|
||||
"build": "(tsbuild)",
|
||||
"format": "(gitzone format)"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@gitzone/tsrun": "^1.0.5",
|
||||
"smartfile": "^4.2.28",
|
||||
"tapbundle": "^2.0.0"
|
||||
"@gitzone/tsbuild": "^2.1.11",
|
||||
"@gitzone/tsrun": "^1.2.6",
|
||||
"@gitzone/tstest": "^1.0.21",
|
||||
"@pushrocks/smartfile": "^7.0.2",
|
||||
"@pushrocks/tapbundle": "^3.0.9",
|
||||
"@types/node": "^12.0.2"
|
||||
},
|
||||
"dependencies": {
|
||||
"smartq": "^1.1.8"
|
||||
}
|
||||
"@pushrocks/smartpromise": "^3.0.2"
|
||||
},
|
||||
"files": [
|
||||
"ts/*",
|
||||
"ts_web/*",
|
||||
"dist/*",
|
||||
"dist_web/*",
|
||||
"assets/*",
|
||||
"cli.js",
|
||||
"npmextra.json",
|
||||
"readme.md"
|
||||
]
|
||||
}
|
||||
|
||||
26
readme.md
Normal file
26
readme.md
Normal file
@@ -0,0 +1,26 @@
|
||||
# @pushrocks/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/)
|
||||
|
||||
## 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/)
|
||||
|
||||
## Usage
|
||||
|
||||
For further information read the linked docs at the top of this readme.
|
||||
|
||||
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh)
|
||||
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy.html)
|
||||
|
||||
[](https://maintainedby.lossless.com)
|
||||
12
test/test.ts
12
test/test.ts
@@ -1,9 +1,9 @@
|
||||
// tslint:disable-next-line:no-implicit-dependencies
|
||||
import { expect, tap } from 'tapbundle';
|
||||
import { expect, tap } from '@pushrocks/tapbundle';
|
||||
import * as smartcsv from '../ts/index';
|
||||
|
||||
// tslint:disable-next-line:no-implicit-dependencies
|
||||
import * as smartfile from 'smartfile';
|
||||
import * as smartfile from '@pushrocks/smartfile';
|
||||
|
||||
let fileString: string;
|
||||
let testCsv: smartcsv.Csv;
|
||||
@@ -18,4 +18,12 @@ tap.test('should create a valid csv', async () => {
|
||||
console.log(result);
|
||||
});
|
||||
|
||||
tap.test('should create a valid csv string', async () => {
|
||||
const createdCsvString = await smartcsv.Csv.createCsvStringFromArray([
|
||||
{ wow: 'hi', wow2: 'there' },
|
||||
{ wow: 'really', wow3: 'yes' }
|
||||
]);
|
||||
console.log(createdCsvString);
|
||||
});
|
||||
|
||||
tap.start();
|
||||
|
||||
54
ts/index.ts
54
ts/index.ts
@@ -5,15 +5,49 @@ export interface ICsvConstructorOptions {
|
||||
}
|
||||
|
||||
export class Csv {
|
||||
// STATIC
|
||||
|
||||
/**
|
||||
* creates a Csv Object from string
|
||||
* @param csvStringArg
|
||||
* @param optionsArg
|
||||
*/
|
||||
public static async createCsvFromString(
|
||||
csvStringArg: string,
|
||||
options: ICsvConstructorOptions
|
||||
optionsArg: ICsvConstructorOptions
|
||||
): Promise<Csv> {
|
||||
const csvInstance = new Csv();
|
||||
csvInstance.csvString = csvStringArg;
|
||||
csvInstance.determineKeyframe();
|
||||
const csvInstance = new Csv(csvStringArg, optionsArg);
|
||||
return csvInstance;
|
||||
}
|
||||
|
||||
public static async createCsvStringFromArray(arrayArg: any[]): Promise<string> {
|
||||
const foundKeys: string[] = [];
|
||||
|
||||
// lets deal with the keys
|
||||
for (const objectArg of arrayArg) {
|
||||
for (const key of Object.keys(objectArg)) {
|
||||
foundKeys.includes(key) ? null : foundKeys.push(key);
|
||||
}
|
||||
}
|
||||
|
||||
// lets deal with the data
|
||||
const dataRows: string[] = [];
|
||||
for (const objectArg of arrayArg) {
|
||||
const dataRowArray: string[] = [];
|
||||
for (const key of foundKeys) {
|
||||
dataRowArray.push(objectArg[key]);
|
||||
}
|
||||
dataRows.push(dataRowArray.join(','));
|
||||
}
|
||||
|
||||
// lets put togehter the csv string and return it
|
||||
const headerString = foundKeys.join(',');
|
||||
const dataString = dataRows.join('\n');
|
||||
const csvString = `${headerString}\n${dataString}\n`;
|
||||
return csvString;
|
||||
}
|
||||
|
||||
// INSTANCE
|
||||
public csvString: string;
|
||||
public headers: string[];
|
||||
public keyFrame: string = null;
|
||||
@@ -22,6 +56,15 @@ export class Csv {
|
||||
headers: true
|
||||
};
|
||||
|
||||
constructor(csvStringArg: string, optionsArg: ICsvConstructorOptions) {
|
||||
this.csvString = csvStringArg;
|
||||
this.options = optionsArg;
|
||||
this.determineKeyframe();
|
||||
}
|
||||
|
||||
/**
|
||||
* determines the keyframe of the csv string
|
||||
*/
|
||||
public determineKeyframe() {
|
||||
let commaLength = 0;
|
||||
let semicolonLength = 0;
|
||||
@@ -41,6 +84,9 @@ export class Csv {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* serializes the csv string
|
||||
*/
|
||||
public serializeCsvString() {
|
||||
const rowArray = this.getRows();
|
||||
const resultArray = [];
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
import * as smartq from 'smartq';
|
||||
import * as smartq from '@pushrocks/smartpromise';
|
||||
|
||||
export { smartq };
|
||||
|
||||
20
tslint.json
20
tslint.json
@@ -1,13 +1,17 @@
|
||||
{
|
||||
"extends": [
|
||||
"tslint:latest",
|
||||
"tslint-config-prettier"
|
||||
],
|
||||
"extends": ["tslint:latest", "tslint-config-prettier"],
|
||||
"rules": {
|
||||
"semicolon": [
|
||||
true,
|
||||
"always"
|
||||
"semicolon": [true, "always"],
|
||||
"no-console": false,
|
||||
"ordered-imports": false,
|
||||
"object-literal-sort-keys": false,
|
||||
"member-ordering": {
|
||||
"options":{
|
||||
"order": [
|
||||
"static-method"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
},
|
||||
"defaultSeverity": "warning"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user