# recoo

> Regular expression helper

Latest version **1.0.8** (published 2015-02-23) · Apache 2.0 license · 0 weekly downloads

## Install

```sh
npm install recoo
pnpm add recoo
yarn add recoo
bun add recoo
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.8 |
| Published | 2015-02-23 |
| First published | 2015-02-13 |
| Weekly downloads | 0 |
| License | Apache 2.0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Mark Zhan |
| Maintainers | markzhan |
| Keywords | re, regex, regexp, regular, expression, helper, chain, is, test, find, parse, check, match, contain, pattern, validate |

## Links

- npm: https://www.npmjs.com/package/recoo
- Repository: https://github.com/markzhan/recoo
- Issues: https://github.com/markzhan/recoo/issues
- npm.io page: https://npm.io/package/recoo

## Alternatives

- [memory-cache](https://npm.io/package/memory-cache.md) — 795.0K weekly downloads
- [@httptoolkit/proxy-agent](https://npm.io/package/@httptoolkit/proxy-agent.md) — 11.2K weekly downloads
- [express-cache-controller](https://npm.io/package/express-cache-controller.md) — 5.3K weekly downloads
- [http-cache-middleware](https://npm.io/package/http-cache-middleware.md) — 4.5K weekly downloads
- [cache2](https://npm.io/package/cache2.md) — 1.5K weekly downloads

## Recent versions

- 1.0.8 (latest) — 2015-02-23
- 1.0.7 — 2015-02-23
- 1.0.6 — 2015-02-15
- 1.0.3 — 2015-02-15
- 1.0.2 — 2015-02-14
- 1.0.1 — 2015-02-13
- 1.0.0 — 2015-02-13

## README

[![Build Status](https://api.travis-ci.org/markzhan/recoo.svg?branch=master)](https://travis-ci.org/markzhan/recoo)
[![Coverage Status](https://coveralls.io/repos/markzhan/recoo/badge.svg)](https://coveralls.io/r/markzhan/recoo)
[![NPM Downloads](https://img.shields.io/npm/dm/recoo.svg?style=flat)](https://www.npmjs.org/package/recoo)


# recoo

Regular expression helper.


## Installation

```sh
npm i recoo --save
```

## Usage

```js
var r = require('recoo');

var ipv4 = r()
.a('25[0-5]')
.or('2[0-4][0-9]')
.or('1[0-9][0-9]')
.or('[1-9][0-9]')
.or('[0-9]')
.p()

ipv4 = ipv4.a(r('\\.').a(ipv4).p(0,3));

console.log(ipv4.regex);  // (?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])(?:\.(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])){3}
console.log(ipv4.is('192.168.1.1')); // true
console.log(ipv4.contain('192.168.1.a 192.168.1.1'));  // true
console.log(ipv4.match('192.168.1.a 192.68.1.1-8.8.8.8.'));  // [ '192.68.1.1', '8.8.8.8' ]
console.log(ipv4.e().test('192.168.1.1'));  // true

// check url
var tlds = 'com|cn';
var protocol = '(?:(?:(?:\\w)+:)?\/\/)?';
var auth = '(?:\\S+(?::\\S*)?@)?';
var host = '(?:xn--[a-z0-9\\-]{1,59}|(?:(?:[a-z\\u00a1-\\uffff0-9]+-?){0,62}[a-z\\u00a1-\\uffff0-9]{1,63}))';
var domain = '(?:\\.(?:xn--[a-z0-9\\-]{1,59}|(?:[a-z\\u00a1-\\uffff0-9]+-?){0,62}[a-z\\u00a1-\\uffff0-9]{1,63}))*';
var tld = '(?:\\.(?:xn--[a-z0-9\\-]{1,59}|' + tlds + '+))';
var port = '(?::\\d{2,5})?';
var path = '(?:\/[^\\s]*)?';

var url = r().a(ipv4).or().p('localhost').or().a(host).a(domain).a(tld)
var url = r().a(protocol).a(auth).p(url).a(port).a(path)

console.log(url.is('http://markzhan.com')); // true
```

## API

#### .a(re, [m, n]) - `<...>[{m,n}]`

* @param{ Mixed } regex string or recoo object
* @param{ Mixed } {m,n} <- m, m >= 0 OR ? + * {...} {...}?
* @param{ Number } {m,n} <- n, n >= m
```js
var r = require('recoo');
console.log(r().a('\\d').regex); // \d
console.log(r().a('\\d').is('8')); // true
console.log(r().a(r('\\d')).is('8')); // true
```

#### .or([re, [m, n]]) - `<|...>[{m,n}]`

* @param{ Mixed } regex string or recoo object
* @param{ Mixed } {m,n} <- m, m >= 0 OR ? + * {...} {...}?
* @param{ Number } {m,n} <- n, n >= m
```js
var r = require('recoo');
console.log(r('hello').or('world').regex); // hello|world
console.log(r('hello').or('world').match('hello')); // [ 'hello' ]
console.log(r('hello').or('world').match('world')); // [ 'world' ]
```

#### .m([re, [m, n]]) - `<[...]>[{m,n}]`

* @param{ Mixed } regex string or recoo object
* @param{ Mixed } {m,n} <- m, m >= 0 OR ? + * {...} {...}?
* @param{ Number } {m,n} <- n, n >= m
```js
var r = require('recoo');
console.log(r().m('0-7').regex); // [0-7]
console.log(r().m('0-7').is('8')); // false
console.log(r().m(r('0-9')).is('8')); // true
```

#### .p([re, [m, n]]) - `<(...)>[{m,n}]`

* @param{ Mixed } regex string or recoo object
* @param{ Mixed } {m,n} <- m, m >= 0 OR ? + * {...} {...}?
* @param{ Number } {m,n} <- n, n >= m
```js
var r = require('recoo');
console.log(r().p('abc').regex); // (?:abc)
console.log(r().p('abc').contain('123')); // false
console.log(r().p(r('abc')).contain('abc123')); // true
```

#### .n(m, n) - `{m,n}`

* @param{ Mixed } {m,n} <- m, m >= 0 OR string : ? + * {...} {...}?
* @param{ Number } {m,n} <- n, n >= m
```js
var r = require('recoo');
console.log(r('\\d').n('+').regex); // \d+
console.log(r('\\d').n(3,3).regex); // \d{3,3}
console.log(r('\\d').n('+').match('99')); // [ '99' ]
console.log(r('\\d').n(3,3).match('99.999')); // [ '999' ]
```

#### .exact()
```js
var r = require('recoo');
console.log(r('\\d').regex); // \d
console.log(r('\\d').contain('8.8')); // true
console.log(r('\\d').exact().contain('8.8')); // false
```

#### .go([opts])
```js
var r = require('recoo');
console.log(r('\\d').regex); // String: \d
console.log(r('\\d').go().regex); // Regexp: /\d/
console.log(r('\\d').go('ig').regex); // Regexp: /\d/gi
```

#### .opt(opts)
```js
var r = require('recoo');
console.log(r('\\d').opt('ig').go().regex); // Regexp: /\d/gi
console.log(r('\\d').opt('g').go('i').regex); // Regexp: /\d/i
```

#### .e([str])

* @param { Mixed }

```js
var r = require('recoo');
console.log(r('\\w').e());  // /\w/
console.log(r('\\w').e('ig'));  // /\w/gi
console.log(r('\\w').e('abc').is()); // false
console.log(r('\\w').e('abc').contain()); // true
console.log(r('abc').e('abc').match()); // [ 'abc' ]
console.log(r('\\d').e('abc').match()); // null
console.log(r('\\d').e().test('8'));  // true
```

#### .is([str])

* same as previous

#### .contain([str])

* same as previous

#### .match([str])

* same as previous

#### .desc(str)
```js
var r = require('recoo');
console.log(r().desc('API test').description); // 'API test'
```


## License

Copyright © 2015 [Mark Zhan](http://markzhan.com).

This project is available under the Apache license. See [LICENSE](https://github.com/markzhan/recoo/blob/master/LICENSE) for details.

---
_Source: https://npm.io/package/recoo · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
