Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

ranges-apply

Package Overview
Dependencies
Maintainers
1
Versions
161
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ranges-apply

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

  • 7.0.12
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
134K
decreased by-18.49%
Maintainers
1
Weekly downloads
 
Created

What is ranges-apply?

The 'ranges-apply' npm package is used to apply multiple string editing operations, defined as ranges, to a given input string. This is particularly useful for tasks that involve multiple, non-overlapping edits to a string, such as text processing, code formatting, or data cleaning.

What are ranges-apply's main functionalities?

Apply Ranges

This feature allows you to apply multiple ranges of edits to a string. Each range is defined by a start index, an end index, and a replacement string. The function processes these ranges and applies the edits to the input string.

const { rApply } = require('ranges-apply');
const input = 'Hello, world!';
const ranges = [
  [7, 12, 'universe'],
  [0, 5, 'Hi']
];
const result = rApply(input, ranges);
console.log(result); // 'Hi, universe!'

Handling Overlapping Ranges

This feature demonstrates how the package handles overlapping ranges. The edits are applied in the order they appear in the array, which can result in overlapping changes being concatenated.

const { rApply } = require('ranges-apply');
const input = 'Hello, world!';
const ranges = [
  [7, 12, 'universe'],
  [10, 15, 'planet']
];
const result = rApply(input, ranges);
console.log(result); // 'Hello, universeplanet!'

Empty Ranges

This feature shows how to insert text at a specific position without removing any existing characters. An empty range (where the start and end indices are the same) allows you to insert text at that position.

const { rApply } = require('ranges-apply');
const input = 'Hello, world!';
const ranges = [
  [7, 7, 'beautiful ']
];
const result = rApply(input, ranges);
console.log(result); // 'Hello, beautiful world!'

Other packages similar to ranges-apply

Keywords

FAQs

Package last updated on 11 Sep 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc