Skip to content

nijikokun/lua-find

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

lua-find NPM version NPM monthly downloads NPM total downloads

Javascript implementation of Lua's String.find functionality to allow Javascript users get back the start of a needle, and it's end. Using both plain text matching and regular expression matching.

Install

Install with npm:

$ npm install lua-find --save

Usage

const find = require('lua-find')

See the tests for more examples.

Pattern Example

let [start, end] = find('Hello World', /World/)
// [ 6, 11 ]
// Pattern format also supports string based searches
let [start, end] = find('Hello World', 'World')
// [ 6, 11 ]

Plain format example

Uses string.indexOf to improve performance when the pattern is a string.

let [start, end] = find('Hello World', 'World', 0, true)
// [ 6, 11 ]

It also enforces patterns to be strings:

let [start, end] = find('Hello /World/', /World/, 0, true) 
// [ 6, 13 ]

Starting position examples

The third argument is the startingAt property.

let [start, end] = find('Hello World, World Hello', 'Hello', 11, true)
// [19, 24]

Contributing

Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.

Running Tests

Running and reviewing unit tests is a great way to get familiarized with a library and its API. You can run tests with the following command:

$ npm test

License

Copyright © 2018, Nijiko Yonskai. Released under the MIT License.

About

Javascript implementation of Lua's String.find functionality

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published