Skip to content

Commit 85730bb

Browse files
Merge pull request #6 from es-shims/updates
2 parents c3b6231 + 524d34b commit 85730bb

File tree

14 files changed

+120
-28
lines changed

14 files changed

+120
-28
lines changed

.eslintrc

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"root": true,
3+
4+
"extends": "@ljharb",
5+
6+
"rules": {
7+
"id-length": "off",
8+
"new-cap": ["error", {
9+
"capIsNewExceptions": [
10+
"StringCharCodeAt",
11+
"RequireObjectCoercible",
12+
"ToIntegerOrInfinity",
13+
"ToString",
14+
],
15+
}],
16+
"no-magic-numbers": "off",
17+
},
18+
19+
"overrides": [
20+
{
21+
"files": ["tests/**/*"],
22+
"rules": {
23+
"max-lines-per-function": "off",
24+
"max-statements-per-line": "off",
25+
},
26+
},
27+
]
28+
}

.github/workflows/node-aught.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
name: 'Tests: node.js < 10'
2+
3+
on: [pull_request, push]
4+
5+
jobs:
6+
tests:
7+
uses: ljharb/actions/.github/workflows/node.yml@main
8+
with:
9+
range: '< 10'
10+
type: minors
11+
command: npm run tests-only

.github/workflows/node-pretest.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
name: 'Tests: pretest/posttest'
2+
3+
on: [pull_request, push]
4+
5+
jobs:
6+
tests:
7+
uses: ljharb/actions/.github/workflows/pretest.yml@main

.github/workflows/node-tens.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
name: 'Tests: node.js >= 10'
2+
3+
on: [pull_request, push]
4+
5+
jobs:
6+
tests:
7+
uses: ljharb/actions/.github/workflows/node.yml@main
8+
with:
9+
range: '>= 10'
10+
type: minors
11+
command: npm run tests-only

.github/workflows/publish-on-tag.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ jobs:
1010
runs-on: ubuntu-latest
1111
steps:
1212
- name: Checkout
13-
uses: actions/checkout@v2
13+
uses: actions/checkout@v4
1414
- name: Set up Node.js
1515
uses: actions/setup-node@v3
1616
with:

.github/workflows/rebase.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
name: Automatic Rebase
2+
3+
on: [pull_request_target]
4+
5+
jobs:
6+
_:
7+
uses: ljharb/actions/.github/workflows/rebase.yml@main
8+
secrets:
9+
token: ${{ secrets.GITHUB_TOKEN }}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
name: Require “Allow Edits”
2+
3+
on: [pull_request_target]
4+
5+
jobs:
6+
_:
7+
name: "Require “Allow Edits”"
8+
9+
runs-on: ubuntu-latest
10+
11+
steps:
12+
- uses: ljharb/require-allow-edits@main

LICENSE-MIT.txt renamed to LICENSE

File renamed without changes.

auto.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
/*! https://mths.be/codepointat v1.0.0 by @mathias */
22

3+
'use strict';
4+
35
require('./shim')();

implementation.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,17 @@
22

33
'use strict';
44

5-
var callBound = require('es-abstract/helpers/callBound');
6-
var RequireObjectCoercible = require('es-abstract/2019/RequireObjectCoercible');
7-
var ToString = require('es-abstract/2019/ToString');
8-
var ToInteger = require('es-abstract/2019/ToInteger');
5+
var callBound = require('call-bind/callBound');
6+
var RequireObjectCoercible = require('es-abstract/2024/RequireObjectCoercible');
7+
var ToString = require('es-abstract/2024/ToString');
8+
var ToIntegerOrInfinity = require('es-abstract/2024/ToIntegerOrInfinity');
99
var StringCharCodeAt = callBound('String.prototype.charCodeAt');
1010

1111
module.exports = function codePointAt(position) {
1212
var O = RequireObjectCoercible(this);
1313
var string = ToString(O);
1414
var size = string.length;
15-
var index = ToInteger(position);
15+
var index = ToIntegerOrInfinity(position);
1616
// Account for out-of-bounds indices:
1717
if (index < 0 || index >= size) {
1818
return undefined;
@@ -21,13 +21,13 @@ module.exports = function codePointAt(position) {
2121
var first = StringCharCodeAt(string, index);
2222
var second;
2323
if ( // check if it’s the start of a surrogate pair
24-
first >= 0xD800 && first <= 0xDBFF && // high surrogate
25-
size > index + 1 // there is a next code unit
24+
first >= 0xD800 && first <= 0xDBFF // high surrogate
25+
&& size > index + 1 // there is a next code unit
2626
) {
2727
second = StringCharCodeAt(string, index + 1);
2828
if (second >= 0xDC00 && second <= 0xDFFF) { // low surrogate
2929
// https://mathiasbynens.be/notes/javascript-encoding#surrogate-formulae
30-
return (first - 0xD800) * 0x400 + second - 0xDC00 + 0x10000;
30+
return ((first - 0xD800) * 0x400) + second - 0xDC00 + 0x10000;
3131
}
3232
}
3333
return first;

package.json

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
"exports": {
88
".": "./index.js",
99
"./auto": "./auto.js",
10-
"./shim": "./shim.js",
11-
"./getPolyfill": "./getPolyfill.js",
10+
"./polyfill": "./polyfill.js",
1211
"./implementation": "./implementation.js",
12+
"./shim": "./shim.js",
1313
"./package.json": "./package.json"
1414
},
1515
"keywords": [
@@ -30,20 +30,32 @@
3030
},
3131
"bugs": "https://github.com/mathiasbynens/String.prototype.codePointAt/issues",
3232
"scripts": {
33-
"pretest": "es-shim-api --bound",
33+
"lint": "eslint --ext=js,mjs .",
34+
"postlint": "es-shim-api --bound",
35+
"pretest": "npm run lint",
3436
"test": "npm run tests-only",
3537
"tests-only": "tape 'tests/*.js'",
36-
"cover": "istanbul cover --report html --verbose --dir coverage tape 'tests/*.js'"
38+
"posttest": "npx npm@'>=10.2' audit --production"
3739
},
3840
"dependencies": {
39-
"es-abstract": "^1.17.5"
41+
"call-bind": "^1.0.7",
42+
"es-abstract": "^1.23.3"
4043
},
4144
"devDependencies": {
42-
"@es-shims/api": "^2.1.2",
43-
"define-properties": "^1.1.3",
44-
"function-bind": "^1.1.1",
45-
"functions-have-names": "^1.2.1",
45+
"@es-shims/api": "^2.5.1",
46+
"@ljharb/eslint-config": "^21.1.1",
47+
"define-properties": "^1.2.1",
48+
"eslint": "=8.8.0",
49+
"function-bind": "^1.1.2",
50+
"functions-have-names": "^1.2.3",
51+
"has-strict-mode": "^1.0.1",
4652
"istanbul": "^0.4.5",
47-
"tape": "^5.0.0"
53+
"tape": "^5.9.0"
54+
},
55+
"directories": {
56+
"test": "tests"
57+
},
58+
"engines": {
59+
"node": ">= 0.4"
4860
}
4961
}

shim.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@ module.exports = function shimCodePointAt() {
1414
}
1515

1616
return polyfill;
17-
}
17+
};

tests/shimmed.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ codePointAt.shim();
55

66
var test = require('tape');
77
var defineProperties = require('define-properties');
8-
var bind = require('function-bind');
8+
var callBind = require('call-bind');
99
var isEnumerable = Object.prototype.propertyIsEnumerable;
1010
var functionsHaveNames = require('functions-have-names')();
1111

@@ -24,7 +24,7 @@ test('shimmed', function (t) {
2424
et.end();
2525
});
2626

27-
runTests(bind.call(Function.call, String.prototype.codePointAt), t);
27+
runTests(callBind(String.prototype.codePointAt), t);
2828

2929
t.end();
3030
});

tests/tests.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
'use strict';
22

3-
module.exports = function (codePointAt, t) {
3+
var supportsStrictMode = require('has-strict-mode')();
4+
5+
module.exports = function (codePointAt, t) {
46
t.test('String that starts with a BMP symbol', function (st) {
57
st.equal(codePointAt('abc\uD834\uDF06def', -1), undefined);
68
st.equal(codePointAt('abc\uD834\uDF06def', -0), 0x61);
@@ -82,21 +84,19 @@ module.exports = function (codePointAt, t) {
8284
st.end();
8385
});
8486

85-
var supportsStrictMode = (function () { return typeof this === 'undefined'; }());
86-
8787
t.test('bad string/this value', { skip: !supportsStrictMode }, function (st) {
8888
st['throws'](function () { return codePointAt(undefined, 'a'); }, TypeError, 'undefined is not an object');
8989
st['throws'](function () { return codePointAt(null, 'a'); }, TypeError, 'null is not an object');
9090
st.end();
9191
});
92-
92+
9393
t.test('cast this value', function (st) {
9494
st.equal(codePointAt(42, 0), 0x34);
9595
st.equal(codePointAt(42, 1), 0x32);
96-
st.equal(codePointAt({ 'toString': function() { return 'abc'; } }, 2), 0x63);
96+
st.equal(codePointAt({ toString: function () { return 'abc'; } }, 2), 0x63);
9797

9898
var tmp = 0;
99-
st.equal(codePointAt({ 'toString': function() { ++tmp; return String(tmp); } }, 0), 0x31);
99+
st.equal(codePointAt({ toString: function () { tmp += 1; return String(tmp); } }, 0), 0x31);
100100
st.equal(tmp, 1);
101101

102102
st.end();

0 commit comments

Comments
 (0)