Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

ranges-apply

codsen308.6kMIT7.0.16TypeScript support: included

Take an array of string index ranges, delete/replace the string according to them

delete, from, many, multiple, ranges, replace, slice, slices, splice, string

readme

ranges-apply

Take an array of string index ranges, delete/replace the string according to them

page on codsen.com page on npm page on github Downloads per month changelog MIT Licence

Install

This package is pure ESM. If you're not ready yet, install an older version of this program, 5.1.0 (npm i ranges-apply@5.1.0).

npm i ranges-apply

Quick Take

import { strict as assert } from "assert";

import { rApply } from "ranges-apply";

const oldString = "The quick brown fox jumps over the lazy dog.";
const ranges = [
  [4, 19, "bad grey wolf"],
  [35, 43, "little Red Riding Hood"],
];
assert.equal(
  rApply(oldString, ranges),
  "The bad grey wolf jumps over the little Red Riding Hood.",
);

Documentation

Please visit codsen.com for a full description of the API.

Contributing

To report bugs or request features or assistance, raise an issue on GitHub.

Licence

MIT License.

Copyright © 2010-2024 Roy Revelt and other contributors.

ok codsen star

changelog

Change Log

All notable changes to this project will be documented in this file. See Conventional Commits for commit guidelines.

7.0.0 (2022-12-01)

BREAKING CHANGES

  • Minimum supported Node version is v14.18; we're dropping v12 support

6.2.0 (2022-08-12)

Features

6.1.0 (2022-04-11)

Features

  • export defaults and version (1107244)

6.0.0 (2021-09-09)

Features

BREAKING CHANGES

  • programs now are in ES Modules and won't work with Common JS require()

5.1.0 (2021-05-24)

Features

  • config file based major bump blacklisting (e15f9bb)

5.0.15 (2021-04-11)

Reverts

  • Revert "chore: setup refresh" (23cf206)

5.0.3 (2021-02-07)

Fixed

  • passed ranges can be null (ed082b8)

5.0.1 (2021-01-28)

Fixed

  • add testStats to npmignore (f3c84e9)

5.0.0 (2021-01-23)

Features

  • rewrite in TS and start using named exports (202b763)

BREAKING CHANGES

  • previously: import rApply from ... - now import { rApply } from ...

4.0.0 (2020-11-28)

Accidental version bump during migration to SourceHut. Sorry about that.

3.2.0 (2020-09-07)

Fixed

Features

  • discard any nulls among ranges (2a09e88)

3.1.5 (2020-04-26)

Fixed

  • harden the eslint rules set and make all tests pass (3b593b4)

3.1.0 (2020-01-26)

Features

  • remove a dependency, speed up the program by 130% (b787194)

2.12.0 (2019-01-20)

  • Various documentation and setup tweaks after we migrated to monorepo
  • Setup refresh: updated dependencies and all config files using automated tools

2.9.0 (2018-12-26)

  • Add 3rd input arg - progressFn (f6735e2)
  • Accept null as second input argument, instead of ranges (0c59484)
  • ranges-merge (sort + merge) is applied by default now to prevent errors on unsorted ranges (35e3c4b)

2.8.0 (2018-11-29)

  • Added third argument, progressFn — it reports progress, feeding natural numbers meaning percentage done to any function that is in the third input argument.
  • Pinned all the throws on all unit tests. "Pinning unit test throws" means we not just assert the fact that function threw, but match the throw's error message too. This gives more assurance:

    1. When there are many cases when an algorithm can throw and generic "function threw" assertion is used, a unit test can anticipate one throw to be thrown but another was thrown. Generic "function threw" assertions would still pass, throw is throw after all. But not pinned throws:
    2. It's easier to sort unit tests this way (order by throw ID) in a test file
    3. It's easier to perfect the unit test coverage when throws can be easier identified.
    4. It's faster to comprehend a number compared to a sentence. "THROW_ID_01" is faster to comprehend than a full title (which can differ from other title by a single word). At the end of the day, being less tired means achieving more.
    const error1 = t.throws(() => {
      repl();
    });
    t.match(error1.message, /THROW_ID_01/);

2.7.0 (2018-10-25)

  • Updated all dependencies
  • Restored coveralls.io reporting
  • Restored unit test linting

2.6.0 (2018-08-29)

  • Now second argument, ranges array, can be null. This means, output of ranges-push classes method.current() can be fed directly into this library without even checking. If it's null, original string will be returned.

2.5.0 (2018-08-16)

  • Now we merge all input ranges using ranges-merge because it's necessary for algorithm and we can't rely on user to always provide merged ranges only.

2.4.0 (2018-08-11)

  • Updated error labels
  • Updated all dependencies
  • Removed AVA ES linting rules and nyc code coverage build steps because we migrated to Babel v.7 and nyc breaks

2.3.0 (2018-06-18)

  • Renamed to ranges-apply and migrated to Bitbucket.

2.2.0 (2018-05-11)

  • Set up Prettier
  • Removed package.lock and .editorconfig
  • Wired Rollup to remove comments from non-dev builds. This means we can now leave the console.logs in the source code — Rollup will remove from production code.
  • Unit tests are pointing at ES modules build, which means that code coverage is correct now, without Babel functions being missed

2.1.0 (2018-02-13)

  • Now accepts a single range as well, not only array of ranges.

2.0.0 (2017-11-02)

  • The main source now is in ES2015 modules with import/export.
  • Implemented Rollup to generate 3 flavours of this package: CommonJS, UMD and ESM module with import/export.

1.4.0 (2017-09-19)

  • 🔧 Switching to ESLint on airbnb-base preset with semicolons-off override. JS Standard is rubbish because it's too relaxed and it's been using half-year-old ESLint. Actually it's even flagged as insecure by BitHound at the moment because of shell.js dependency two levels deep. ESLint itself is fine however.
  • 💥 Removed options, the third input argument. It did nothing and I was expecting to add options, but now I don't want any. I removed the unused code related to options.

1.3.0 (2017-08-30)

  • 🔧 OK, so after replacing ES6 template strings, the lets stopped minification of emailcomb. I came up with idea to transpile the source to /es5/index.js, after publishing it should be available for consumption via require('string-replace-slices-array/es5'). Let's see how it goes.
  • 🔧 I restored all template strings as they were in v1.1.0.
  • 🔧 Tweaked the npm scripts, so ES5 version is generated as a pre-commit step.

1.2.0 (2017-08-29)

  • 🔧 Guys, strange stuff. I was generating a production build of emailcomb and it refused to minify this library because of the first backtick in the ES6 template strings. So, I replaced them with ES5 code. Let's see how it will go.

1.1.0 (2017-08-16)

  • 🔧 Now allowing zeros as values in ranges too. Sorry about that, the integer-checking library was not accepting zeros. Fixed now.

1.0.0 (2017-07-25)

  • First public release