strscanner

lexical string analysis for javascript

8 个版本
安装
npm install strscanner
yarn add strscanner
pnpm add strscanner
bun add strscanner
README

Example


var strscan = require("strscan");

var scanner = strscan("hello world -> ", {
	skipWhitespace: true
});


while(!scanner.eof()) {
	
	scanner.nextChar();

	if(scanner.isAZ()) {
		var word = scanner.nextWord();
	} else 
	if(scanner.cchar() == "-") {
		var arrow = scanner.to(1);
	}
}

API

.eof()

returns true if the scanner is at the end

.nextChar()

scans to the next character

.cchar()

returns the current char

.isAZ()

returns true if the current char is A-Z

.is09()

returns true if the current char is 0-9

.isAlpha()

returns true if the current char is A-Z 0-9

.next(match)

returns true if the current char matches the given regular expression

.nextWord()

returns the next word

.to(count)

scans to the given position, and returns the buffer

.peek(count)

returns a buffer from the current position to the given count, then rewinds

.rewind(count)

rewinds N characters

.skip(count)

skips N characters

版本列表
0.0.8 2014-02-20
0.0.6 2014-02-20
0.0.5 2013-05-24
0.0.4 2013-04-22
0.0.3 2013-04-20
0.0.2 2013-04-18
0.0.1 2012-06-12
0.0.0 2012-06-12