https://github.com/remarkablemark/splace
✂️ Split and replace string
https://github.com/remarkablemark/splace
javascript npm replace split string typescript
Last synced: 3 months ago
JSON representation
✂️ Split and replace string
- Host: GitHub
- URL: https://github.com/remarkablemark/splace
- Owner: remarkablemark
- License: mit
- Created: 2022-12-23T05:20:28.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2024-10-29T20:36:20.000Z (7 months ago)
- Last Synced: 2024-10-29T22:49:43.848Z (7 months ago)
- Topics: javascript, npm, replace, split, string, typescript
- Language: TypeScript
- Homepage: https://npmjs.com/package/splace
- Size: 1.47 MB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
- Codeowners: .github/CODEOWNERS
Awesome Lists containing this project
README
# splace
[](https://nodei.co/npm/splace/)
[](https://www.npmjs.com/package/splace)
[](https://github.com/remarkablemark/splace/actions/workflows/build.yml)
[](https://codecov.io/gh/remarkablemark/splace)Split and replace string:
```
splace(string, replace[, excludeEmpty])
```[Replit](https://replit.com/@remarkablemark/splace)
## Quick Start
```ts
import { splace } from 'splace';splace('Hello, world!', { world: 'person' }); // ['Hello, ', 'person', '!']
```## Installation
[NPM](https://www.npmjs.com/package/splace):
```sh
npm install splace
```[Yarn](https://yarnpkg.com/package/splace):
```sh
yarn add splace
```## Usage
Import with ES modules:
```ts
import { splace } from 'splace';
```Require with CommonJS:
```ts
const { splace } = require('splace');
```Split and replace a word:
```ts
splace('Hello, world!', { world: 'mate' });
// ['Hello, ', 'mate', '!']
```Split and replace words:
```ts
splace('Hello, world!', { Hello: "G'day", world: 'mate' });
// ["G'day", ', ', 'mate', '!']
```Split and replace based on object order:
```ts
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:
```ts
splace('1 + 1 = 2', { 1: {}, 2: [] });
// [{}, ' + ', {}, ' = ', []]
```Empty strings are removed by default. To keep empty strings:
```ts
splace('foo', { foo: 'bar' }, false);
// ['', 'bar', '']
```## Release
Release is automated with [Release Please](https://github.com/googleapis/release-please).
## License
[MIT](https://github.com/remarkablemark/splace/blob/master/LICENSE)