string.prototype.trim

ES5 spec-compliant shim for String.prototype.trim

MIT 16 个版本
安装
npm install string.prototype.trim
yarn add string.prototype.trim
pnpm add string.prototype.trim
bun add string.prototype.trim
README

String.prototype.trim Version Badge

github actions coverage License Downloads

![npm badge][npm-badge-png]

An ES5 spec-compliant String.prototype.trim shim. Invoke its "shim" method to shim String.prototype.trim if it is unavailable.

This package implements the es-shim API interface. It works in an ES3-supported environment and complies with the spec (both ES5 and current).

Most common usage:

var assert = require('assert');
var trim = require('string.prototype.trim');

assert(trim(' \t\na \t\n') === 'a');

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

assert(trim(' \t\na \t\n') === ' \t\na \t\n'.trim());

Engine Bugs

Some implementations of String#trim incorrectly trim zero-width spaces. This shim detects and corrects this behavior.

Tests

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

版本列表
1.2.11 2026-06-05
1.2.10 2024-12-11
1.2.9 2024-03-17
1.2.8 2023-09-07
1.2.7 2022-11-07
1.2.6 2022-04-24
1.2.5 2021-10-04
1.2.4 2021-02-21
1.2.3 2020-11-21
1.2.2 2020-09-15
1.2.1 2019-12-16
1.2.0 2019-07-24
1.1.2 2016-02-06
1.1.1 2015-08-16
1.1.0 2015-08-16
1.0.0 2015-08-09