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 new file mode 100644 index 0000000..529fd61 --- /dev/null +++ b/.github/ISSUE_TEMPLATE.md @@ -0,0 +1,34 @@ +Is this a bug? If not consider asking on [StackOverflow][StackOverflow]. + +Does the documentation require improvement? Consider posting a [Feature][Feature] with the the recommended changes. + +# Subject of the issue + +Provide a brief description of your issue. + +## Environment + +- Platform: Node | Browser +- Version: Chrome 50 +- Usage: Load from file | Load from Ajax | Hooks + +## Steps to reproduce + +- step1 +- step2 +- step3 + +## Expected behaviour + +Tell us what should happen + +## Actual behaviour + +Tell us what happens instead + +## References + + - [name](href) + +[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/DISC_TEMPLATE.md b/.github/ISSUE_TEMPLATES/DISC_TEMPLATE.md new file mode 100644 index 0000000..bb2b3d5 --- /dev/null +++ b/.github/ISSUE_TEMPLATES/DISC_TEMPLATE.md @@ -0,0 +1,13 @@ +# Topic + +## What Does this Impact? + +Write a brief description of how this discussion applies to jquery-csv. + +## Notes + +Optionally, compile notes from the discussion here. + +## References + +- [link](href) diff --git a/.github/ISSUE_TEMPLATES/FEAT_TEMPLATE.md b/.github/ISSUE_TEMPLATES/FEAT_TEMPLATE.md new file mode 100644 index 0000000..5b7fae0 --- /dev/null +++ b/.github/ISSUE_TEMPLATES/FEAT_TEMPLATE.md @@ -0,0 +1,25 @@ +# the name of the feature + +A brief description of what the feature aims to accomplish + +## Goals + +- goal +- goal + +## Checklist + +- [ ] Is this tested? +- [ ] Is documentation up-to-date? + +## Details + + + +## References + + - [name](href) + + + +[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 new file mode 100644 index 0000000..46d9c94 --- /dev/null +++ b/.github/ISSUE_TEMPLATES/SPEC_TEMPLATE.md @@ -0,0 +1,21 @@ +# the name of the specification + +A brief description of the specification + +## Goals + +- goal +- goal + +## Milestones + +- [ ] milestone +- [ ] milestone + +## Details + +Add code snippets and/or a more in-depth description of the implementation details + +## References + + - [name](href) diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md new file mode 100644 index 0000000..0e0a5cc --- /dev/null +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -0,0 +1,17 @@ +If this PR applies to an existing spec, link to it and delete the rest. + +## Checklist + +- [ ] Is this API breaking? +- [ ] Is this tested? +- [ ] Is Documentation required? + +*Note: Don't worry about leaving these unchecked. These exist to quickly identify common requirements.* + +## Description + +Post a brief description of the changes. + +## References + +- [name](href) 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 80e5be4..669b769 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ node_modules +package/ .DS_Store - +*.tgz diff --git a/.npmignore b/.npmignore new file mode 100644 index 0000000..34cd610 --- /dev/null +++ b/.npmignore @@ -0,0 +1,9 @@ +.github/ +docs/ +examples/ +package/ +test/ +.git/ +*.tgz +.travis.yml +CONTRIBUTING.md diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index a2a867a..0b69ae7 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,23 +1,41 @@ -## Long-Term Development - -1.0 will be the first long-term stable release. The API will be locked until the next major release. New functionality-breaking and/or backwards incompatible changes will be introduced into the master branch. - -## Short-Term Development - -0.8.0 The first stable release following the migration to GitHub from Google Code. - -* The parser is fully featured and mostly bug free -* The TODO list includes re-vamping of the Documentation & examples -* Tests will be revisited and work will be done to add headless browser testing support. -* NPM support will be added -* Hopefully, Bower support can be transferred over from Mirlord and updated to the latest. - -## How You Can Help - -**Run the test runner:** Just run the **tests** in your particular brand of browser and report any failures. - -**We need performance tests:** Performance tests in javascript would add a lot of value to the project. If that's your forte, don't be shy. - -**Provide feedback:** If you have a good suggestion, a useful use case, or just want to share your experience, don't hesitate to get involved. - -Without your contributions and the contributions of the community, this would be just another half-baked CSV to add to the pile of literally thousands of broken/incomplete implementations. The quality of projects like these is a direct result of a greater community that is willing to suggest improvements and test the code. \ No newline at end of file +# 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 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 + +## Code Contributions + +- If you'd like to add a new example or test, submit a [Specification][Specification] +- If you'd like to propose a new feature, submit a [Feature][Feature] request + +**DO** + +- Follow the [Forking Workflow][Forking Workflow] + 1. Fork the project + 2. Clone your fork + 3. Add a remote pointing to the origin repo + 3. Create a new `feature` branch + 4. Checkout the `feature` branch + 5. Commit your changes + 6. Rebase your changes onto the latest w/ `git pull --rebase` + 7. Post a PR comparing `origin/master` to the `fork/feature` +- Provide tests where applicable +- Provide documentation updates that apply to the changes +- Follow the current style of the project + +**Don't** + +- Group multiple features into a single PR +- Co-mingle whitespace changes with code changes +- Make superficial changes (ie style/structure) to existing code +- Make API breaking changes unless they're clearly documented in a Specification + +[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&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 24041ec..9e3079b 100644 --- a/README.md +++ b/README.md @@ -1,23 +1,21 @@ -[](https://cdnjs.com/libraries/jquery-csv) -[](https://badge.fury.io/js/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 @@ -40,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 @@ -106,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 @@ -148,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/bower.json b/bower.json deleted file mode 100644 index 09ee35a..0000000 --- a/bower.json +++ /dev/null @@ -1,23 +0,0 @@ -{ - "name": "jquery-csv", - "version": "0.8.1", - "homepage": "https://github.com/evanplaice/jquery-csv", - "authors": [ - "Evan Plaice[description]
+[code]
+ On the adjacent tabs, you will find examples demonstrating the usage of the jQuery-CSV library.
-Samples datasets will be provided with each example but if you want, you may insert your own data. Just press the 'Run' button to re-execute the parser.
-The main project page can be found on Google Code
-If you want the complete documentation. Goto: API Wiki
-If you would like to provide feedback, you may do so on the Feedback Wiki.
-If you find a bug, report a 'Defect' in the Issues section of the project site.
-If you have a suggestion for a new feature, create a 'Feature Request' in the Issues section of the project site.
-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 });
+