https://github.com/cak/larp
Lightweight Asynchronous Regex Project
https://github.com/cak/larp
regex regexp
Last synced: 8 months ago
JSON representation
Lightweight Asynchronous Regex Project
- Host: GitHub
- URL: https://github.com/cak/larp
- Owner: cak
- License: mit
- Created: 2018-10-22T01:05:54.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2024-10-16T09:11:06.000Z (over 1 year ago)
- Last Synced: 2025-10-06T16:38:56.615Z (8 months ago)
- Topics: regex, regexp
- Language: TypeScript
- Homepage: https://www.npmjs.com/package/larp
- Size: 6.84 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# LARP
Lightweight Asynchronous Regex Project
LARP is a library that uses stored regex patterns and returns the pattern matches in a promise. You can also use URLs or filenames as the argument with an options parameter and LARP will parse the source code of the page or text from the file as arguments for the regex marching. More powerful regex magic than a level 15 spell caster!
## Usage
### Install
npm install larp
#### Modules
Import: `import * as larp from "larp";`
Require: `const larp = require("larp");`
#### Matching
- Email Addresses
_ `email(arg: string, options?: config)`
_ Example match: _john.doe@example.com_
- URLS
_ `url(arg: string, options?: config)`
_ Example match: _http://www.example.com_
- IPv4 Addresses
_ `ipv4(arg: string, options?: config)`
_ Example match: _127.0.0.1_
- HTML src Attribute Values
_ `src(arg: string, options?: config)`
_ Example match: _~~src="~~ /javascripts/main.js ~~">~~_
- HTML href Attribute Values
_ `href(arg: string, options?: config)`
_ Example match: _~~href="~~ /examples" ~~>~~_
#### Config (optional)
- **url**
_ `{ url: true }`
_ Use argument as _URL_ location and URL source will be matched.
- **file**
_ `{ file: true }`
_ Use argument as _file_ location and file text will be matched.
## Examples (basic)
The string argument specifies the text to be matched.
```javascript
larp.email("Lorem ipsum john.doe@example.com dolor sit amet.");
=> Promise: [ 'john.doe@example.com' ]
larp.url("Lorem ipsum https://www.example.com dolor sit amet.");
=> Promise: [ 'https://www.example.com' ]
larp.ipv4("Lorem ipsum 127.0.0.1 dolor sit amet.");
=> Promise: [ '127.0.0.1' ]
larp.src("
Lorem ipsum

dolor sit amet.
");
=> Promise: [ 'unicorn.png' ]
larp.href("
Lorem ipsum
Unicornsdolor sit amet.
");
=> Promise: [ '/unicorns.html' ]
```
## Examples (options)
The string argument specifies the filename when option { file: true } is provided:
```javascript
larp.ipv4("sample.txt", { file: true })
=> Promise: [ '127.0.0.1' ]
```
The string argument specifies the URL location when option { url : true } is provided:
```javascript
larp.href("http://www.example.com", { url: true })
=> Promise: [ '/stylesheets/style.css', '/examples' ]
```
## Attribution
- URL Regex from [John Gruber](https://daringfireball.net/2010/07/improved_regex_for_matching_urls)