From ccf792d31e2c8a890f5a45f07368475479ff2606 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philippe=20Rivi=C3=A8re?= Date: Fri, 4 Jun 2021 19:32:39 +0200 Subject: [PATCH] Adopt type=module (#43) * Adopt type=module follow changes in d3-format: * type=module * add exports * remove zip * license: ISC * update dependencies * format links to source * es6 and browser rather than no-undef * remove Sublime project * add eslint.json * update dependencies * tweak eslintrc * typeof test * Update README Co-authored-by: Mike Bostock --- .eslintrc.json | 4 - .github/eslint.json | 18 + .github/workflows/node.js.yml | 30 + LICENSE | 40 +- README.md | 61 +- d3-fetch.sublime-project | 17 - package.json | 49 +- test/.eslintrc.json | 12 + test/export-test.js | 16 + yarn.lock | 1488 ++++++++++++++++++--------------- 10 files changed, 967 insertions(+), 768 deletions(-) create mode 100644 .github/eslint.json create mode 100644 .github/workflows/node.js.yml delete mode 100644 d3-fetch.sublime-project create mode 100644 test/.eslintrc.json create mode 100644 test/export-test.js diff --git a/.eslintrc.json b/.eslintrc.json index 8287875..64f7cac 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -6,10 +6,6 @@ }, "env": { "es6": true, - "node": true, "browser": true - }, - "rules": { - "no-cond-assign": 0 } } diff --git a/.github/eslint.json b/.github/eslint.json new file mode 100644 index 0000000..c280fdb --- /dev/null +++ b/.github/eslint.json @@ -0,0 +1,18 @@ +{ + "problemMatcher": [ + { + "owner": "eslint-compact", + "pattern": [ + { + "regexp": "^(.+):\\sline\\s(\\d+),\\scol\\s(\\d+),\\s(Error|Warning|Info)\\s-\\s(.+)\\s\\((.+)\\)$", + "file": 1, + "line": 2, + "column": 3, + "severity": 4, + "message": 5, + "code": 6 + } + ] + } + ] +} diff --git a/.github/workflows/node.js.yml b/.github/workflows/node.js.yml new file mode 100644 index 0000000..7e5ee59 --- /dev/null +++ b/.github/workflows/node.js.yml @@ -0,0 +1,30 @@ +# https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions + +name: Node.js CI + +on: + push: + branches: [ main ] + pull_request: + branches: [ main ] + +jobs: + build: + + runs-on: ubuntu-latest + + strategy: + matrix: + node-version: [14.x] + + steps: + - uses: actions/checkout@v2 + - name: Use Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v1 + with: + node-version: ${{ matrix.node-version }} + - run: yarn --frozen-lockfile + - run: | + echo ::add-matcher::.github/eslint.json + yarn run eslint src test --format=compact + - run: yarn test diff --git a/LICENSE b/LICENSE index fb54fc9..ff79401 100644 --- a/LICENSE +++ b/LICENSE @@ -1,27 +1,13 @@ -Copyright 2016 Mike Bostock -All rights reserved. - -Redistribution and use in source and binary forms, with or without modification, -are permitted provided that the following conditions are met: - -* Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - -* Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - -* Neither the name of the author nor the names of contributors may be used to - endorse or promote products derived from this software without specific prior - written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR -ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON -ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +Copyright 2016-2021 Mike Bostock + +Permission to use, copy, modify, and/or distribute this software for any purpose +with or without fee is hereby granted, provided that the above copyright notice +and this permission notice appear in all copies. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH +REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND +FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, +INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS +OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER +TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF +THIS SOFTWARE. diff --git a/README.md b/README.md index 36283fb..a9451a1 100644 --- a/README.md +++ b/README.md @@ -3,31 +3,42 @@ This module provides convenient parsing on top of [Fetch](https://fetch.spec.whatwg.org/). For example, to load a text file: ```js -d3.text("/path/to/file.txt").then(function(text) { - console.log(text); // Hello, world! -}); +const text = await d3.text("/path/to/file.txt"); +console.log(text); // Hello, world! ``` To load and parse a CSV file: ```js -d3.csv("/path/to/file.csv").then(function(data) { - console.log(data); // [{"Hello": "world"}, …] -}); +const data = await d3.csv("/path/to/file.csv"); +console.log(data); // [{"Hello": "world"}, …] ``` This module has built-in support for parsing [JSON](#json), [CSV](#csv), and [TSV](#tsv). You can parse additional formats by using [text](#text) directly. (This module replaced [d3-request](https://github.com/d3/d3-request).) ## Installing -If you use NPM, `npm install d3-fetch`. Otherwise, download the [latest release](https://github.com/d3/d3-fetch/releases/latest). You can also load directly from [d3js.org](https://d3js.org) as a [standalone library](https://d3js.org/d3-fetch.v1.min.js). AMD, CommonJS, and vanilla environments are supported. In vanilla, a `d3` global is exported: +If you use npm, `npm install d3-fetch`. You can also download the [latest release on GitHub](https://github.com/d3/d3-fetch/releases/latest). For vanilla HTML in modern browsers, import d3-fetch from Skypack: + +```html + +``` + +For legacy environments, you can load d3-fetch’s UMD bundle from an npm-based CDN such as jsDelivr; a `d3` global is exported: ```html - - +