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

1.0.0 • Public • Published

splace

NPM

NPM version build codecov

Split and replace string:

splace(string, replace[, excludeEmpty])

Replit

Quick Start

import { splace } from 'splace';

splace('Hello, world!', { world: 'person' }); // ['Hello, ', 'person', '!']

Installation

NPM:

npm install splace

Yarn:

yarn add splace

Usage

Import with ES modules:

import { splace } from 'splace';

Require with CommonJS:

const { splace } = require('splace');

Split and replace a word:

splace('Hello, world!', { world: 'mate' });
// ['Hello, ', 'mate', '!']

Split and replace words:

splace('Hello, world!', { Hello: "G'day", world: 'mate' });
// ["G'day", ', ', 'mate', '!']

Split and replace based on object order:

splace('How much wood would a woodchuck chuck, if a woodchuck could chuck wood?', {
  woodchuck: 'foo',
  wood: 'bar',
  chuck: 'baz',
}).join('');
// 'How much bar would a foo baz, if a foo could baz bar?'

Split and replace non-string values:

splace('1 + 1 = 2', { 1: {}, 2: [] });
// [{}, ' + ', {}, ' = ', []]

Empty strings are removed from the output by default. To prevent empty strings from being removed:

splace('foo', { foo: 'bar' }, false);
// ['', 'bar', '']

Release

Release is automated with Release Please.

License

MIT

Package Sidebar

Install

npm i splace

Weekly Downloads

0

Version

1.0.0

License

MIT

Unpacked Size

7.88 kB

Total Files

7

Last publish

Collaborators

  • remarkablemark