From 9a1286260f2022631f893d9d76ad088fe87a63b0 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Sun, 6 Oct 2024 10:31:45 +0700 Subject: [PATCH 01/11] [Dev Deps] update `@es-shims/api`, `define-properties`, `function-bind`, `functions-have-names`, `tape` --- package.json | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index 150489e..fc00f02 100644 --- a/package.json +++ b/package.json @@ -39,11 +39,11 @@ "es-abstract": "^1.17.5" }, "devDependencies": { - "@es-shims/api": "^2.1.2", - "define-properties": "^1.1.3", - "function-bind": "^1.1.1", - "functions-have-names": "^1.2.1", + "@es-shims/api": "^2.5.1", + "define-properties": "^1.2.1", + "function-bind": "^1.1.2", + "functions-have-names": "^1.2.3", "istanbul": "^0.4.5", - "tape": "^5.0.0" + "tape": "^5.9.0" } } From 76dea3164c4b56574998519061f507f1853f1e84 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Sun, 6 Oct 2024 10:35:26 +0700 Subject: [PATCH 02/11] [Tests] add `posttest` --- package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/package.json b/package.json index fc00f02..316fbd1 100644 --- a/package.json +++ b/package.json @@ -33,6 +33,7 @@ "pretest": "es-shim-api --bound", "test": "npm run tests-only", "tests-only": "tape 'tests/*.js'", + "posttest": "npx npm@'>=10.2' audit --production", "cover": "istanbul cover --report html --verbose --dir coverage tape 'tests/*.js'" }, "dependencies": { From 955b8e6f9e8e9fe8bcc9230dea16d01dfa6d718c Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Sun, 6 Oct 2024 10:39:10 +0700 Subject: [PATCH 03/11] [Tests] use `has-strict-mode` --- package.json | 1 + tests/tests.js | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 316fbd1..a295bd7 100644 --- a/package.json +++ b/package.json @@ -44,6 +44,7 @@ "define-properties": "^1.2.1", "function-bind": "^1.1.2", "functions-have-names": "^1.2.3", + "has-strict-mode": "^1.0.1", "istanbul": "^0.4.5", "tape": "^5.9.0" } diff --git a/tests/tests.js b/tests/tests.js index 13e1a29..c1edc26 100644 --- a/tests/tests.js +++ b/tests/tests.js @@ -1,5 +1,7 @@ 'use strict'; +var supportsStrictMode = require('has-strict-mode')(); + module.exports = function (codePointAt, t) { t.test('String that starts with a BMP symbol', function (st) { st.equal(codePointAt('abc\uD834\uDF06def', -1), undefined); @@ -82,8 +84,6 @@ module.exports = function (codePointAt, t) { st.end(); }); - var supportsStrictMode = (function () { return typeof this === 'undefined'; }()); - t.test('bad string/this value', { skip: !supportsStrictMode }, function (st) { st['throws'](function () { return codePointAt(undefined, 'a'); }, TypeError, 'undefined is not an object'); st['throws'](function () { return codePointAt(null, 'a'); }, TypeError, 'null is not an object'); From 91a11f8f0885163492deb42da210e92d0cf4c397 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Sun, 6 Oct 2024 10:40:05 +0700 Subject: [PATCH 04/11] [eslint] add linting --- .eslintrc | 28 ++++++++++++++++++++++++++++ auto.js | 2 ++ implementation.js | 6 +++--- package.json | 6 +++++- shim.js | 2 +- tests/tests.js | 8 ++++---- 6 files changed, 43 insertions(+), 9 deletions(-) create mode 100644 .eslintrc diff --git a/.eslintrc b/.eslintrc new file mode 100644 index 0000000..1976abe --- /dev/null +++ b/.eslintrc @@ -0,0 +1,28 @@ +{ + "root": true, + + "extends": "@ljharb", + + "rules": { + "id-length": "off", + "new-cap": ["error", { + "capIsNewExceptions": [ + "StringCharCodeAt", + "RequireObjectCoercible", + "ToInteger", + "ToString", + ], + }], + "no-magic-numbers": "off", + }, + + "overrides": [ + { + "files": ["tests/**/*"], + "rules": { + "max-lines-per-function": "off", + "max-statements-per-line": "off", + }, + }, + ] +} diff --git a/auto.js b/auto.js index bc90109..9b30243 100644 --- a/auto.js +++ b/auto.js @@ -1,3 +1,5 @@ /*! https://mths.be/codepointat v1.0.0 by @mathias */ +'use strict'; + require('./shim')(); diff --git a/implementation.js b/implementation.js index 34f96df..2b0a33d 100644 --- a/implementation.js +++ b/implementation.js @@ -21,13 +21,13 @@ module.exports = function codePointAt(position) { var first = StringCharCodeAt(string, index); var second; if ( // check if it’s the start of a surrogate pair - first >= 0xD800 && first <= 0xDBFF && // high surrogate - size > index + 1 // there is a next code unit + first >= 0xD800 && first <= 0xDBFF // high surrogate + && size > index + 1 // there is a next code unit ) { second = StringCharCodeAt(string, index + 1); if (second >= 0xDC00 && second <= 0xDFFF) { // low surrogate // https://mathiasbynens.be/notes/javascript-encoding#surrogate-formulae - return (first - 0xD800) * 0x400 + second - 0xDC00 + 0x10000; + return ((first - 0xD800) * 0x400) + second - 0xDC00 + 0x10000; } } return first; diff --git a/package.json b/package.json index a295bd7..7dc6454 100644 --- a/package.json +++ b/package.json @@ -30,7 +30,9 @@ }, "bugs": "https://github.com/mathiasbynens/String.prototype.codePointAt/issues", "scripts": { - "pretest": "es-shim-api --bound", + "lint": "eslint --ext=js,mjs .", + "postlint": "es-shim-api --bound", + "pretest": "npm run lint", "test": "npm run tests-only", "tests-only": "tape 'tests/*.js'", "posttest": "npx npm@'>=10.2' audit --production", @@ -41,7 +43,9 @@ }, "devDependencies": { "@es-shims/api": "^2.5.1", + "@ljharb/eslint-config": "^21.1.1", "define-properties": "^1.2.1", + "eslint": "=8.8.0", "function-bind": "^1.1.2", "functions-have-names": "^1.2.3", "has-strict-mode": "^1.0.1", diff --git a/shim.js b/shim.js index c279551..87b69db 100644 --- a/shim.js +++ b/shim.js @@ -14,4 +14,4 @@ module.exports = function shimCodePointAt() { } return polyfill; -} +}; diff --git a/tests/tests.js b/tests/tests.js index c1edc26..80d1dea 100644 --- a/tests/tests.js +++ b/tests/tests.js @@ -2,7 +2,7 @@ var supportsStrictMode = require('has-strict-mode')(); -module.exports = function (codePointAt, t) { +module.exports = function (codePointAt, t) { t.test('String that starts with a BMP symbol', function (st) { st.equal(codePointAt('abc\uD834\uDF06def', -1), undefined); st.equal(codePointAt('abc\uD834\uDF06def', -0), 0x61); @@ -89,14 +89,14 @@ module.exports = function (codePointAt, t) { st['throws'](function () { return codePointAt(null, 'a'); }, TypeError, 'null is not an object'); st.end(); }); - + t.test('cast this value', function (st) { st.equal(codePointAt(42, 0), 0x34); st.equal(codePointAt(42, 1), 0x32); - st.equal(codePointAt({ 'toString': function() { return 'abc'; } }, 2), 0x63); + st.equal(codePointAt({ toString: function () { return 'abc'; } }, 2), 0x63); var tmp = 0; - st.equal(codePointAt({ 'toString': function() { ++tmp; return String(tmp); } }, 0), 0x31); + st.equal(codePointAt({ toString: function () { tmp += 1; return String(tmp); } }, 0), 0x31); st.equal(tmp, 1); st.end(); From 213f7c95d098db81efe99241f320ee0ae9efbd43 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Sun, 6 Oct 2024 10:32:31 +0700 Subject: [PATCH 05/11] [Tests] use `call-bind` instead of `function-bind` --- package.json | 1 + tests/shimmed.js | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 7dc6454..c40c076 100644 --- a/package.json +++ b/package.json @@ -44,6 +44,7 @@ "devDependencies": { "@es-shims/api": "^2.5.1", "@ljharb/eslint-config": "^21.1.1", + "call-bind": "^1.0.7", "define-properties": "^1.2.1", "eslint": "=8.8.0", "function-bind": "^1.1.2", diff --git a/tests/shimmed.js b/tests/shimmed.js index 426fbf7..fffec72 100644 --- a/tests/shimmed.js +++ b/tests/shimmed.js @@ -5,7 +5,7 @@ codePointAt.shim(); var test = require('tape'); var defineProperties = require('define-properties'); -var bind = require('function-bind'); +var callBind = require('call-bind'); var isEnumerable = Object.prototype.propertyIsEnumerable; var functionsHaveNames = require('functions-have-names')(); @@ -24,7 +24,7 @@ test('shimmed', function (t) { et.end(); }); - runTests(bind.call(Function.call, String.prototype.codePointAt), t); + runTests(callBind(String.prototype.codePointAt), t); t.end(); }); From 87558cd968ecbce35b3c08cb33271897aa9ee74c Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Sun, 6 Oct 2024 10:33:21 +0700 Subject: [PATCH 06/11] [Deps] update `es-abstract` --- .eslintrc | 2 +- implementation.js | 10 +++++----- package.json | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/.eslintrc b/.eslintrc index 1976abe..2379838 100644 --- a/.eslintrc +++ b/.eslintrc @@ -9,7 +9,7 @@ "capIsNewExceptions": [ "StringCharCodeAt", "RequireObjectCoercible", - "ToInteger", + "ToIntegerOrInfinity", "ToString", ], }], diff --git a/implementation.js b/implementation.js index 2b0a33d..74d93cf 100644 --- a/implementation.js +++ b/implementation.js @@ -2,17 +2,17 @@ 'use strict'; -var callBound = require('es-abstract/helpers/callBound'); -var RequireObjectCoercible = require('es-abstract/2019/RequireObjectCoercible'); -var ToString = require('es-abstract/2019/ToString'); -var ToInteger = require('es-abstract/2019/ToInteger'); +var callBound = require('call-bind/callBound'); +var RequireObjectCoercible = require('es-abstract/2024/RequireObjectCoercible'); +var ToString = require('es-abstract/2024/ToString'); +var ToIntegerOrInfinity = require('es-abstract/2024/ToIntegerOrInfinity'); var StringCharCodeAt = callBound('String.prototype.charCodeAt'); module.exports = function codePointAt(position) { var O = RequireObjectCoercible(this); var string = ToString(O); var size = string.length; - var index = ToInteger(position); + var index = ToIntegerOrInfinity(position); // Account for out-of-bounds indices: if (index < 0 || index >= size) { return undefined; diff --git a/package.json b/package.json index c40c076..4530c08 100644 --- a/package.json +++ b/package.json @@ -39,12 +39,12 @@ "cover": "istanbul cover --report html --verbose --dir coverage tape 'tests/*.js'" }, "dependencies": { - "es-abstract": "^1.17.5" + "call-bind": "^1.0.7", + "es-abstract": "^1.23.3" }, "devDependencies": { "@es-shims/api": "^2.5.1", "@ljharb/eslint-config": "^21.1.1", - "call-bind": "^1.0.7", "define-properties": "^1.2.1", "eslint": "=8.8.0", "function-bind": "^1.1.2", From 5e5a241e76df541c6105e52b36e17c7282cc37da Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Sun, 6 Oct 2024 10:41:37 +0700 Subject: [PATCH 07/11] [Tests] add actions --- .github/workflows/node-aught.yml | 11 +++++++++++ .github/workflows/node-pretest.yml | 7 +++++++ .github/workflows/node-tens.yml | 11 +++++++++++ .github/workflows/publish-on-tag.yml | 2 +- .github/workflows/rebase.yml | 9 +++++++++ .github/workflows/require-allow-edits.yml | 12 ++++++++++++ package.json | 3 +-- 7 files changed, 52 insertions(+), 3 deletions(-) create mode 100644 .github/workflows/node-aught.yml create mode 100644 .github/workflows/node-pretest.yml create mode 100644 .github/workflows/node-tens.yml create mode 100644 .github/workflows/rebase.yml create mode 100644 .github/workflows/require-allow-edits.yml diff --git a/.github/workflows/node-aught.yml b/.github/workflows/node-aught.yml new file mode 100644 index 0000000..4213896 --- /dev/null +++ b/.github/workflows/node-aught.yml @@ -0,0 +1,11 @@ +name: 'Tests: node.js < 10' + +on: [pull_request, push] + +jobs: + tests: + uses: ljharb/actions/.github/workflows/node.yml@main + with: + range: '< 10' + type: minors + command: npm run tests-only diff --git a/.github/workflows/node-pretest.yml b/.github/workflows/node-pretest.yml new file mode 100644 index 0000000..765edf7 --- /dev/null +++ b/.github/workflows/node-pretest.yml @@ -0,0 +1,7 @@ +name: 'Tests: pretest/posttest' + +on: [pull_request, push] + +jobs: + tests: + uses: ljharb/actions/.github/workflows/pretest.yml@main diff --git a/.github/workflows/node-tens.yml b/.github/workflows/node-tens.yml new file mode 100644 index 0000000..1f55be0 --- /dev/null +++ b/.github/workflows/node-tens.yml @@ -0,0 +1,11 @@ +name: 'Tests: node.js >= 10' + +on: [pull_request, push] + +jobs: + tests: + uses: ljharb/actions/.github/workflows/node.yml@main + with: + range: '>= 10' + type: minors + command: npm run tests-only diff --git a/.github/workflows/publish-on-tag.yml b/.github/workflows/publish-on-tag.yml index ddb8304..f557404 100644 --- a/.github/workflows/publish-on-tag.yml +++ b/.github/workflows/publish-on-tag.yml @@ -10,7 +10,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout - uses: actions/checkout@v2 + uses: actions/checkout@v4 - name: Set up Node.js uses: actions/setup-node@v3 with: diff --git a/.github/workflows/rebase.yml b/.github/workflows/rebase.yml new file mode 100644 index 0000000..b9e1712 --- /dev/null +++ b/.github/workflows/rebase.yml @@ -0,0 +1,9 @@ +name: Automatic Rebase + +on: [pull_request_target] + +jobs: + _: + uses: ljharb/actions/.github/workflows/rebase.yml@main + secrets: + token: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/require-allow-edits.yml b/.github/workflows/require-allow-edits.yml new file mode 100644 index 0000000..7b842f8 --- /dev/null +++ b/.github/workflows/require-allow-edits.yml @@ -0,0 +1,12 @@ +name: Require “Allow Edits” + +on: [pull_request_target] + +jobs: + _: + name: "Require “Allow Edits”" + + runs-on: ubuntu-latest + + steps: + - uses: ljharb/require-allow-edits@main diff --git a/package.json b/package.json index 4530c08..61f535b 100644 --- a/package.json +++ b/package.json @@ -35,8 +35,7 @@ "pretest": "npm run lint", "test": "npm run tests-only", "tests-only": "tape 'tests/*.js'", - "posttest": "npx npm@'>=10.2' audit --production", - "cover": "istanbul cover --report html --verbose --dir coverage tape 'tests/*.js'" + "posttest": "npx npm@'>=10.2' audit --production" }, "dependencies": { "call-bind": "^1.0.7", From cfe9a62daf9a0621a4a51d4b00ddc84433158d74 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Sun, 6 Oct 2024 10:41:56 +0700 Subject: [PATCH 08/11] [meta] rename license to conventional filename --- LICENSE-MIT.txt => LICENSE | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename LICENSE-MIT.txt => LICENSE (100%) diff --git a/LICENSE-MIT.txt b/LICENSE similarity index 100% rename from LICENSE-MIT.txt rename to LICENSE From 0eb6780b3fb8bddff75944174e298a2d5b2fa21f Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Sun, 6 Oct 2024 10:43:42 +0700 Subject: [PATCH 09/11] [meta] add `directories.test` --- package.json | 3 +++ 1 file changed, 3 insertions(+) diff --git a/package.json b/package.json index 61f535b..ccf5e1e 100644 --- a/package.json +++ b/package.json @@ -51,5 +51,8 @@ "has-strict-mode": "^1.0.1", "istanbul": "^0.4.5", "tape": "^5.9.0" + }, + "directories": { + "test": "tests" } } From 2587ded812f2a62046db5c9864c0ee4bcf025a1a Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Sun, 6 Oct 2024 10:48:03 +0700 Subject: [PATCH 10/11] [meta] add missing `engines.node` --- package.json | 3 +++ 1 file changed, 3 insertions(+) diff --git a/package.json b/package.json index ccf5e1e..3532f91 100644 --- a/package.json +++ b/package.json @@ -54,5 +54,8 @@ }, "directories": { "test": "tests" + }, + "engines": { + "node": ">= 0.4" } } From 524d34bdcd5cbf8085706f459329c9e4e8bb3efa Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Sun, 6 Oct 2024 10:34:45 +0700 Subject: [PATCH 11/11] [Fix] add missing `polyfill` endpoint; remove nonexistent `getPolyfill` endpoint Fixes #5 --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 3532f91..34343de 100644 --- a/package.json +++ b/package.json @@ -7,9 +7,9 @@ "exports": { ".": "./index.js", "./auto": "./auto.js", - "./shim": "./shim.js", - "./getPolyfill": "./getPolyfill.js", + "./polyfill": "./polyfill.js", "./implementation": "./implementation.js", + "./shim": "./shim.js", "./package.json": "./package.json" }, "keywords": [