Skip to content

Commit ac30873

Browse files
Filmbostock
andauthoredJun 5, 2021
Adopt type=module (#246)
* Adopt type=module follow changes in d3-format: * type=module * add exports * remove zip * license: ISC * update dependencies * add eslint.json * remove Sublime project * related d3/d3#3502; extract copyrights from LICENSE * update dependencies * update homepage * cleaner imports * fix eslintrc * fix tests * Update README * cleaner imports Co-authored-by: Mike Bostock <mbostock@gmail.com>
1 parent 2b7db62 commit ac30873

33 files changed

+3425
-3788
lines changed
 

‎.eslintrc.json

+1-3
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@
55
"ecmaVersion": 8
66
},
77
"env": {
8-
"es6": true,
9-
"node": true,
10-
"browser": true
8+
"es6": true
119
},
1210
"rules": {
1311
"no-cond-assign": 0

‎.github/eslint.json

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"problemMatcher": [
3+
{
4+
"owner": "eslint-compact",
5+
"pattern": [
6+
{
7+
"regexp": "^(.+):\\sline\\s(\\d+),\\scol\\s(\\d+),\\s(Error|Warning|Info)\\s-\\s(.+)\\s\\((.+)\\)$",
8+
"file": 1,
9+
"line": 2,
10+
"column": 3,
11+
"severity": 4,
12+
"message": 5,
13+
"code": 6
14+
}
15+
]
16+
}
17+
]
18+
}

‎.github/workflows/node.js.yml

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions
2+
3+
name: Node.js CI
4+
5+
on:
6+
push:
7+
branches: [ main ]
8+
pull_request:
9+
branches: [ main ]
10+
11+
jobs:
12+
build:
13+
14+
runs-on: ubuntu-latest
15+
16+
strategy:
17+
matrix:
18+
node-version: [14.x]
19+
20+
steps:
21+
- uses: actions/checkout@v2
22+
- name: Use Node.js ${{ matrix.node-version }}
23+
uses: actions/setup-node@v1
24+
with:
25+
node-version: ${{ matrix.node-version }}
26+
- run: yarn --frozen-lockfile
27+
- run: |
28+
echo ::add-matcher::.github/eslint.json
29+
yarn run eslint src test --format=compact
30+
- run: yarn test

‎LICENSE

+13-27
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,13 @@
1-
Copyright 2010-2015 Mike Bostock
2-
All rights reserved.
3-
4-
Redistribution and use in source and binary forms, with or without modification,
5-
are permitted provided that the following conditions are met:
6-
7-
* Redistributions of source code must retain the above copyright notice, this
8-
list of conditions and the following disclaimer.
9-
10-
* Redistributions in binary form must reproduce the above copyright notice,
11-
this list of conditions and the following disclaimer in the documentation
12-
and/or other materials provided with the distribution.
13-
14-
* Neither the name of the author nor the names of contributors may be used to
15-
endorse or promote products derived from this software without specific prior
16-
written permission.
17-
18-
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
19-
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20-
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21-
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
22-
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23-
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24-
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
25-
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26-
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27-
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
1+
Copyright 2010-2021 Mike Bostock
2+
3+
Permission to use, copy, modify, and/or distribute this software for any purpose
4+
with or without fee is hereby granted, provided that the above copyright notice
5+
and this permission notice appear in all copies.
6+
7+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
8+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
9+
FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
10+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
11+
OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
12+
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
13+
THIS SOFTWARE.

‎README.md

+21-9
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,31 @@ For a longer introduction, see these recommended tutorials:
2020

2121
## Installing
2222

23-
If you use NPM, `npm install d3-scale`. Otherwise, download the [latest release](https://github.com/d3/d3-scale/releases/latest). You can also load directly from [d3js.org](https://d3js.org), either as a [standalone library](https://d3js.org/d3-scale.v3.min.js) or as part of [D3](https://github.com/d3/d3). AMD, CommonJS, and vanilla environments are supported. In vanilla, a `d3` global is exported:
23+
If you use npm, `npm install d3-scale`. You can also download the [latest release on GitHub](https://github.com/d3/d3-scale/releases/latest). For vanilla HTML in modern browsers, import d3-scale from Skypack:
2424

2525
```html
26-
<script src="https://d3js.org/d3-array.v2.min.js"></script>
27-
<script src="https://d3js.org/d3-color.v2.min.js"></script>
28-
<script src="https://d3js.org/d3-format.v2.min.js"></script>
29-
<script src="https://d3js.org/d3-interpolate.v2.min.js"></script>
30-
<script src="https://d3js.org/d3-time.v2.min.js"></script>
31-
<script src="https://d3js.org/d3-time-format.v3.min.js"></script>
32-
<script src="https://d3js.org/d3-scale.v3.min.js"></script>
26+
<script type="module">
27+
28+
import {scaleLinear} from "https://cdn.skypack.dev/d3-scale@4";
29+
30+
const x = scaleLinear();
31+
32+
</script>
33+
```
34+
35+
For legacy environments, you can load d3-scale’s UMD bundle from an npm-based CDN such as jsDelivr; a `d3` global is exported:
36+
37+
```html
38+
<script src="https://cdn.jsdelivr.net/npm/d3-array@3"></script>
39+
<script src="https://cdn.jsdelivr.net/npm/d3-color@3"></script>
40+
<script src="https://cdn.jsdelivr.net/npm/d3-format@3"></script>
41+
<script src="https://cdn.jsdelivr.net/npm/d3-interpolate@3"></script>
42+
<script src="https://cdn.jsdelivr.net/npm/d3-time@3"></script>
43+
<script src="https://cdn.jsdelivr.net/npm/d3-time-format@4"></script>
44+
<script src="https://cdn.jsdelivr.net/npm/d3-scale@4"></script>
3345
<script>
3446
35-
var x = d3.scaleLinear();
47+
const x = d3.scaleLinear();
3648
3749
</script>
3850
```

‎d3-scale.sublime-project

-17
This file was deleted.

‎package.json

+31-24
Original file line numberDiff line numberDiff line change
@@ -2,49 +2,56 @@
22
"name": "d3-scale",
33
"version": "3.3.0",
44
"description": "Encodings that map abstract data to visual representation.",
5+
"homepage": "https://d3js.org/d3-scale/",
6+
"repository": {
7+
"type": "git",
8+
"url": "https://github.com/d3/d3-scale.git"
9+
},
510
"keywords": [
611
"d3",
712
"d3-module",
813
"scale",
914
"visualization"
1015
],
11-
"homepage": "https://d3js.org/d3-scale/",
12-
"license": "BSD-3-Clause",
16+
"license": "ISC",
1317
"author": {
1418
"name": "Mike Bostock",
15-
"url": "http://bost.ocks.org/mike"
16-
},
17-
"main": "dist/d3-scale.js",
18-
"unpkg": "dist/d3-scale.min.js",
19-
"jsdelivr": "dist/d3-scale.min.js",
20-
"module": "src/index.js",
21-
"repository": {
22-
"type": "git",
23-
"url": "https://github.com/d3/d3-scale.git"
19+
"url": "https://bost.ocks.org/mike"
2420
},
21+
"type": "module",
2522
"files": [
2623
"dist/**/*.js",
2724
"src/**/*.js"
2825
],
29-
"scripts": {
30-
"pretest": "rollup -c",
31-
"test": "TZ=America/Los_Angeles tape 'test/**/*-test.js' && eslint src",
32-
"prepublishOnly": "rm -rf dist && yarn test",
33-
"postpublish": "git push && git push --tags && cd ../d3.github.com && git pull && cp ../${npm_package_name}/dist/${npm_package_name}.js ${npm_package_name}.v${npm_package_version%%.*}.js && cp ../${npm_package_name}/dist/${npm_package_name}.min.js ${npm_package_name}.v${npm_package_version%%.*}.min.js && git add ${npm_package_name}.v${npm_package_version%%.*}.js ${npm_package_name}.v${npm_package_version%%.*}.min.js && git commit -m \"${npm_package_name} ${npm_package_version}\" && git push && cd - && zip -j dist/${npm_package_name}.zip -- LICENSE README.md dist/${npm_package_name}.js dist/${npm_package_name}.min.js"
26+
"module": "src/index.js",
27+
"main": "src/index.js",
28+
"jsdelivr": "dist/d3-scale.min.js",
29+
"unpkg": "dist/d3-scale.min.js",
30+
"exports": {
31+
"umd": "./dist/d3-scale.min.js",
32+
"default": "./src/index.js"
3433
},
3534
"sideEffects": false,
3635
"dependencies": {
37-
"d3-array": "^2.3.0",
38-
"d3-format": "1 - 2",
39-
"d3-interpolate": "1.2.0 - 2",
40-
"d3-time": "^2.1.1",
41-
"d3-time-format": "2 - 3"
36+
"d3-array": "2.3.0 - 3",
37+
"d3-format": "1 - 3",
38+
"d3-interpolate": "1.2.0 - 3",
39+
"d3-time": "2.1.1 - 3",
40+
"d3-time-format": "2 - 4"
4241
},
4342
"devDependencies": {
44-
"d3-color": "1 - 2",
43+
"d3-color": "1 - 3",
4544
"eslint": "7",
45+
"mocha": "8",
4646
"rollup": "2",
47-
"rollup-plugin-terser": "7",
48-
"tape": "4"
47+
"rollup-plugin-terser": "7"
48+
},
49+
"scripts": {
50+
"test": "TZ=America/Los_Angeles mocha 'test/**/*-test.js' && eslint src test",
51+
"prepublishOnly": "rm -rf dist && yarn test && rollup -c",
52+
"postpublish": "git push && git push --tags && cd ../d3.github.com && git pull && cp ../${npm_package_name}/dist/${npm_package_name}.js ${npm_package_name}.v${npm_package_version%%.*}.js && cp ../${npm_package_name}/dist/${npm_package_name}.min.js ${npm_package_name}.v${npm_package_version%%.*}.min.js && git add ${npm_package_name}.v${npm_package_version%%.*}.js ${npm_package_name}.v${npm_package_version%%.*}.min.js && git commit -m \"${npm_package_name} ${npm_package_version}\" && git push && cd -"
53+
},
54+
"engines": {
55+
"node": ">=12"
4956
}
5057
}

‎rollup.config.js

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
1+
import {readFileSync} from "fs";
12
import {terser} from "rollup-plugin-terser";
23
import * as meta from "./package.json";
34

5+
// Extract copyrights from the LICENSE.
6+
const copyright = readFileSync("./LICENSE", "utf-8")
7+
.split(/\n/g)
8+
.filter(line => /^Copyright\s+/.test(line))
9+
.map(line => line.replace(/^Copyright\s+/, ""))
10+
.join(", ");
11+
412
const config = {
513
input: "src/index.js",
614
external: Object.keys(meta.dependencies || {}).filter(key => /^d3-/.test(key)),
@@ -10,7 +18,7 @@ const config = {
1018
format: "umd",
1119
indent: false,
1220
extend: true,
13-
banner: `// ${meta.homepage} v${meta.version} Copyright ${(new Date).getFullYear()} ${meta.author.name}`,
21+
banner: `// ${meta.homepage} v${meta.version} Copyright ${copyright}`,
1422
globals: Object.assign({}, ...Object.keys(meta.dependencies || {}).filter(key => /^d3-/.test(key)).map(key => ({[key]: "d3"})))
1523
},
1624
plugins: []

‎test/.eslintrc.json

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"extends": "eslint:recommended",
3+
"parserOptions": {
4+
"sourceType": "module",
5+
"ecmaVersion": 8
6+
},
7+
"env": {
8+
"mocha": true
9+
},
10+
"rules": {
11+
"no-sparse-arrays": 0
12+
}
13+
}

‎test/asserts.js

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import assert from "assert";
2+
3+
export function assertInDelta(actual, expected, delta = 1e-6) {
4+
assert(inDelta(actual, expected, delta), `${actual} should be within ${delta} of ${expected}`);
5+
}
6+
7+
function inDelta(actual, expected, delta) {
8+
return (Array.isArray(expected) ? inDeltaArray
9+
: typeof expected === "object" ? inDeltaObject
10+
: inDeltaNumber)(actual, expected, delta);
11+
}
12+
13+
function inDeltaArray(actual, expected, delta) {
14+
let n = expected.length, i = -1;
15+
if (actual.length !== n) return false;
16+
while (++i < n) if (!inDelta(actual[i], expected[i], delta)) return false;
17+
return true;
18+
}
19+
20+
function inDeltaObject(actual, expected, delta) {
21+
for (let i in expected) if (!inDelta(actual[i], expected[i], delta)) return false;
22+
for (let i in actual) if (!(i in expected)) return false;
23+
return true;
24+
}
25+
26+
function inDeltaNumber(actual, expected, delta) {
27+
return actual >= expected - delta && actual <= expected + delta;
28+
}

0 commit comments

Comments
 (0)
Please sign in to comment.