Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/bnvk/text-scrub
This ain't yo grand daddy's find & replace or trim tool
https://github.com/bnvk/text-scrub
Last synced: 3 months ago
JSON representation
This ain't yo grand daddy's find & replace or trim tool
- Host: GitHub
- URL: https://github.com/bnvk/text-scrub
- Owner: bnvk
- Created: 2015-08-25T18:21:03.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2015-12-23T18:01:43.000Z (about 9 years ago)
- Last Synced: 2024-10-04T22:46:40.013Z (3 months ago)
- Language: JavaScript
- Homepage:
- Size: 19.5 KB
- Stars: 4
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
- project-awesome - bnvk/text-scrub - This ain't yo grand daddy's find & replace or trim tool (JavaScript)
README
Text Scrub
==========[![NPM](https://nodei.co/npm/text-scrub.png)](https://nodei.co/npm/text-scrub/)
Perform trim, grow, extract, scrub, deduplication, and structured splitting operations on lines of text in a chainable fashion. This ain't yo grand daddy's find & replace tool.
```
npm install text-scrub
```Include `text-scrub` in your server side node.js or client side app using [browserify](https://www.npmjs.com/package/browserify) today!
```
npm install text-scrub
var TextScrub = require('text-scrub')
```#### Use Cases
- Clean bits and pieces from a line of text
- Add bits and pieces to a line of text
- Transform file paths into usable data structures
- You are *not* the RegEx wizard that you wish you were
- Even if you were a RegEx wizard, the code would be gnarly#### Examples
The following examples are based on an input string such as:
```
var old_text = '[doge@fort]$ /home/root/path/thunderbird-profile/ImapMail/account-6.com/Clients.sbd/USA.sbd/East Coast.sbd/Cities.sbd/New York'
```TextScrub can either call specific filters manually such as `TextScrub.trim(start: '[doge@fort]$ ', old)` or `TextScrub.swap(...)` or you can chain filters together using the `TextScrub.Wash(tools)` method which would perform the `.trim()` operation and then `.grow()`
```
var new_text = TextScrub.Wash([
{ scrub: 'trim', start: '[doge@fort]$ ' },
{ scrub: 'swap', find: 'path/thunderbird-profile/ImapMail/account-6.com/', replace: 'messages/' }
], old_text)
```The resulting text would be
```
/home/root/messages/Clients.sbd/USA.sbd/East Coast.sbd/Cities.sbd/New York`
```### Tools & Options
**clean** removes whiteapce from start and end of input
```
TextScrub.clean(opts, line)return // string
```**trim** cuts a specified string (or character count) from the start & end of the input
```
TextScrub.trim(opts, line)opts.start // string, integer
opts.end // string, integerreturn // string
```**grow** - adds a string to the start & end of the input
```
TextScrub.grow(opts, line)opts.start // string
opts.end // stringreturn // string
```**extractor** - extracts emails, urls, or currency from the input string and returns them in an object
```
TextScrub.extractor(opts, line)opts // array ['emails', 'urls', 'currency']
opts.output // objectreturn // object { 'emails': {}, 'urls': {}, 'currency': {} }
```**swap** - performs find & replace operations, but allows for regex inputs that replace all instances or specified "item" of regex array
```
TextScrub.swap(opts, line)opts.find // string
opts.regex // string email, url, or currency
opts.item // integer (only used with regex)
opts.replace // stringreturn // string
```**splitter** - performs splitting of a string on "term" and then builds a nested object of sub terms. splitter handles "overage" by either `ignoring`, `joining` or pushing items to `unsorted` output.
```
TextScrub.splitter(opts, line)opts.term // string
opts.depth // integer 2
opts.overage // string ignore, join, unsorted
opts.joiner // string ','
opts.unique // bool true
opts.output // object { unsorted: [], groups: {} }return //
```#### The Output option
Two of the tools `.extractor()` and `.splitter()` accept the passing of `opts.options` variable