Skip to content

Commit

Permalink
Dubnormalize (#32)
Browse files Browse the repository at this point in the history
* change
* method
* improved
* to...text
* where linebreaks become your desire
  • Loading branch information
ryanve authored Feb 28, 2022
1 parent 5da946d commit 27f5f2a
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 12 deletions.
21 changes: 17 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ import eol from 'eol'
- Normalize line endings in <var>text</var> to <b>CR</b> (Mac OS)
- <b>@return</b> string with line endings normalized to `\r`

### `eol.dub(text)`

- [Dubnormalize.](https://github.com/ryanve/eol/pull/32) [Used internally.](eol.js) [Generative.](#dubbing)
- Create normalizer where linebreaks become <var>text</var>
- <b>@return</b> composed function

### `eol.before(text)`
- Add linebreak before <var>text</var>
- <b>@return</b> string with linebreak added before text
Expand All @@ -56,9 +62,16 @@ eol.split(text).filter(line => line).join(eol.auto) // text joined after removin
eol.split(text).slice(-3).join(eol.auto) // last 3 lines joined
```

## Elsewhere in space
### Dubbing

```
let lflf = eol.dub("\n\n")
lflf("...")
```

[<kbd><b>got space</b>?</kbd>](https://github.com/ryanve/ssv)


[`ssv`](https://ryanve.github.io/ssv/)
## [opensource](package.json)

## License
MIT
[`MIT License`](LICENSE.md)
7 changes: 7 additions & 0 deletions eol.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@ declare module eol {
*/
export function cr(text: string): string;

/**
* Dubnormalize. Used internally. Mixin friendly.
* Create normalizer where linebreaks become your desire.
* @return anonymous function
*/
export function dub(text: string): (text: string) => string;

/**
* Add linebreak before text
* @return string with linebreak added before text
Expand Down
17 changes: 9 additions & 8 deletions eol.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,27 @@
return text + linebreak
}

function converts(to) {
function convert(text) {
function dub(to) {
function change(text) {
return text.replace(newline, to)
}
convert.toString = function() {
change.toString = function() {
return to
}
return convert
return change
}

function split(text) {
return text.split(newline)
}

api['lf'] = converts('\n')
api['cr'] = converts('\r')
api['crlf'] = converts('\r\n')
api['auto'] = converts(linebreak)
api['lf'] = dub('\n')
api['cr'] = dub('\r')
api['crlf'] = dub('\r\n')
api['auto'] = dub(linebreak)
api['before'] = before
api['after'] = after
api['split'] = split
api['dub'] = dub
return api
});
2 changes: 2 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
throw new Error('FAILED TEST: ' + this.id)
}

aok('dub method', typeof eol.dub == 'function')
aok('dub return', typeof eol.dub() == 'function')
aok('contains sees contained text', contains('ab', 'a') === true)
aok('sample contains newlines', contains(sample, '\n') && contains(sample, '\r'))
aok('returns other strings as is', eol.auto('random') === 'random')
Expand Down

0 comments on commit 27f5f2a

Please sign in to comment.