From 55fbd0460cce18c54f731e0f8a672bc9360041ee Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 15 Jun 2020 05:44:03 +0000 Subject: [PATCH 01/23] npm: bump eslint-plugin-prettier from 3.1.3 to 3.1.4 Bumps [eslint-plugin-prettier](https://github.com/prettier/eslint-plugin-prettier) from 3.1.3 to 3.1.4. - [Release notes](https://github.com/prettier/eslint-plugin-prettier/releases) - [Changelog](https://github.com/prettier/eslint-plugin-prettier/blob/master/CHANGELOG.md) - [Commits](https://github.com/prettier/eslint-plugin-prettier/compare/v3.1.3...v3.1.4) Signed-off-by: dependabot[bot] --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 1eb725c..63cac6f 100644 --- a/package.json +++ b/package.json @@ -125,7 +125,7 @@ "cross-env": "7.0.2", "eslint": "7.2.0", "eslint-config-prettier": "6.11.0", - "eslint-plugin-prettier": "3.1.3", + "eslint-plugin-prettier": "3.1.4", "eslint-plugin-react": "7.20.0", "eslint-plugin-react-hooks": "4.0.4", "generate-changelog": "1.8.0", From 460142f161d4e48f6c646f70ac9c504f5e1144d6 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 16 Jun 2020 05:45:00 +0000 Subject: [PATCH 02/23] npm: bump @microsoft/api-extractor from 7.8.11 to 7.8.12 Bumps [@microsoft/api-extractor](https://github.com/microsoft/rushstack) from 7.8.11 to 7.8.12. - [Release notes](https://github.com/microsoft/rushstack/releases) - [Commits](https://github.com/microsoft/rushstack/compare/@microsoft/api-extractor_v7.8.11...@microsoft/api-extractor_v7.8.12) Signed-off-by: dependabot[bot] --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 63cac6f..48c3391 100644 --- a/package.json +++ b/package.json @@ -116,7 +116,7 @@ "homepage": "https://gregoranders.github.io/ts-csv/", "devDependencies": { "@microsoft/api-documenter": "7.8.12", - "@microsoft/api-extractor": "7.8.11", + "@microsoft/api-extractor": "7.8.12", "@types/jest": "26.0.0", "@types/node": "14.0.13", "@typescript-eslint/eslint-plugin": "3.2.0", From 56fd575a97b2c295be040990c2ee043ef5136557 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 16 Jun 2020 05:47:54 +0000 Subject: [PATCH 03/23] npm: bump @typescript-eslint/parser from 3.2.0 to 3.3.0 Bumps [@typescript-eslint/parser](https://github.com/typescript-eslint/typescript-eslint/tree/HEAD/packages/parser) from 3.2.0 to 3.3.0. - [Release notes](https://github.com/typescript-eslint/typescript-eslint/releases) - [Changelog](https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/parser/CHANGELOG.md) - [Commits](https://github.com/typescript-eslint/typescript-eslint/commits/v3.3.0/packages/parser) Signed-off-by: dependabot[bot] --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 63cac6f..edeb27b 100644 --- a/package.json +++ b/package.json @@ -120,7 +120,7 @@ "@types/jest": "26.0.0", "@types/node": "14.0.13", "@typescript-eslint/eslint-plugin": "3.2.0", - "@typescript-eslint/parser": "3.2.0", + "@typescript-eslint/parser": "3.3.0", "cpx": "1.5.0", "cross-env": "7.0.2", "eslint": "7.2.0", From c1787f9cb92661d0fe51660cdaa70b71b2d5114e Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 16 Jun 2020 05:50:48 +0000 Subject: [PATCH 04/23] npm: bump @typescript-eslint/eslint-plugin from 3.2.0 to 3.3.0 Bumps [@typescript-eslint/eslint-plugin](https://github.com/typescript-eslint/typescript-eslint/tree/HEAD/packages/eslint-plugin) from 3.2.0 to 3.3.0. - [Release notes](https://github.com/typescript-eslint/typescript-eslint/releases) - [Changelog](https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/CHANGELOG.md) - [Commits](https://github.com/typescript-eslint/typescript-eslint/commits/v3.3.0/packages/eslint-plugin) Signed-off-by: dependabot[bot] --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 63cac6f..bf5d8be 100644 --- a/package.json +++ b/package.json @@ -119,7 +119,7 @@ "@microsoft/api-extractor": "7.8.11", "@types/jest": "26.0.0", "@types/node": "14.0.13", - "@typescript-eslint/eslint-plugin": "3.2.0", + "@typescript-eslint/eslint-plugin": "3.3.0", "@typescript-eslint/parser": "3.2.0", "cpx": "1.5.0", "cross-env": "7.0.2", From 9332c3211edde18c78ca88e54943f909ada6007e Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 16 Jun 2020 05:53:23 +0000 Subject: [PATCH 05/23] npm: bump @microsoft/api-documenter from 7.8.12 to 7.8.13 Bumps [@microsoft/api-documenter](https://github.com/microsoft/rushstack) from 7.8.12 to 7.8.13. - [Release notes](https://github.com/microsoft/rushstack/releases) - [Commits](https://github.com/microsoft/rushstack/compare/@microsoft/api-documenter_v7.8.12...@microsoft/api-documenter_v7.8.13) Signed-off-by: dependabot[bot] --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 63cac6f..273e074 100644 --- a/package.json +++ b/package.json @@ -115,7 +115,7 @@ }, "homepage": "https://gregoranders.github.io/ts-csv/", "devDependencies": { - "@microsoft/api-documenter": "7.8.12", + "@microsoft/api-documenter": "7.8.13", "@microsoft/api-extractor": "7.8.11", "@types/jest": "26.0.0", "@types/node": "14.0.13", From dba06913af3e0f818ef798058e854e10f8a92e90 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 17 Jun 2020 05:42:53 +0000 Subject: [PATCH 06/23] npm: bump jest-spec-reporter from 1.0.13 to 1.0.14 Bumps [jest-spec-reporter](https://github.com/pierreroth64/jest-spec-reporter) from 1.0.13 to 1.0.14. - [Release notes](https://github.com/pierreroth64/jest-spec-reporter/releases) - [Commits](https://github.com/pierreroth64/jest-spec-reporter/compare/v1.0.13...v1.0.14) Signed-off-by: dependabot[bot] --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 63cac6f..ccb4adb 100644 --- a/package.json +++ b/package.json @@ -134,7 +134,7 @@ "jest-cli": "26.0.1", "jest-html-reporter": "3.1.3", "jest-junit": "10.0.0", - "jest-spec-reporter": "1.0.13", + "jest-spec-reporter": "1.0.14", "lint-staged": "10.2.10", "prettier": "2.0.5", "rimraf": "3.0.2", From fbd4d5a8e8c7ae044870f47822a73ddc3b6d74b0 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 18 Jun 2020 05:47:18 +0000 Subject: [PATCH 07/23] npm: bump lint-staged from 10.2.10 to 10.2.11 Bumps [lint-staged](https://github.com/okonet/lint-staged) from 10.2.10 to 10.2.11. - [Release notes](https://github.com/okonet/lint-staged/releases) - [Commits](https://github.com/okonet/lint-staged/compare/v10.2.10...v10.2.11) Signed-off-by: dependabot[bot] --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 91abfac..6daee5f 100644 --- a/package.json +++ b/package.json @@ -135,7 +135,7 @@ "jest-html-reporter": "3.1.3", "jest-junit": "10.0.0", "jest-spec-reporter": "1.0.14", - "lint-staged": "10.2.10", + "lint-staged": "10.2.11", "prettier": "2.0.5", "rimraf": "3.0.2", "ts-jest": "26.1.0", From 9ec51457a62f9eaefd6d889026f57973fef771e3 Mon Sep 17 00:00:00 2001 From: Gregor Anders Date: Sat, 20 Jun 2020 13:16:20 +0200 Subject: [PATCH 08/23] chore(eslint): move config move eslint config into package.json --- .eslintrc.js | 19 ------------------- package.json | 18 ++++++++++++++++++ 2 files changed, 18 insertions(+), 19 deletions(-) delete mode 100644 .eslintrc.js diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index f4c4eae..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1,19 +0,0 @@ -module.exports = { - root: true, - parser: '@typescript-eslint/parser', - plugins: ['@typescript-eslint'], - extends: [ - 'eslint:recommended', - 'plugin:@typescript-eslint/recommended', - 'prettier/@typescript-eslint', - ], - parserOptions: { - ecmaVersion: 2020, - sourceType: 'module', - ecmaFeatures: { - jsx: true, - }, - }, - rules: {}, - settings: {}, -}; diff --git a/package.json b/package.json index 91abfac..bf88c20 100644 --- a/package.json +++ b/package.json @@ -41,6 +41,24 @@ "jest", "typescript" ], + "eslintConfig": { + "root": true, + "parser": "@typescript-eslint/parser", + "plugins": ["@typescript-eslint"], + "extends": [ + "eslint:recommended", + "plugin:@typescript-eslint/recommended", + "prettier/@typescript-eslint" + ], + "parserOptions": { + "ecmaVersion": 2020, + "sourceType": "module", + "ecmaFeatures": { + } + }, + "rules": {}, + "settings": {} + }, "husky": { "hooks": { "pre-commit": "lint-staged && npm run prepare", From 72c5be2458f963b037e54d1a1ffcd6f0a7cdfc31 Mon Sep 17 00:00:00 2001 From: Gregor Anders Date: Sat, 20 Jun 2020 13:17:12 +0200 Subject: [PATCH 09/23] chore(package): remove tasks remove release tasks from package.json --- package.json | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/package.json b/package.json index bf88c20..a714d35 100644 --- a/package.json +++ b/package.json @@ -15,10 +15,7 @@ "prepare": "npm test && npm run build && npm run api-extractor && npm run api-documenter && eslint --ext .ts ./src", "api-extractor": "api-extractor run --local --verbose", "api-documenter": "api-documenter markdown --input ./dist --output ./docs-tmp && cpx 'docs-tmp/**/*.*' docs", - "codeclimate": "docker run --interactive --tty --rm --env CODECLIMATE_CODE=\"$PWD\" --volume \"$PWD\":/code --volume /var/run/docker.sock:/var/run/docker.sock --volume /tmp/cc:/tmp/cc codeclimate/codeclimate analyze", - "release:major": "changelog -M && git add CHANGELOG.md && git commit -m 'chore(changelog): CHANGELOG.md' && npm version major -m \"chore(release): %s \"", - "release:minor": "changelog -m && git add CHANGELOG.md && git commit -m 'chore(changelog): CHANGELOG.md' && npm version minor -m \"chore(release): %s \"", - "release:patch": "changelog -p && git add CHANGELOG.md && git commit -m 'chore(changelog): CHANGELOG.md' && npm version patch -m \"chore(release): %s \"" + "codeclimate": "docker run --interactive --tty --rm --env CODECLIMATE_CODE=\"$PWD\" --volume \"$PWD\":/code --volume /var/run/docker.sock:/var/run/docker.sock --volume /tmp/cc:/tmp/cc codeclimate/codeclimate analyze" }, "main": "dist/cjs/index.js", "module": "dist/esm/index.js", From dfb954df74bb4ef7c84a2795a67d972a2dd17719 Mon Sep 17 00:00:00 2001 From: Gregor Anders Date: Sat, 20 Jun 2020 13:18:19 +0200 Subject: [PATCH 10/23] chore(release): remove file remove typing from dist --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index a714d35..656df48 100644 --- a/package.json +++ b/package.json @@ -12,7 +12,7 @@ "script": "npm run script:cjs && npm run script:esm", "script:cjs": "tsc --project ./ --module commonjs --target es5 --outDir ./dist/cjs", "script:esm": "tsc --project ./ --module es6 --declaration --declarationDir ./dist/esm --outDir ./dist/esm", - "prepare": "npm test && npm run build && npm run api-extractor && npm run api-documenter && eslint --ext .ts ./src", + "prepare": "npm test && npm run build && npm run api-extractor && npm run api-documenter && eslint --ext .ts ./src && rimraf ./build/esm/index.d.ts", "api-extractor": "api-extractor run --local --verbose", "api-documenter": "api-documenter markdown --input ./dist --output ./docs-tmp && cpx 'docs-tmp/**/*.*' docs", "codeclimate": "docker run --interactive --tty --rm --env CODECLIMATE_CODE=\"$PWD\" --volume \"$PWD\":/code --volume /var/run/docker.sock:/var/run/docker.sock --volume /tmp/cc:/tmp/cc codeclimate/codeclimate analyze" From 07c951150201720b79e7bb6b6ba0e742653fe2b4 Mon Sep 17 00:00:00 2001 From: Gregor Anders Date: Sat, 20 Jun 2020 13:19:22 +0200 Subject: [PATCH 11/23] refactor(build): refactor workflows refactor github workflows --- .github/workflows/development.yml | 7 ++--- .github/workflows/feature.yml | 7 ++--- .github/workflows/master.yml | 51 +++++++++++++++---------------- 3 files changed, 30 insertions(+), 35 deletions(-) diff --git a/.github/workflows/development.yml b/.github/workflows/development.yml index 2882bf0..176d02b 100644 --- a/.github/workflows/development.yml +++ b/.github/workflows/development.yml @@ -5,6 +5,9 @@ on: branches: - development +env: + CI: true + jobs: build: runs-on: ${{ matrix.os }} @@ -26,13 +29,9 @@ jobs: - name: npm install run: | npm install - env: - CI: true - name: code coverage if: matrix.os == 'ubuntu-latest' && matrix.node-version == '14.x' uses: coverallsapp/github-action@master with: github-token: ${{ secrets.GITHUB_TOKEN }} path-to-lcov: ./test/coverage/lcov.info - env: - CI: true diff --git a/.github/workflows/feature.yml b/.github/workflows/feature.yml index 4775a58..f2b31b6 100644 --- a/.github/workflows/feature.yml +++ b/.github/workflows/feature.yml @@ -5,6 +5,9 @@ on: branches: - feature/* +env: + CI: true + jobs: build: runs-on: ${{ matrix.os }} @@ -26,13 +29,9 @@ jobs: - name: npm install run: | npm install - env: - CI: true - name: code coverage if: matrix.os == 'ubuntu-latest' && matrix.node-version == '14.x' uses: coverallsapp/github-action@master with: github-token: ${{ secrets.GITHUB_TOKEN }} path-to-lcov: ./test/coverage/lcov.info - env: - CI: true diff --git a/.github/workflows/master.yml b/.github/workflows/master.yml index b9d8fc1..9e93c0a 100644 --- a/.github/workflows/master.yml +++ b/.github/workflows/master.yml @@ -5,6 +5,10 @@ on: branches: - master +env: + CI: true + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + jobs: build: runs-on: ${{ matrix.os }} @@ -26,37 +30,30 @@ jobs: - name: npm install run: | npm install - env: - CI: true - name: code coverage if: matrix.os == 'ubuntu-latest' && matrix.node-version == '14.x' uses: coverallsapp/github-action@master with: github-token: ${{ secrets.GITHUB_TOKEN }} path-to-lcov: ./test/coverage/lcov.info + - name: publish code coverage to code climate + if: matrix.os == 'ubuntu-latest' && matrix.node-version == '14.x' + uses: paambaati/codeclimate-action@v2.6.0 env: - CI: true - # - name: publish code coverage to code climate - # if: matrix.os == 'ubuntu-latest' && matrix.node-version == '14.x' - # uses: paambaati/codeclimate-action@v2.3.0 - # env: - # CI: true - # CC_TEST_REPORTER_ID: ${{ secrets.CODE_CLIMATE }} - # with: - # coverageCommand: npm run test - # coverageLocations: | - # ./test/coverage/lcov.info:lcov - # debug: true - # - name: create release - # if: matrix.os == 'ubuntu-latest' && matrix.node-version == '14.x' - # id: createrelease - # uses: gregoranders/nodejs-create-release@v0.0.6 - # env: - # GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - # PACKAGE_JSON: ${{ steps.projectinfo.outputs.context }} - # with: - # tag: v${{ steps.projectinfo.outputs.version }} - # name: ${{ steps.projectinfo.outputs.version }} Release - # body: ${{ steps.projectinfo.outputs.name }} - ${{ steps.projectinfo.outputs.version }} Release - # target: ${{ github.ref }} - # draft: true + CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }} + with: + coverageCommand: npm run test + coverageLocations: | + ./test/coverage/lcov.info:lcov + - name: create release + if: matrix.os == 'ubuntu-latest' && matrix.node-version == '14.x' + id: createrelease + uses: gregoranders/nodejs-create-release@v0.0.6 + env: + PACKAGE_JSON: ${{ steps.projectinfo.outputs.context }} + with: + tag: v${{ steps.projectinfo.outputs.version }} + name: ${{ steps.projectinfo.outputs.version }} Release + body: ${{ steps.projectinfo.outputs.name }} - ${{ steps.projectinfo.outputs.version }} Release + target: ${{ github.ref }} + draft: true From 0e68a0e4da12f3ae86cd1b225b2517325d98f9c8 Mon Sep 17 00:00:00 2001 From: Gregor Anders Date: Sat, 20 Jun 2020 13:19:59 +0200 Subject: [PATCH 12/23] build(release): add release workflow add release workflow with publish to npm --- .github/workflows/release.yml | 37 +++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 .github/workflows/release.yml diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..28e7550 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,37 @@ +name: Release CI + +on: + release: + types: + - edited + +env: + CI: true + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + +jobs: + build: + runs-on: ${{ matrix.os }} + + strategy: + matrix: + os: [ubuntu-latest, macos-latest, windows-latest] + node-version: [14.x] + + steps: + - uses: actions/checkout@v2 + - name: Use Node.js ${{ matrix.node-version }} on ${{ matrix.os }} + uses: actions/setup-node@v1 + with: + node-version: ${{ matrix.node-version }} + - name: nodejs project information + id: projectinfo + uses: gregoranders/nodejs-project-info@v0.0.6 + - name: npm install + run: | + npm install + - name: npm publish + env: + NPM_TOKEN: ${{ secrets.NPM_TOKEN }} + run: | + npm publish --access public From 1773dc798ac9c1f8481514a7f6608b2146753596 Mon Sep 17 00:00:00 2001 From: Gregor Anders Date: Sat, 20 Jun 2020 13:20:42 +0200 Subject: [PATCH 13/23] fix(tsconfig): remove DOM remove DOM as library from tsconfig --- tsconfig.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tsconfig.json b/tsconfig.json index 6d30d33..c504341 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -8,7 +8,7 @@ "experimentalDecorators": true, "forceConsistentCasingInFileNames": true, "importHelpers": false, - "lib": ["DOM", "ESNext"], + "lib": ["ESNext"], "target": "ESNext", "module": "ESNext", "moduleResolution": "Node", From 9742113ecb8136a1d3cbd34360043c915cb2ce05 Mon Sep 17 00:00:00 2001 From: Gregor Anders Date: Sat, 20 Jun 2020 13:21:23 +0200 Subject: [PATCH 14/23] chore(npm): remove .npmignore --- .npmignore | 7 ------- 1 file changed, 7 deletions(-) delete mode 100644 .npmignore diff --git a/.npmignore b/.npmignore deleted file mode 100644 index 7b986e3..0000000 --- a/.npmignore +++ /dev/null @@ -1,7 +0,0 @@ -api/ -dist/ -docs/ -CHANGELOG.md -SECURITY.md -README.md -LICENSE From ae46c5d87b0a7336617f624fdb9f086f7efbeba6 Mon Sep 17 00:00:00 2001 From: Gregor Anders Date: Sat, 20 Jun 2020 13:23:29 +0200 Subject: [PATCH 15/23] refactor(index): make result immutable - ensure the result is immutable - adjust docs - add/adjust tests --- README.md | 79 ++++++++++++++++++++++++++++++++++------ docs/csv.parser.json.md | 1 + docs/csv.parser.md | 4 +-- docs/csv.parser.rows.md | 1 + etc/csv.api.md | 2 ++ src/index.spec.ts | 80 +++++++++++++++++++++++++++++++++++++++++ src/index.ts | 24 +++++++++---- 7 files changed, 172 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index 7684e3c..075b778 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # @gregoranders/csv -## Simple CSV parser in [TypeScript](http://www.typescriptlang.org/) +## Simple CSV parser in [TypeScript][typescript-url] ## [API Docs](./docs/index.md) @@ -12,13 +12,14 @@ [![types][npm-types-image]][npm-types-url] [![node][node-image]][node-url] -[![Main Language](https://img.shields.io/github/languages/top/gregoranders/ts-csv)][code-metric-url] [![Languages](https://img.shields.io/github/languages/count/gregoranders/ts-csv)][code-metric-url] [![Code Size](https://img.shields.io/github/languages/code-size/gregoranders/ts-csv)][code-metric-url] [![Repo-Size](https://img.shields.io/github/repo-size/gregoranders/ts-csv)][code-metric-url] +[![Main Language][language-image]][code-metric-url] [![Languages][languages-image]][code-metric-url] [![Code Size][code-size-image]][code-metric-url] [![Repo-Size][repo-size-image]][code-metric-url] ## Features -- TypeScript -- Jest Snapshot/Unit Tests with Code Coverage -- GitHub CI Integration (feature, development, master) +- [TypeScript][typescript-url] +- [Jest][jest-url] Unit Tests with Code Coverage +- GitHub CI Integration (feature, development, master, release) +- Publish via CI - Code Quality via Code Climate | | | | @@ -37,9 +38,62 @@ npm install --save-dev @gregoranders/csv import Parser from '@gregoranders/csv'; const parser = new Parser(); -const rows = parser.parse('a,b,c\n1,2,3'); - -console.log(rows); +const rows = parser.parse('a,b,c\n1,2,3\n4,5,6'); + +console.log(JSON.stringify(rows, null, 2)); + +[ + [ + "a", + "b", + "c" + ], + [ + "1", + "2", + "3" + ], + [ + "4", + "5", + "6" + ] +] + +console.log(JSON.stringify(parser.rows, null, 2)); + +[ + [ + "a", + "b", + "c" + ], + [ + "1", + "2", + "3" + ], + [ + "4", + "5", + "6" + ] +] + +console.log(JSON.stringify(parser.json, null, 2)); + +[ + { + "a": "1", + "b": "2", + "c": "3" + }, + { + "a": "4", + "b": "5", + "c": "6" + } +] ``` ### Clone repository @@ -62,8 +116,7 @@ npm run build ### Testing -#### Test using [Jest](https://jestjs.io/) - +#### Test using [Jest][jest-url] ``` npm test ``` @@ -122,3 +175,9 @@ npm run clear [npm-types-image]: https://img.shields.io/npm/types/@gregoranders/csv [release-url]: https://www.npmjs.com/package/@gregoranders/csv [release-image]: https://img.shields.io/github/release/gregoranders/ts-csv +[language-image]: https://img.shields.io/github/languages/top/gregoranders/ts-csv +[languages-image]: https://img.shields.io/github/languages/count/gregoranders/ts-csv +[code-size-image]: https://img.shields.io/github/languages/code-size/gregoranders/ts-csv +[repo-size-image]: https://img.shields.io/github/repo-size/gregoranders/ts-csv +[typescript-url]: http://www.typescriptlang.org/ +[jest-url]: https://jestjs.io diff --git a/docs/csv.parser.json.md b/docs/csv.parser.json.md index 5bcc0a5..8f566aa 100644 --- a/docs/csv.parser.json.md +++ b/docs/csv.parser.json.md @@ -9,5 +9,6 @@ returns rows as JSON using the first row as property name provider Signature: ```typescript +/** @virtual */ get json(): readonly T[]; ``` diff --git a/docs/csv.parser.md b/docs/csv.parser.md index 785e151..e70f3ea 100644 --- a/docs/csv.parser.md +++ b/docs/csv.parser.md @@ -19,9 +19,7 @@ export declare class Parser> import Parser from '@gregoranders/csv'; const parser = new Parser(); -const rows = parser.parse('a,b,c\n1,2,3'); - -console.log(rows); +const rows = parser.parse('a,b,c\n1,2,3\n4,5,6'); ``` diff --git a/docs/csv.parser.rows.md b/docs/csv.parser.rows.md index 04755ed..a450eb7 100644 --- a/docs/csv.parser.rows.md +++ b/docs/csv.parser.rows.md @@ -9,5 +9,6 @@ returns rows Signature: ```typescript +/** @virtual */ get rows(): readonly Row[]; ``` diff --git a/etc/csv.api.md b/etc/csv.api.md index eb4638f..ea8d81a 100644 --- a/etc/csv.api.md +++ b/etc/csv.api.md @@ -26,8 +26,10 @@ export const libversion = "0.0.3"; // @public class Parser> { constructor(configuration?: Configuration); + // @virtual get json(): readonly T[]; parse(text: string): readonly Row[]; + // @virtual get rows(): readonly Row[]; } diff --git a/src/index.spec.ts b/src/index.spec.ts index cd72ada..634f0fb 100644 --- a/src/index.spec.ts +++ b/src/index.spec.ts @@ -195,4 +195,84 @@ describe(`${TestSubject.libname} ${TestSubject.libversion} - csv`, () => { }); }); }); + + describe(`returned value is immutable`, () => { + it('parse should return immutable value', () => { + const testSubject = new TestSubject.Parser(); + const rows = testSubject.parse('1,2,3\n,b,c'); + + const wrows = (rows as unknown) as Array; + expect.assertions(3) + + try { + wrows.push(['test']); + } catch (error) { + expect(error).toStrictEqual(TypeError('Cannot add property 2, object is not extensible')); + } + + try { + wrows[0].push('test'); + } catch (error) { + expect(error).toStrictEqual(TypeError('Cannot add property 3, object is not extensible')); + } + + try { + wrows[0][0] = 'test'; + } catch (error) { + expect(error).toStrictEqual(TypeError(`Cannot assign to read only property '0' of object '[object Array]'`)); + } + }); + + it('rows should return immutable value', () => { + const testSubject = new TestSubject.Parser(); + testSubject.parse('1,2,3\n,b,c'); + + const wrows = (testSubject.rows as unknown) as Array; + expect.assertions(3) + + try { + wrows.push(['test']); + } catch (error) { + expect(error).toStrictEqual(TypeError('Cannot add property 2, object is not extensible')); + } + + try { + wrows[0].push('test'); + } catch (error) { + expect(error).toStrictEqual(TypeError('Cannot add property 3, object is not extensible')); + } + + try { + wrows[0][0] = 'test'; + } catch (error) { + expect(error).toStrictEqual(TypeError(`Cannot assign to read only property '0' of object '[object Array]'`)); + } + }); + + it('json should return immutable value', () => { + const testSubject = new TestSubject.Parser(); + testSubject.parse('1,2,3\n,b,c'); + + const wrows = (testSubject.json as unknown) as Array>; + expect.assertions(3) + + try { + wrows.push({'test': 'test'}); + } catch (error) { + expect(error).toStrictEqual(TypeError('Cannot add property 1, object is not extensible')); + } + + try { + wrows.push({'test': 'test'}); + } catch (error) { + expect(error).toStrictEqual(TypeError('Cannot add property 1, object is not extensible')); + } + + try { + wrows[0]['1'] = 'test'; + } catch (error) { + expect(error).toStrictEqual(TypeError(`Cannot assign to read only property '1' of object '#'`)); + } + }); + }); }); diff --git a/src/index.ts b/src/index.ts index b14e99c..3109dfd 100644 --- a/src/index.ts +++ b/src/index.ts @@ -107,10 +107,10 @@ const ParseError = (line: number, column: number) => * import Parser from '@gregoranders/csv'; * * const parser = new Parser(); - * const rows = parser.parse('a,b,c\n1,2,3'); - * - * console.log(rows); + * const rows = parser.parse('a,b,c\n1,2,3\n4,5,6'); * ``` + * + * @typeParam T - the type returned by {@link Parser#json} * @public */ export class Parser> { @@ -148,6 +148,7 @@ export class Parser> { * @returns an array of {@link Row}s * * @throws Error on parse error + * @readonly */ public parse(text: string): readonly Row[] { this._rows = []; @@ -175,22 +176,33 @@ export class Parser> { throw ParseError(this._quoteState.line, this._quoteState.lineOffset); } - return this.rows; + this.rows.forEach((row) => { + row.forEach((value) => Object.freeze(value)) + Object.freeze(row); + }); + + Object.freeze(this._rows); + + return this._rows; } /** * returns rows * * @returns an array of {@link Row}s + * @readonly + * @virtual */ public get rows(): readonly Row[] { - return Object.freeze(this._rows); + return this._rows; } /** * returns rows as JSON using the first row as property name provider * * @returns an array of {@link Row}s as JSON + * @readonly + * @virtual */ public get json(): readonly T[] { if (this.rows.length) { @@ -213,7 +225,7 @@ export class Parser> { ); } - return []; + return Object.freeze([]); } private handleNext() { From b4f4ae256b29fd27ec3e8e60c2f97d0c1607d17a Mon Sep 17 00:00:00 2001 From: Gregor Anders Date: Sat, 20 Jun 2020 13:24:10 +0200 Subject: [PATCH 16/23] chore(release): bump version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 656df48..1d89c17 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@gregoranders/csv", - "version": "0.0.3", + "version": "0.0.4", "description": "Simple CSV parser in TypeScript", "scripts": { "clear": "npm run prescript && npm run pretest && rimraf ./node_modules ./package-lock.json ./temp", From e08b309d26726a0665a16368d6f903d3a935fce0 Mon Sep 17 00:00:00 2001 From: Gregor Anders Date: Sat, 20 Jun 2020 13:30:28 +0200 Subject: [PATCH 17/23] docs(README): update docs --- README.md | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 075b778..f77ff4f 100644 --- a/README.md +++ b/README.md @@ -31,7 +31,7 @@ ## Example ```sh -npm install --save-dev @gregoranders/csv +npm install @gregoranders/csv ``` ```ts @@ -39,7 +39,8 @@ import Parser from '@gregoranders/csv'; const parser = new Parser(); const rows = parser.parse('a,b,c\n1,2,3\n4,5,6'); - +``` +```ts console.log(JSON.stringify(rows, null, 2)); [ @@ -59,7 +60,8 @@ console.log(JSON.stringify(rows, null, 2)); "6" ] ] - +``` +```ts console.log(JSON.stringify(parser.rows, null, 2)); [ @@ -79,7 +81,8 @@ console.log(JSON.stringify(parser.rows, null, 2)); "6" ] ] - +``` +```ts console.log(JSON.stringify(parser.json, null, 2)); [ From a0a78fa6b4e29519f8c1a25b24afed9d6f9c9c4d Mon Sep 17 00:00:00 2001 From: Gregor Anders Date: Sat, 20 Jun 2020 13:32:06 +0200 Subject: [PATCH 18/23] chore(SECURITY): update update SECURITY to reflect upcoming release --- SECURITY.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/SECURITY.md b/SECURITY.md index bdd9c98..e5cc41f 100644 --- a/SECURITY.md +++ b/SECURITY.md @@ -5,7 +5,8 @@ ​ | Version | Supported | | ------- | ------------------ | -| 0.0.3 | :white_check_mark: | +| 0.0.4 | :white_check_mark: | +| 0.0.3 | :x: | | 0.0.2 | :x: | | 0.0.1 | :x: | ​ From d1dae6621ab25a93850aaa8ebbaeba1417f107fd Mon Sep 17 00:00:00 2001 From: Gregor Anders Date: Sat, 20 Jun 2020 13:33:14 +0200 Subject: [PATCH 19/23] chore(release): update lib version in code --- src/index.spec.ts | 2 +- src/index.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/index.spec.ts b/src/index.spec.ts index 634f0fb..d1255be 100644 --- a/src/index.spec.ts +++ b/src/index.spec.ts @@ -17,7 +17,7 @@ describe(`${TestSubject.libname} ${TestSubject.libversion} - csv`, () => { }); it('libversion', () => { - expect(TestSubject.libversion).toBe('0.0.3'); + expect(TestSubject.libversion).toBe('0.0.4'); }); it('liburl', () => { diff --git a/src/index.ts b/src/index.ts index 3109dfd..83fb2d0 100644 --- a/src/index.ts +++ b/src/index.ts @@ -18,7 +18,7 @@ export const libname = '@gregoranders/csv'; * @public * @readonly */ -export const libversion = '0.0.3'; +export const libversion = '0.0.4'; /** * library homepage From ef535a3596d3cc21f7bca61fea741d7adcbdf2f6 Mon Sep 17 00:00:00 2001 From: Gregor Anders Date: Sat, 20 Jun 2020 13:33:46 +0200 Subject: [PATCH 20/23] docs(api): update api docs --- docs/csv.libversion.md | 2 +- etc/csv.api.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/csv.libversion.md b/docs/csv.libversion.md index 6d3da00..4bccf8c 100644 --- a/docs/csv.libversion.md +++ b/docs/csv.libversion.md @@ -9,5 +9,5 @@ library version Signature: ```typescript -libversion = "0.0.3" +libversion = "0.0.4" ``` diff --git a/etc/csv.api.md b/etc/csv.api.md index ea8d81a..f54971c 100644 --- a/etc/csv.api.md +++ b/etc/csv.api.md @@ -21,7 +21,7 @@ export const libname = "@gregoranders/csv"; export const liburl = "https://gregoranders.github.io/ts-csv/"; // @public -export const libversion = "0.0.3"; +export const libversion = "0.0.4"; // @public class Parser> { From 1be6a3cbbe5d21cf9a297ad01e45d97e6c7be75d Mon Sep 17 00:00:00 2001 From: Gregor Anders Date: Sat, 20 Jun 2020 13:34:43 +0200 Subject: [PATCH 21/23] docs(CHANGELOG): update changelog --- CHANGELOG.md | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index b9df711..d39516c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,45 @@ +#### 0.0.4 (2020-06-20) + +##### Build System / Dependencies + +* **release:** add release workflow ([0e68a0e4](https://github.com/gregoranders/ts-csv/commit/0e68a0e4da12f3ae86cd1b225b2517325d98f9c8)) + +##### Chores + +* **release:** + * update lib version in code ([d1dae662](https://github.com/gregoranders/ts-csv/commit/d1dae6621ab25a93850aaa8ebbaeba1417f107fd)) + * bump version ([b4f4ae25](https://github.com/gregoranders/ts-csv/commit/b4f4ae256b29fd27ec3e8e60c2f97d0c1607d17a)) + * remove file ([dfb954df](https://github.com/gregoranders/ts-csv/commit/dfb954df74bb4ef7c84a2795a67d972a2dd17719)) +* **SECURITY:** update ([a0a78fa6](https://github.com/gregoranders/ts-csv/commit/a0a78fa6b4e29519f8c1a25b24afed9d6f9c9c4d)) +* **npm:** remove .npmignore ([9742113e](https://github.com/gregoranders/ts-csv/commit/9742113ecb8136a1d3cbd34360043c915cb2ce05)) +* **package:** remove tasks ([72c5be24](https://github.com/gregoranders/ts-csv/commit/72c5be2458f963b037e54d1a1ffcd6f0a7cdfc31)) +* **eslint:** move config ([9ec51457](https://github.com/gregoranders/ts-csv/commit/9ec51457a62f9eaefd6d889026f57973fef771e3)) + +##### Documentation Changes + +* **api:** update api docs ([ef535a35](https://github.com/gregoranders/ts-csv/commit/ef535a3596d3cc21f7bca61fea741d7adcbdf2f6)) +* **README:** update docs ([e08b309d](https://github.com/gregoranders/ts-csv/commit/e08b309d26726a0665a16368d6f903d3a935fce0)) + +##### Bug Fixes + +* **tsconfig:** remove DOM ([1773dc79](https://github.com/gregoranders/ts-csv/commit/1773dc798ac9c1f8481514a7f6608b2146753596)) + +##### Other Changes + +* gregoranders/ts-csv into development ([9143c2c3](https://github.com/gregoranders/ts-csv/commit/9143c2c3c9eaf04ff49a725d5e87ed451fef8b9f)) +* bump lint-staged from 10.2.10 to 10.2.11 ([fbd4d5a8](https://github.com/gregoranders/ts-csv/commit/fbd4d5a8e8c7ae044870f47822a73ddc3b6d74b0)) +* bump jest-spec-reporter from 1.0.13 to 1.0.14 ([dba06913](https://github.com/gregoranders/ts-csv/commit/dba06913af3e0f818ef798058e854e10f8a92e90)) +* bump @microsoft/api-documenter from 7.8.12 to 7.8.13 ([9332c321](https://github.com/gregoranders/ts-csv/commit/9332c3211edde18c78ca88e54943f909ada6007e)) +* bump @typescript-eslint/eslint-plugin from 3.2.0 to 3.3.0 ([c1787f9c](https://github.com/gregoranders/ts-csv/commit/c1787f9cb92661d0fe51660cdaa70b71b2d5114e)) +* bump @typescript-eslint/parser from 3.2.0 to 3.3.0 ([56fd575a](https://github.com/gregoranders/ts-csv/commit/56fd575a97b2c295be040990c2ee043ef5136557)) +* bump @microsoft/api-extractor from 7.8.11 to 7.8.12 ([460142f1](https://github.com/gregoranders/ts-csv/commit/460142f161d4e48f6c646f70ac9c504f5e1144d6)) +* bump eslint-plugin-prettier from 3.1.3 to 3.1.4 ([55fbd046](https://github.com/gregoranders/ts-csv/commit/55fbd0460cce18c54f731e0f8a672bc9360041ee)) + +##### Refactors + +* **index:** make result immutable ([ae46c5d8](https://github.com/gregoranders/ts-csv/commit/ae46c5d87b0a7336617f624fdb9f086f7efbeba6)) +* **build:** refactor workflows ([07c95115](https://github.com/gregoranders/ts-csv/commit/07c951150201720b79e7bb6b6ba0e742653fe2b4)) + #### 0.0.3 (2020-06-14) ##### Documentation Changes From 99756f37f67d200ca23586c5e767237ab825a143 Mon Sep 17 00:00:00 2001 From: Gregor Anders Date: Sat, 20 Jun 2020 13:56:04 +0200 Subject: [PATCH 22/23] fix(build): fix code quality issue --- src/index.ts | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/index.ts b/src/index.ts index 83fb2d0..d5187b1 100644 --- a/src/index.ts +++ b/src/index.ts @@ -176,12 +176,7 @@ export class Parser> { throw ParseError(this._quoteState.line, this._quoteState.lineOffset); } - this.rows.forEach((row) => { - row.forEach((value) => Object.freeze(value)) - Object.freeze(row); - }); - - Object.freeze(this._rows); + this.makeImmutable(); return this._rows; } @@ -325,6 +320,14 @@ export class Parser> { state.lineOffset = -1; state.appendRow = false; } + + private makeImmutable() { + this.rows.forEach((row) => { + row.forEach((value) => Object.freeze(value)) + Object.freeze(row); + }); + Object.freeze(this._rows); + } } /** From 953842c78fa7b7a47358e8462f1c394cef2f8aeb Mon Sep 17 00:00:00 2001 From: Gregor Anders Date: Sat, 20 Jun 2020 13:57:06 +0200 Subject: [PATCH 23/23] docs(CHANGELOG): update --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index d39516c..4a79946 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,11 +17,13 @@ ##### Documentation Changes +* **CHANGELOG:** update changelog ([1be6a3cb](https://github.com/gregoranders/ts-csv/commit/1be6a3cbbe5d21cf9a297ad01e45d97e6c7be75d)) * **api:** update api docs ([ef535a35](https://github.com/gregoranders/ts-csv/commit/ef535a3596d3cc21f7bca61fea741d7adcbdf2f6)) * **README:** update docs ([e08b309d](https://github.com/gregoranders/ts-csv/commit/e08b309d26726a0665a16368d6f903d3a935fce0)) ##### Bug Fixes +* **build:** fix code quality issue ([99756f37](https://github.com/gregoranders/ts-csv/commit/99756f37f67d200ca23586c5e767237ab825a143)) * **tsconfig:** remove DOM ([1773dc79](https://github.com/gregoranders/ts-csv/commit/1773dc798ac9c1f8481514a7f6608b2146753596)) ##### Other Changes