https://github.com/fetchte/stringmerge
String Alternating Merge
https://github.com/fetchte/stringmerge
Last synced: 2 months ago
JSON representation
String Alternating Merge
- Host: GitHub
- URL: https://github.com/fetchte/stringmerge
- Owner: fetchTe
- License: other
- Created: 2017-10-05T22:26:10.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2017-10-06T20:34:01.000Z (about 8 years ago)
- Last Synced: 2025-01-21T12:48:39.206Z (11 months ago)
- Language: JavaScript
- Size: 1.13 MB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# stringmerge → String Alternating Merge
[](https://github.com/artisin/stringmerge/blob/master/LICENSE.txt)
[](https://www.npmjs.com/package/stringmerge)
[](https://app.wercker.com/project/byKey/a668f191696fe6b304f81c996a083c8c)
[](https://github.com/artisin/stringmerge/blob/master/package.json)
## Description
Merges multiple strings together alternating through their arguments.
```
merge :: (...String) → String
merge :: ('abc', '123456') -> 'a1b2c3456'
```
## Install
You can either install stringmerge via npm:
```bash
yarn add stringmerge
```
Alternatively, you can download/copy one of files in the `/dist` folder depending on your use-case:
+ `dist/stringmerge.js` - The node build for use with webpack and the like
+ `dist/stringmerge-browser.js` - The browser build includes all the various library dependancies
+ `dist/stringmerge-browser.min.js` - The minified version of browser version
## Mode of Operation
The default export `merge` merges string arguments together via a simple `while` loop. Any non-string arguments will be disregarded.
```js
import merge from 'stringmerge'
const mergedString = merge('abc', '123', 123, 'z');
// should(mergeResults).be.eql('a1zb2c3');
```
Alternatively, you can use the `mergeGenerator` export which utilizes a [generator](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Iterators_and_Generators) to iterate through the arguments. This only makes sense if you have a ridiculous amount of arguments around the ballpark of +25000.
```js
import { mergeGenerator } from 'stringmerge'
const mergedString = mergeGenerator('abc', '123', 123, 'z');
// should(mergeResults).be.eql('a1zb2c3');
```
## Npm Sripts
```yaml
scripts:
build: 'Builds stringmerge → output dist/'
clean: 'deletes all dist/ files'
commit: 'commitizen commit'
dev: 'webpack watch development'
benchmark: 'runs benchmarks located in __tests__/benchmark.run.js'
test: 'runs test located in __tests__/tests.run.js'
```
## Benchmarks
```
merge - two arguments x 325,472 ops/sec ±1.10% (91 runs sampled)
mergeGenerator - two arguments x 247,051 ops/sec ±0.50% (90 runs sampled)
```
```
merge - ten arguments x 37,848 ops/sec ±0.55% (91 runs sampled)
mergeGenerator - ten arguments x 25,903 ops/sec ±1.96% (89 runs sampled)
```
```
merge 50000 - arguments x 0.13 ops/sec ±65.16% (5 runs sampled)
mergeGenerator - 50000 arguments x 0.56 ops/sec ±50.97% (6 runs sampled)
```