splace
v1.0.2
Published
Split and replace string
Downloads
9
Maintainers
Readme
splace
Split and replace string:
splace(string, replace[, excludeEmpty])
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 string with non-string values:
splace('1 + 1 = 2', { 1: {}, 2: [] });
// [{}, ' + ', {}, ' = ', []]
Empty strings are removed by default. To keep empty strings:
splace('foo', { foo: 'bar' }, false);
// ['', 'bar', '']
Release
Release is automated with Release Please.