Détail du package

string.prototype.towellformed

es-shims6.9kMIT1.0.2

An ESnext spec-compliant String.prototype.toWellFormed shim/polyfill/replacement that works as far down as ES3.

javascript, ecmascript, polyfill, shim

readme

string.prototype.towellformed Version Badge

github actions coverage dependency status dev dependency status License Downloads

npm badge

An ESnext spec-compliant String.prototype.toWellFormed shim/polyfill/replacement that works as far down as ES3.

This package implements the es-shim API interface. It works in an ES3-supported environment and complies with the expected ES2024 spec.

Because String.prototype.toWellFormed depends on a receiver (the this value), the main export takes the string to operate on as the first argument.

Getting started

npm install --save string.prototype.towellformed

Usage/Examples

var toWellFormed = require('string.prototype.towellformed');
var assert = require('assert');

var leadingPoo = '\uD83D';
var trailingPoo = '\uDCA9';
var wholePoo = leadingPoo + trailingPoo;

var replacementChar = '\uFFFD';

assert.equal(toWellFormed(wholePoo), wholePoo);
assert.equal(toWellFormed(leadingPoo), replacementChar);
assert.equal(toWellFormed(trailingPoo), replacementChar);
var toWellFormed = require('string.prototype.towellformed');
var assert = require('assert');
/* when String#toWellFormed is not present */
delete String.prototype.toWellFormed;
var shimmed = toWellFormed.shim();

assert.equal(shimmed, toWellFormed.getPolyfill());
assert.deepEqual(wholePoo.toWellFormed(), toWellFormed(wholePoo));
assert.deepEqual(leadingPoo.toWellFormed(), toWellFormed(leadingPoo));
assert.deepEqual(trailingPoo.toWellFormed(), toWellFormed(trailingPoo));
var toWellFormed = require('string.prototype.towellformed');
var assert = require('assert');
/* when String#at is present */
var shimmed = toWellFormed.shim();

assert.equal(shimmed, String.prototype.toWellFormed);
assert.deepEqual(wholePoo.toWellFormed(), toWellFormed(wholePoo));
assert.deepEqual(leadingPoo.toWellFormed(), toWellFormed(leadingPoo));
assert.deepEqual(trailingPoo.toWellFormed(), toWellFormed(trailingPoo));

Tests

Simply clone the repo, npm install, and run npm test