npm install string.prototype.replaceall

Spec-compliant polyfill for String.prototype.replaceAll ESnext proposal

About string.prototype.replaceall

The npm package "string.prototype.replaceall" offers a robust solution for developers needing a spec-compliant polyfill that aligns with the ESnext proposal for String.prototype.replaceAll. This module enhances JavaScript's string manipulation capabilities by allowing developers to seamlessly replace all occurrences of a substring with a new string, without the need for regular expressions or complex looping mechanisms. The utility of this package is crucial for maintaining clean and efficient code, particularly in applications where string data requires standardized formatting or dynamic content replacement across various segments of an application.

To integrate "string.prototype.replaceall" into your project, simply execute the command `npm install string.prototype.replaceall` in your project's root directory. This installation process adds the package to your node_modules folder and updates your project's package.json dependencies, ensuring that your application remains consistent with the latest standards proposed for JavaScript string manipulation. By incorporating this package, developers can avoid the pitfalls of incomplete or incorrect implementations of string replacement functions, leading to more reliable and maintainable codebases.

The "string.prototype.replaceall" module is not only a practical addition to any developer's toolkit but also a testament to the evolving JavaScript ecosystem's commitment to backward compatibility and future readiness. As web and application development grows increasingly complex, having access to tools that simplify and standardize common tasks like string replacement is invaluable. This package ensures that developers can focus on creating innovative features and enhancing user experience, rather than getting bogged down by the intricacies of basic string operations.

More from es-shims

es-shims npm packages

Find the best node modules for your project.

Search npm

regexp.prototype.flags

ES6 spec-compliant RegExp.prototype.flags shim...

Read more
,

string.prototype.trimend

ES2019 spec-compliant String.prototype.trimEnd shim...

Read more
,

string.prototype.trimstart

ES2019 spec-compliant String.prototype.trimStart shim...

Read more
,

arraybuffer.prototype.slice

ES spec-compliant shim for ArrayBuffer.prototype...

Read more
,

string.prototype.matchall

Spec-compliant polyfill for String.prototype...

Read more
,

object.groupby

An ESnext spec-compliant `Object.groupBy` shim/polyfill/replacement that works as far down as ES3...

Read more
,

array.prototype.tosorted

An ESnext spec-compliant `Array.prototype...

Read more
,

es-iterator-helpers

An ESnext spec-compliant iterator helpers shim/polyfill/replacement that works as far down as ES3...

Read more
,

array.prototype.toreversed

An ESnext spec-compliant `Array.prototype...

Read more
,

typedarray.prototype.slice

ES spec-compliant shim for TypedArray.prototype...

Read more
,

string.prototype.replaceall

Spec-compliant polyfill for String.prototype...

Read more
,

error-cause

An ES-spec-compliant shim/polyfill/replacement for the `...

Read more

Dependencies

Core dependencies of this npm package and its dev dependencies.

call-bind, define-properties, es-abstract, es-errors, es-object-atoms, get-intrinsic, has-symbols, is-regex, @es-shims/api, @ljharb/eslint-config, aud, auto-changelog, es5-shim, es6-shim, eslint, evalmd, functions-have-names, in-publish, npmignore, nyc, safe-publish-latest, tape

Documentation

A README file for the string.prototype.replaceall code repository. View Code

string.prototype.replaceall Version Badge

github actions coverage dependency status dev dependency status License Downloads

npm badge

ES Proposal spec-compliant shim for String.prototype.replaceAll. Invoke its "shim" method to shim String.prototype.replaceAll if it is unavailable or noncompliant.

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

Most common usage:

const assert = require('assert');
const replaceAll = require('string.prototype.replaceall');

const str = 'aabc';

// replaceAll and replace are the same, when given a global regex to replace
assert.equal(replaceAll(str, /a/g, 'z'), str.replace(/a/g, 'z'));

// replace, with a string, replaces once
assert.equal(str.replace('a', 'z'), 'zabc');

// replaceAll, with a string, replaces all
assert.equal(replaceAll(str, 'a', 'z'), 'zzbc');

replaceAll.shim(); // will be a no-op if not needed

// replaceAll and replace are the same, when given a global regex to replace
assert.equal(str.replaceAll(/a/g, 'z'), str.replace(/a/g, 'z'));

// replace, with a string, replaces once
assert.equal(str.replace('a', 'z'), 'zabc');

// replaceAll, with a string, replaces all
assert.equal(str.replaceAll('a', 'z'), 'zzbc');

Tests

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