Socket
Socket
Sign inDemoInstall

string.fromcodepoint

Package Overview
Dependencies
Maintainers
2
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

string.fromcodepoint - npm Package Compare versions

Comparing version 1.0.0 to 1.0.1

.eslintrc

2

auto.js
/*! https://mths.be/fromcodepoint v1.0.0 by @mathias */
'use strict';
require('./shim')();

31

implementation.js

@@ -5,11 +5,14 @@ /*! https://mths.be/fromcodepoint v1.0.0 by @mathias */

var ToNumber = require('es-abstract/2019/ToNumber');
var IsInteger = require('es-abstract/2019/IsInteger');
var callBound = require('es-abstract/helpers/callBound');
var callBind = require('es-abstract/helpers/callBind');
var GetIntrinsic = require('es-abstract/GetIntrinsic');
var IsIntegralNumber = require('es-abstract/2022/IsIntegralNumber');
var ToNumber = require('es-abstract/2022/ToNumber');
var ArrayPush = callBound('Array.prototype.push');
var StringFromCharCodeSpread = callBind.apply(String.fromCharCode, null);
var callBound = require('call-bind/callBound');
var callBind = require('call-bind');
var GetIntrinsic = require('get-intrinsic');
var $RangeError = GetIntrinsic('%RangeError%');
var $push = callBound('Array.prototype.push');
var $fromCharCodeSpread = callBind.apply(GetIntrinsic('%String.fromCharCode%'), null);
// eslint-disable-next-line no-unused-vars
module.exports = function fromCodePoint(_ /* fromCodePoint.length is 1 */) {

@@ -29,9 +32,9 @@ var MAX_SIZE = 0x4000;

if (
!IsInteger(codePoint) ||
codePoint < 0 || codePoint > 0x10FFFF // not a valid Unicode code point
!IsIntegralNumber(codePoint)
|| codePoint < 0 || codePoint > 0x10FFFF // not a valid Unicode code point
) {
throw RangeError('Invalid code point: ' + codePoint);
throw new $RangeError('Invalid code point: ' + codePoint);
}
if (codePoint <= 0xFFFF) { // BMP code point
ArrayPush(codeUnits, codePoint);
$push(codeUnits, codePoint);
} else { // Astral code point; split in surrogate halves

@@ -42,6 +45,6 @@ // https://mathiasbynens.be/notes/javascript-encoding#surrogate-formulae

lowSurrogate = (codePoint % 0x400) + 0xDC00;
ArrayPush(codeUnits, highSurrogate, lowSurrogate);
$push(codeUnits, highSurrogate, lowSurrogate);
}
if (index + 1 == length || codeUnits.length > MAX_SIZE) {
result += StringFromCharCodeSpread(codeUnits);
if (index + 1 === length || codeUnits.length > MAX_SIZE) {
result += $fromCharCodeSpread(codeUnits);
codeUnits.length = 0;

@@ -48,0 +51,0 @@ }

@@ -5,3 +5,3 @@ /*! https://mths.be/fromcodepoint v1.0.0 by @mathias */

var callBind = require('es-abstract/helpers/callBind');
var callBind = require('call-bind');
var define = require('define-properties');

@@ -8,0 +8,0 @@

{
"name": "string.fromcodepoint",
"version": "1.0.0",
"version": "1.0.1",
"description": "A robust & optimized `String.fromCodePoint` polyfill, based on the ECMAScript 6 specification.",

@@ -10,5 +10,5 @@ "homepage": "https://mths.be/fromcodepoint",

"./auto": "./auto.js",
"./polyfill": "./polyfill.js",
"./implementation": "./implementation.js",
"./shim": "./shim.js",
"./getPolyfill": "./getPolyfill.js",
"./implementation": "./implementation.js",
"./package.json": "./package.json"

@@ -34,18 +34,42 @@ },

"scripts": {
"pretest": "es-shim-api --bound",
"prepack": "npmignore --auto --commentLines=autogenerated",
"lint": "eslint --ext=js,mjs .",
"postlint": "es-shim-api --bound",
"pretest": "npm run lint",
"test": "npm run tests-only",
"tests-only": "tape 'tests/*.js'",
"cover": "istanbul cover --report html --verbose --dir coverage tape 'tests/*.js'"
"tests-only": "nyc tape 'tests/*.js'",
"posttest": "aud --production",
"version": "auto-changelog && git add CHANGELOG.md",
"postversion": "auto-changelog && git add CHANGELOG.md && git commit --no-edit --amend && git tag -f \"v$(node -e \"console.log(require('./package.json').version)\")\""
},
"dependencies": {
"define-properties": "^1.1.3",
"es-abstract": "^1.17.5"
"call-bind": "^1.0.2",
"define-properties": "^1.2.0",
"es-abstract": "^1.21.2",
"get-intrinsic": "^1.2.0"
},
"devDependencies": {
"@es-shims/api": "^2.1.2",
"function-bind": "^1.1.1",
"functions-have-names": "^1.2.1",
"istanbul": "^0.4.5",
"tape": "^5.0.0"
"@es-shims/api": "^2.4.0",
"@ljharb/eslint-config": "^21.0.1",
"aud": "^2.0.2",
"auto-changelog": "^2.4.0",
"eslint": "=8.8.0",
"functions-have-names": "^1.2.3",
"npmignore": "^0.3.0",
"nyc": "^10.3.2",
"tape": "^5.6.3"
},
"auto-changelog": {
"output": "CHANGELOG.md",
"template": "keepachangelog",
"unreleased": false,
"commitLimit": false,
"backfillLimit": false,
"hideCredit": true
},
"publishConfig": {
"ignore": [
".github/workflows"
]
}
}

@@ -1,2 +0,2 @@

# ES6 `String.fromCodePoint` polyfill [![Build status](https://travis-ci.org/mathiasbynens/String.fromCodePoint.svg?branch=master)](https://travis-ci.org/mathiasbynens/String.fromCodePoint) [![Code coverage status](http://img.shields.io/coveralls/mathiasbynens/String.fromCodePoint/master.svg)](https://coveralls.io/r/mathiasbynens/String.fromCodePoint)
# ES6 `String.fromCodePoint` polyfill [![string.fromcodepoint on npm](https://img.shields.io/npm/v/string.fromcodepoint)](https://www.npmjs.com/package/string.fromcodepoint)

@@ -44,2 +44,24 @@ An robust & optimized polyfill for [the `String.fromCodePoint` method in ECMAScript 6](http://people.mozilla.org/~jorendorff/es6-draft.html#sec-string.fromcodepoint).

## For maintainers
### How to publish a new release
1. On the `main` branch, bump the version number in `package.json`:
```sh
npm version patch
```
Instead of `patch`, use `minor` or `major` [as needed](https://semver.org/).
Note that this produces a Git commit + tag.
1. Push the release commit and tag:
```sh
git push && git push --tags
```
Our CI then automatically publishes the new release to npm.
## Author

@@ -46,0 +68,0 @@

'use strict';
var includes = require('../');
var index = require('../');
var test = require('tape');

@@ -9,5 +9,5 @@

test('as a function', function (t) {
runTests(includes, t);
runTests(index, t);
t.end();
});
'use strict';
var fromCodePoint = require('../');
fromCodePoint.shim();
require('../auto');
var test = require('tape');
var defineProperties = require('define-properties');
var bind = require('function-bind');
var isEnumerable = Object.prototype.propertyIsEnumerable;

@@ -10,0 +8,0 @@ var functionsHaveNames = require('functions-have-names')();

'use strict';
module.exports = function(fromCodePoint, t) {
module.exports = function (fromCodePoint, t) {
t.equal(fromCodePoint(), '', 'no arguments');
t.test('cast to 0', function(st) {
t.test('cast to 0', function (st) {
st.equal(fromCodePoint(''), '\0');

@@ -15,3 +15,3 @@ st.equal(fromCodePoint(-0), '\0');

t.test('astral code points', function(st) {
t.test('astral code points', function (st) {
st.equal(fromCodePoint(0x1D306), '\uD834\uDF06');

@@ -23,22 +23,22 @@ st.equal(fromCodePoint(0x1D306, 0x61, 0x1D307), '\uD834\uDF06a\uD834\uDF07');

t.test('invalid code poits', function(st) {
st['throws'](function() { fromCodePoint('_'); }, RangeError);
st['throws'](function() { fromCodePoint('+Infinity'); }, RangeError);
st['throws'](function() { fromCodePoint('-Infinity'); }, RangeError);
st['throws'](function() { fromCodePoint(-1); }, RangeError);
st['throws'](function() { fromCodePoint(0x10FFFF + 1); }, RangeError);
st['throws'](function() { fromCodePoint(3.14); }, RangeError);
st['throws'](function() { fromCodePoint(3e-2); }, RangeError);
st['throws'](function() { fromCodePoint(-Infinity); }, RangeError);
st['throws'](function() { fromCodePoint(+Infinity); }, RangeError);
st['throws'](function() { fromCodePoint(NaN); }, RangeError);
st['throws'](function() { fromCodePoint(undefined); }, RangeError);
st['throws'](function() { fromCodePoint({}); }, RangeError);
st['throws'](function() { fromCodePoint(/./); }, RangeError);
t.test('invalid code points', function (st) {
st['throws'](function () { fromCodePoint('_'); }, RangeError);
st['throws'](function () { fromCodePoint('+Infinity'); }, RangeError);
st['throws'](function () { fromCodePoint('-Infinity'); }, RangeError);
st['throws'](function () { fromCodePoint(-1); }, RangeError);
st['throws'](function () { fromCodePoint(0x10FFFF + 1); }, RangeError);
st['throws'](function () { fromCodePoint(3.14); }, RangeError);
st['throws'](function () { fromCodePoint(3e-2); }, RangeError);
st['throws'](function () { fromCodePoint(-Infinity); }, RangeError);
st['throws'](function () { fromCodePoint(Number(Infinity)); }, RangeError);
st['throws'](function () { fromCodePoint(NaN); }, RangeError);
st['throws'](function () { fromCodePoint(undefined); }, RangeError);
st['throws'](function () { fromCodePoint({}); }, RangeError);
st['throws'](function () { fromCodePoint(/./); }, RangeError);
st.end();
});
t.test('cast code point', function(st) {
t.test('cast code point', function (st) {
var tmp = 0x60;
st.equal(fromCodePoint({ 'valueOf': function() { ++tmp; return tmp; } }), 'a');
st.equal(fromCodePoint({ valueOf: function () { ++tmp; return tmp; } }), 'a');
st.equal(tmp, 0x61);

@@ -48,3 +48,3 @@ st.end();

t.test('long arguments list', function(st) {
t.test('long arguments list', function (st) {
var counter = Math.pow(2, 15) * 3 / 2;

@@ -57,4 +57,4 @@ var result = [];

var counter = Math.pow(2, 15) * 3 / 2;
var result = [];
counter = Math.pow(2, 15) * 3 / 2;
result = [];
while (--counter >= 0) {

@@ -61,0 +61,0 @@ result.push(0xFFFF + 1); // two code units per symbol

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc