包详细信息

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

自述文件

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

更新日志

Changelog

All notable changes to this project will be documented in this file.

The format is based on Keep a Changelog and this project adheres to Semantic Versioning.

v1.0.2 - 2024-03-20

Commits

  • [meta] remove useless ESM 808087d
  • [actions] remove redundant finisher c2b5a5f
  • [Deps] update call-bind, define-properties, es-abstract a197051
  • [Dev Deps] update aud, mock-property, npmignore, tape 00da48c
  • [Refactor] use es-object-atoms where possible ff52ba9
  • [meta] add missing engines.node 88dd84e

v1.0.1 - 2023-08-30

Commits

v1.0.0 - 2022-11-30

Commits

  • Initial implementation, tests, readme 62e3f55
  • Initial commit cd92fd6
  • [Tests] add test cases from test262 6b21eb7
  • [actions] update rebase action to use reusable workflow fb723d7
  • Only apps should have lockfiles fb7377f
  • [Dev Deps] update aud, tape e181cb5
  • [Deps] update es-abstract 04baf93