Detalhes do pacote

string-left-right

codsen661.3kMIT6.0.20

Looks up the first non-whitespace character to the left/right of a given index

check, left, look, lookup

readme (leia-me)

string-left-right

Looks up the first non-whitespace character to the left/right of a given index

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, 4.1.0 (npm i string-left-right@4.1.0).

npm i string-left-right

Quick Take

import { strict as assert } from "assert";

import {
  left,
  right,
  leftSeq,
  rightSeq,
  chompLeft,
  chompRight,
  leftStopAtNewLines,
  rightStopAtNewLines,
} from "string-left-right";

// get the closest non-whitespace character to the left of "d" (which itself
// is at string index 6)
const str = "abc   def";
//             |   |
//           012345678

assert.equal(
  `next non-whitespace character to the left of ${str[6]} (index 6) is ${
    str[left(str, 6)]
  } (index ${left(str, 6)})`,
  "next non-whitespace character to the left of d (index 6) is c (index 2)",
);

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 (log de mudanças)

Change Log

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

6.0.0 (2022-12-01)

BREAKING CHANGES

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

5.1.0 (2022-08-12)

Features

5.0.0 (2021-09-09)

Features

BREAKING CHANGES

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

4.1.0 (2021-05-24)

Features

  • config file based major bump blacklisting (e15f9bb)

4.0.15 (2021-04-11)

Reverts

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

4.0.1 (2021-01-28)

Fixed

  • add testStats to npmignore (f3c84e9)

4.0.0 (2021-01-23)

Features

BREAKING CHANGES

  • there should be no breaking changes but we're bumping major just in case...

2.3.0 (2019-09-04)

Features

  • two new methods: rightStopAtNewLines() and leftStopAtNewLines() (cfb7557)

2.2.0 (2019-04-06)

Features

  • Case insensitive opts to seqLeft and seqRight (fafbf19)
  • Hungry chomp (fd07afd)

2.1.5 (2019-03-22)

Fixed

  • Tweak the algorithm and add more unit tests (1008482)
  • Tweak the chompRight algorithm to match two characters repeated vs more (8403566)

2.1.0 (2019-03-17)

Features

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)

  • Added opts.addSingleSpaceToPreventAccidentalConcatenation (19b1390)

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