deep-substring
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

deep-substring

npm version

A utility function for creating substrings for all values of an object, with optional support for splitting on a given separator.

Installation

Install using npm:

npm install deep-substring -D

Or yarn:

yarn install deep-substring -D

Usage

import { deepSubstring } from 'deep-substring';

deepSubstring('hello', 0, 4);
// => hell

deepSubstring(['hello', 'world'], 1, 4);
// => ['ello', 'orld']

deepSubstring({ hello: { world: 'nested string' } }, 2, 10);
// => { hello: { world: 'sted str' } }

Separators

The separator option can be used to drop any values that would otherwise exceed the start and end index.

import { deepSubstring } from 'deep-substring';

deepSubstring('one,two,three', 0, 10, { separator: ',' });
// => one,two

deepSubstring(['one two', 'three four five'], 0, 10, { separator: ' ' });
// => ['one two', 'three four']

deepSubstring({ hello: { world: ['one|two|three|four'] } }, 2, 15, { separator: '|' });
// => { hello: { world: ['two|three'] } }

Package Sidebar

Install

npm i deep-substring

Weekly Downloads

11

Version

1.0.1

License

ISC

Unpacked Size

7.8 kB

Total Files

7

Last publish

Collaborators

  • alexmendes