https://github.com/dafrok/safe-match
Prevent match API from the result of null
https://github.com/dafrok/safe-match
Last synced: 12 months ago
JSON representation
Prevent match API from the result of null
- Host: GitHub
- URL: https://github.com/dafrok/safe-match
- Owner: Dafrok
- License: mit
- Created: 2016-03-29T05:32:37.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2016-03-29T09:26:44.000Z (over 10 years ago)
- Last Synced: 2025-07-21T07:46:51.333Z (about 1 year ago)
- Language: JavaScript
- Size: 2.93 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: LICENSE
Awesome Lists containing this project
README
# safe-match
## Description
Prevent match API from the result of null.
## Install
```
$ npm i safe-match
```
## API
- match
- init
- reset
## Usage
``` javascript
var safeMatch = require('safe-match').match
safeMatch('foo', /bar/) // => 0
var safeMatchInit = require('safe-match').init
var safeMatchReset = require('safe-match').reset
safeMatchInit()
'foo'.safeMatch(/bar/) // => 0
safeMatchReset()
'foo'.safeMatch(/bar/) // => null
safeMatchInit({
name: 'match'
})
'foo'.match(/bar/) // => 0
safeMatchReset()
'foo'.match(/bar/) // => null
safeMatchInit({
noConflict: true
})
'foo'.safeMatch(/bar/, true) // => 0
'foo'.safeMatch(/bar/) // => null
safeMatchReset()
'foo'.match(/bar/, true) // => null
```