Description
+[description]
++
Usage
+[code]
+ +
Input
+ + ++
diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 2e9e745..0000000 --- a/.gitattributes +++ /dev/null @@ -1,2 +0,0 @@ -# Set default behaviour, in case users don't have core.autocrlf set. -* text=crlf diff --git a/.github/ISSUE_TEMPLATE.md b/.github/ISSUE_TEMPLATE.md index b1d99e5..529fd61 100644 --- a/.github/ISSUE_TEMPLATE.md +++ b/.github/ISSUE_TEMPLATE.md @@ -30,5 +30,5 @@ Tell us what happens instead - [name](href) -[Feature]: https://github.com/evanplaice/jquery-csv/issues/new?template=FEAT_TEMPLATE.md&title=feat()&labels=feature +[Feature]: https://github.com/evanplaice/jquery-csv/issues/new?template=FEAT_TEMPLATE.md&labels=feature [StackOverflow]: https://stackoverflow.com/questions/tagged/jquery-csv?mixed=1 diff --git a/.github/ISSUE_TEMPLATES/FEAT_TEMPLATE.md b/.github/ISSUE_TEMPLATES/FEAT_TEMPLATE.md index e7421e3..5b7fae0 100644 --- a/.github/ISSUE_TEMPLATES/FEAT_TEMPLATE.md +++ b/.github/ISSUE_TEMPLATES/FEAT_TEMPLATE.md @@ -9,23 +9,17 @@ A brief description of what the feature aims to accomplish ## Checklist -- [ ] Is this API breaking? - [ ] Is this tested? -- [ ] Is documentation required? -- [ ] Will you be taking ownership of this change? - -*Note: Don't worry about leaving these unchecked. These exist to quickly identify common requirements.* +- [ ] Is documentation up-to-date? ## Details -Add a loose outline. Don't worry about implementation specifics yet. Feature requests are intended to start a dialog. If this is good to move forward, a specification will be created to outline the implementation details. + ## References - [name](href) -When this feature is ready to move on to implementation, create a [Specification][Specification]. - -*Note: If you're confused and need help getting started, ask lots of questions in the comments. Your contributions are appreciated and your effort is welcome, even if that requires discussing development practices that fall outside the scope of this project.* + -[Specification]: https://github.com/evanplaice/jquery-csv/issues/new?template=SPEC_TEMPLATE.md&title=spec()&labels=specification +[Specification]: https://github.com/evanplaice/jquery-csv/issues/new?template=SPEC_TEMPLATE.md&labels=specification diff --git a/.github/ISSUE_TEMPLATES/SPEC_TEMPLATE.md b/.github/ISSUE_TEMPLATES/SPEC_TEMPLATE.md index ca09c9d..46d9c94 100644 --- a/.github/ISSUE_TEMPLATES/SPEC_TEMPLATE.md +++ b/.github/ISSUE_TEMPLATES/SPEC_TEMPLATE.md @@ -19,5 +19,3 @@ Add code snippets and/or a more in-depth description of the implementation detai ## References - [name](href) - -*Note: If you're confused and need help getting started, ask lots of questions in the comments. Your contributions are appreciated and your effort is welcome, even if that requires discussing development practices that fall outside the scope of this project.* diff --git a/.github/workflows/latest.yml b/.github/workflows/latest.yml new file mode 100644 index 0000000..2cf7f8f --- /dev/null +++ b/.github/workflows/latest.yml @@ -0,0 +1,13 @@ +name: Latest + +on: + push: + branches: + - main + paths-ignore: + - package.json + - package-lock.json + +jobs: + ci: + uses: evanplaice/jquery-csv/.github/workflows/verify.yml@main diff --git a/.github/workflows/npm.yml b/.github/workflows/npm.yml new file mode 100644 index 0000000..b315faf --- /dev/null +++ b/.github/workflows/npm.yml @@ -0,0 +1,24 @@ +name: NPM Release + +on: + workflow_call: + +jobs: + npm: + runs-on: ubuntu-latest + permissions: + contents: read + id-token: write + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Setup + uses: actions/setup-node@v4 + with: + registry-url: "https://registry.npmjs.org" + cache: npm + - run: npm ci + - name: Publish + run: npm publish --provenance --access public + env: + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml new file mode 100644 index 0000000..a05a9b1 --- /dev/null +++ b/.github/workflows/pr.yml @@ -0,0 +1,7 @@ +name: Pull Request + +on: [pull_request] + +jobs: + ci: + uses: evanplaice/jquery-csv/.github/workflows/verify.yml@main diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..82cba53 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,16 @@ +name: Release + +on: + push: + tags: + - v* + +jobs: + ci: + uses: evanplaice/jquery-csv/.github/workflows/verify.yml@main + + cd: + needs: ci + uses: evanplaice/jquery-csv/.github/workflows/npm.yml@main + secrets: inherit + diff --git a/.github/workflows/verify.yml b/.github/workflows/verify.yml new file mode 100644 index 0000000..0b5d99c --- /dev/null +++ b/.github/workflows/verify.yml @@ -0,0 +1,25 @@ +name: Verify + +on: + workflow_call: + +jobs: + verify: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Setup + uses: actions/setup-node@v4 + with: + node-version: 20 + cache: 'npm' + - name: Install + run: npm ci + - name: Lint + run: npm run lint + - name: Test + run: npm t + + # - name: Types + # run: npm run types diff --git a/.gitignore b/.gitignore index 1faf560..669b769 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ node_modules +package/ .DS_Store *.tgz diff --git a/.htmlhint b/.htmlhint deleted file mode 100644 index dcacd47..0000000 --- a/.htmlhint +++ /dev/null @@ -1,16 +0,0 @@ -{ - "tagname-lowercase": true, - "attr-lowercase": true, - "attr-value-double-quotes": true, - "doctype-first": true, - "tag-pair": true, - "spec-char-escape": true, - "id-unique": true, - "src-not-empty": true, - "attr-no-duplication": true, - "title-require": true, - "id-class-value": "dash", - "space-tab-mixed-disabled": "space", - "attr-unsafe-chars": true, - "doctype-html5": true -} diff --git a/.npmignore b/.npmignore index d9324e7..34cd610 100644 --- a/.npmignore +++ b/.npmignore @@ -1,9 +1,9 @@ -.github +.github/ docs/ examples/ +package/ test/ -.gitattributes -.htmlhint +.git/ +*.tgz .travis.yml CONTRIBUTING.md -*.tgz diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 5e2f0ad..0000000 --- a/.travis.yml +++ /dev/null @@ -1,4 +0,0 @@ -language: node_js -node_js: - - "8" - \ No newline at end of file diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index c8cc012..0b69ae7 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,12 +1,9 @@ -If you don't know where to start, take a look at the [Roadmap][Roadmap] of proposed changes for the next release. - # How You Can Help ## Non-code contributions - If you'd like to edit/update the documentation, submit a Pull Request - If you'd like to start a dialog, post a new [Discussion][Discussion] -- If you'd like to mention a project where jquery is used, post a comment in the [Mentions][Mentions] - If you'd like to assist other users of jquery-csv, answer qustions on [StackOverflow][StackOverflow] - If you'd like to promote this project, write articles or blog posts and link back to the project @@ -37,10 +34,8 @@ If you don't know where to start, take a look at the [Roadmap][Roadmap] of propo - Make superficial changes (ie style/structure) to existing code - Make API breaking changes unless they're clearly documented in a Specification -[Roadmap]: https://github.com/evanplaice/jquery-csv/issues/92 -[Discussion]: https://github.com/evanplaice/jquery-csv/issues/new?template=DISC_TEMPLATE.md&title=disc()&labels=discussion -[Mentions]: https://github.com/evanplaice/jquery-csv/issues/97 +[Discussion]: https://github.com/evanplaice/jquery-csv/issues/new?template=DISC_TEMPLATE.md&labels=discussion [StackOverflow]: https://stackoverflow.com/questions/tagged/jquery-csv?mixed=1 -[Feature]: https://github.com/evanplaice/jquery-csv/issues/new?template=FEAT_TEMPLATE.md&title=feat()&labels=feature -[Specification]: https://github.com/evanplaice/jquery-csv/issues/new?template=SPEC_TEMPLATE.md&title=spec()&labels=specification +[Feature]: https://github.com/evanplaice/jquery-csv/issues/new?template=FEAT_TEMPLATE.md&labels=feature +[Specification]: https://github.com/evanplaice/jquery-csv/issues/new?template=SPEC_TEMPLATE.md&labels=specification [Forking Workflow]: https://www.atlassian.com/git/tutorials/comparing-workflows/forking-workflow diff --git a/README.md b/README.md index 0f2c6f6..9e3079b 100644 --- a/README.md +++ b/README.md @@ -1,27 +1,21 @@ -[](https://github.com/evanplaice/jquery-csv/releases) -[](https://www.npmjs.com/package/jquery-csv) -[](https://cdnjs.com/libraries/jquery-csv) -[](https://david-dm.org/evanplaice/jquery-csv?type=dev) -[](https://raw.githubusercontent.com/evanplaice/jquery-csv/master/LICENSE) -[](https://travis-ci.org/evanplaice/jquery-csv) +
✓ NOTICE: For a more modern CSV parser, check out the @VanillaES/CSV project ✓
-*Notice: This is a continuation of the jquery-csv project hosted on Google Code.* + # Introduction -JavaScript is growing up and HTML is finally maturing the point where webapps are being built to completely displace desktop applications. It's about time that the supporting libraries grow up too. +jQuery-csv is an artifact of a simpler time (ie 2012) when the JS library ecosystem was still very underdeveloped. This was the first and still is one of the fastest spec compliant CSV parsers available. -Looking for a complete, end-to-end, battle tested, performance optimized CSV parser that's available in the familiar jQuery syntax style? Welcome... - -This library is a different creature, featuring a slim Chomsky - Type III parser implementation. Full (that means 100%) [IETF RFC 4180](http://tools.ietf.org/html/rfc4180) compliance. Including coverage for a few edge cases that even the spec fails to cover. +This is a complete, customizable, battle tested, performance optimized CSV parser that follows the traditional jQuery-style of syntax. Featuring a slim Chomsky - Type III parser implementation. Full (that means 100%) [IETF RFC 4180](http://tools.ietf.org/html/rfc4180) compliance. Including coverage for a few edge cases that even the spec fails to cover. Enough with the wind-up... -Want to see it in action? Check out the [Basic Usage Demo](http://evanplaice.github.io/jquery-csv/examples/basic-usage.html). - -Want more? The Use Cases section below has what you need. - -Aside: To the script kiddies... Don't be sad, we bet there are still plenty of people who would like to hear you outline the merits of `str.split()`. # Features @@ -44,9 +38,16 @@ Aside: To the script kiddies... Don't be sad, we bet there are still plenty of p ``` **Server-Side** (ie Node.js) - Import via the standard CommonJS approach. + +Install the package via NPM + +```bash +npm i jquery-csv +``` +Then import it as a CommonJS module. + ```javascript -var $ = jQuery = require('jquery'); -require('./jquery.csv.js'); +var csv = require('jquery-csv'); ``` ## Usage @@ -110,19 +111,33 @@ $.csv.fromObjects(objects); # Use Cases -What fun is having a shiny new library without examples to play with? +Instead of the typical useless contrived example code, I have provided a handful of simple yet powerful demos. Not only are they fun to play with but a quick peak at the source will show you how simple and easy they were to implement. Feel free to copy and reuse these in your own projects. -No fun that's what... That is coming from a guy who has spent entirely too much time mucking through API documentation when he'd much rather be out at the beach, surfing, or chasing girls. +## Basic Usage -Instead of the typical useless contrived example code, I have provided a handful of simple yet powerful demos. Not only are they fun to play with but a quick peak at the source will show you how simple and easy they were to implement. +Want to play with the parser and maybe validate your CSV data without all the frills? No need to download the source first, there's a demo for that... -Who knows... maybe this whole 'having fun' concept may spread to some of the other Open Source libraries as a result. One can dream... +[jQuery-CSV - toArray()](http://evanplaice.github.io/jquery-csv/examples/to-array.html) -## Basic Usage +[jQuery-CSV - toArrays()](http://evanplaice.github.io/jquery-csv/examples/to-arrays.html) -Want to play with the parser and maybe validate your CSV data without all the frills? No need to download the source first, there's a demo for that... +[jQuery-CSV - fromArrays()](http://evanplaice.github.io/jquery-csv/examples/from-arrays.html) + +[jQuery-CSV - toObjects()](http://evanplaice.github.io/jquery-csv/examples/to-objects.html) + +[jQuery-CSV - fromObjects()](http://evanplaice.github.io/jquery-csv/examples/from-objects.html) + +## Node.js ESM (EcmaScript Module) Import -[jQuery-CSV - Basic Usage Demonstration](http://evanplaice.github.io/jquery-csv/examples/basic-usage.html) +Here's how to import jQuery-CSV as am ECMAScript module Node.js: + +[jQuery-CSV - ESM Import Demonstration](http://evanplaice.github.io/jquery-csv/examples/snippets/esm-usage.js) + +## Node.js CJS (CommonJS Module) Import + +Here's how to import jQuery-CSV as CommonJS module Node.js: + +[jQuery-CSV - CJS Import Demonstration](http://evanplaice.github.io/jquery-csv/examples/snippets/node-usage.js) ## Client-Side File Handling @@ -152,23 +167,4 @@ Warning: You may experience multiple spontaneous 'oh my got that's soo awesome' [jQuery-CSV - Google Visualization API Demonstration](http://evanplaice.github.io/jquery-csv/examples/google-visualization.html) -## jQuery-CSV + Node.js - -What's better than a powerful JavaScript? platform in the browser. A second, even more powerful JavaScript? platform on the server. - -And... jQuery-CSV fully supports it. There is not online demo because it requires a Node.js server to run but a stub is provided to help get you started. - -Dependencies: - -To make this example work, you'll also need to install jQuery via the NPM. - -```npm install jquery``` - -The link to the stub: - -[node-usage.js](http://evanplaice.github.io/jquery-csv/examples/node-usage.js) - **jQuery-CSV** coding style is inherited from the [JQuery Core Style Guidelines](https://contribute.jquery.org/style-guide/) - -by **Evan Plaice** - diff --git a/docs/hooks-callbacks.md b/docs/hooks-callbacks.md index 1797627..071cf3d 100644 --- a/docs/hooks-callbacks.md +++ b/docs/hooks-callbacks.md @@ -23,7 +23,7 @@ This hook is called before the parser starts processing the dataset. Useful if y ```javascript // strips empty (illegal) lines from the data before parsing -var removeEmptyLines = function(csv) { +var removeEmptyLines = function(csv, state) { var lines = $.csv.splitLines(csv); var output = []; for(var i=0, len=lines.length; i[description]
+[code]
+ On the adjacent tabs, you will find examples demonstrating the usage of the jQuery-CSV library.
-Sample datasets will be provided with each example but if you want, you may insert your own data. Just press the 'Run' button to parse the data
-The main project page can be found on GitHub
-For API specifics. See the API Documentation.
-If you would like to provide feedback, start a Discussion.
-If you find a bug, report an Issue.
-If you have a suggestion for a new feature, create a Feature Request.
-Used to parse a single line of CSV data into an array of values.
-Usage: -
Used to parse multi-line CSV data into a JavaScript 2D (two-dimensional) array.
-Usage: -
Used to convert multi-line CSV data into an array objects containing the data as key-value (ie header:value) pairs.
-Usage: -
Using a custom defined hook to parse dates
+const parseDates = function(value, state) {
+ if (value.match(/(\.|\/|\-)/g)) {
+ const date = new Date(value);
+
+ if (date != 'Invalid Date')
+ return date;
+ }
+
+ return value;
+};
+
+const data = $.csv2Array(csv, { onParseValue: parseDates });
+