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

Package detail

string-range-expander

codsen159.4kMIT4.0.17TypeScript support: included

Expands string index ranges within whitespace boundaries until letters are met

expand, expander, indexes, of, outwards, range, string, text, within

readme

string-range-expander

Expands string index ranges within whitespace boundaries until letters are met

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, 2.1.0 (npm i string-range-expander@2.1.0).

npm i string-range-expander

Quick Take

import { strict as assert } from "assert";

import { expander } from "string-range-expander";

// let's say we have picked the "zzzz" index range - [16, 20]
// "something>\n\t    zzzz <here"
//                    |   |
//                  from  to
//
// PS. "\n" and "\t" take up a single character's length

assert.deepEqual(
  expander({
    str: "something>\n\t    zzzz <here",
    from: 16,
    to: 20,
    ifRightSideIncludesThisThenCropTightly: "<",
  }),
  [10, 21],
);

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-2025 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.

4.0.9 (2023-05-13)

Bug Fixes

  • correct opts.ifRightSideIncludesThisCropItToo edge cases (49bd408)

4.0.0 (2022-12-01)

BREAKING CHANGES

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

3.1.0 (2022-08-12)

Features

3.0.13 (2022-04-18)

Fixed

3.0.0 (2021-09-09)

Features

BREAKING CHANGES

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

2.1.0 (2021-05-24)

Features

  • config file based major bump blacklisting (e15f9bb)

2.0.15 (2021-04-11)

Reverts

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

2.0.1 (2021-01-28)

Fixed

  • add testStats to npmignore (f3c84e9)

2.0.0 (2021-01-23)

Features

  • rewrite in TS, start using named exports (ea4ccc3)

BREAKING CHANGES

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

1.12.0 (2020-11-28)

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

1.11.0 (2020-04-18)

Features

  • refactor, remove all dependencies (there was only one) (6e49b8b)

1.10.45 (2019-10-02)

Performance Improvements

  • remove check-types-mini to improve speed by around 500x (5e219a8)

1.10.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

1.6.0 (2018-12-26)

Features

  • improvements to opts.addSingleSpaceToPreventAccidentalConcatenation (8bb929a)
  • opts.addSingleSpaceToPreventAccidentalConcatenation (19b1390)
  • opts.addSingleSpaceToPreventAccidentalConcatenation improvements (47df5be)

1.5.0 (2018-10-26)

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

1.4.0 (2018-09-20)

  • Improvements to opts.addSingleSpaceToPreventAccidentalConcatenation, now it detects is there at least one digit or number around and if there's none, it doesn't add a space.

1.3.0 (2018-09-20)

  • Improvements to cases when opts.ifLeftSideIncludesThisThenCropTightly/opts.ifRightSideIncludesThisThenCropTightly is an array
  • Now we tend an edge case when opts.addSingleSpaceToPreventAccidentalConcatenation is surrounded by characters, whitelisted by opts.ifLeftSideIncludesThisThenCropTightly and opts.ifRightSideIncludesThisThenCropTightly (or just one of them, but then the other is a falsey empty string). In that case, the compensation space is not added.

1.2.0 (2018-09-18)

  • New feature - opts.addSingleSpaceToPreventAccidentalConcatenation. It's off by default but if it's on, it can prevent accidental concatenation of string when chunk is deleted. It checks the outer edges of the string range what is about to be deleted and if non-whitespace surrounds both sides it adds a single space (as range's third argument).

1.0.0 (2018-09-11)

  • First public release