Skip to content

Commit

Permalink
Tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
Kikobeats committed Nov 6, 2016
1 parent 89dcfe2 commit de2eeb2
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 28 deletions.
37 changes: 16 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
# str-match

<p align="center">
<br>
<img src="https://i.imgur.com/Mh13XWB.gif" alt="str-match">
<br>
</p>

![Last version](https://img.shields.io/github/tag/Kikobeats/str-match.svg?style=flat-square)
[![Build Status](https://img.shields.io/travis/Kikobeats/str-match/master.svg?style=flat-square)](https://travis-ci.org/Kikobeats/str-match)
[![Coverage Status](https://img.shields.io/coveralls/Kikobeats/str-match.svg?style=flat-square)](https://coveralls.io/github/Kikobeats/str-match)
Expand All @@ -25,31 +19,32 @@ $ npm install str-match --save
## Usage

```js
const strMatch = require('str-match')

strMatch('do something')
//=> return something
const strmatch = require('.')
const str = "I'm selling my Macbook Pro"
const re = /macbook pro/i

console.log(strmatch(str, re))
// {
// test: true,
// match: 'Macbook Pro',
// input: 'I\'m selling my Macbook Pro',
// output: 'I\'m selling my '
// }
```

## API

### strMatch(input, [options])
### strmatch(str, regex)

#### input
#### str

*Required*<br>
Type: `string`

Lorem ipsum.

#### options
#### regex

##### foo

Type: `boolean`<br>
Default: `false`

Lorem ipsum.
*Required*<br>
Type: `regexp`

## License

Expand Down
8 changes: 4 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ const replace = require('lodash.replace')
const first = require('lodash.first')
const exists = require('existential')

function strmatch (str, regex) {
const match = first(str.match(regex))
const output = replace(str, match, '')
return { match: exists(match), input: str, output }
function strmatch (input, regex) {
const match = first(input.match(regex))
const output = replace(input, match, '')
return { test: exists(match), match, input, output }
}

module.exports = strmatch
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@
"engines": {
"node": ">= 4"
},
"files": [
"index.js"
],
"scripts": {
"clean": "rm -rf node_modules",
"coveralls": "nyc report --reporter=text-lcov | coveralls",
Expand Down
8 changes: 5 additions & 3 deletions test/index.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
'use strict'

const strmatch = require('..')
require('should')
const should = require('should')

describe('str-match', function () {
it('non detection', function () {
const str = ''
const result = strmatch(str, null)

result.match.should.be.false()
result.test.should.be.false()
should(result.match).be.undefined()
result.input.should.be.equal(str)
result.output.should.be.equal('')
})
Expand All @@ -18,7 +19,8 @@ describe('str-match', function () {
const regex = /ezzy panther/
const result = strmatch(str, regex)

result.match.should.be.true()
result.test.should.be.true()
result.match.should.be.equal('ezzy panther')
result.input.should.be.equal(str)
result.output.should.be.equal('vendo ')
})
Expand Down

0 comments on commit de2eeb2

Please sign in to comment.