-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadvanced.js
42 lines (37 loc) · 1.01 KB
/
advanced.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/*!
* limon <https://github.com/limonjs/limon>
*
* Copyright (c) 2016 Charlike Mike Reagent <@tunnckoCore> (http://www.tunnckocore.tk)
* Released under the MIT license.
*/
/* eslint-disable */
'use strict'
var limon = require('../index')
/**
* We don't want lexer to be on per character
* basis, so we will write a plugin that
* overwrite the default `.tokenize` method
* to pass only the input to the `.run` method.
*/
limon.use(function (app) {
this.tokenize = function tokenize (input, options) {
this.defaults(input, options)
if (!this.input || this.input.length === 0) {
throw new TypeError('limon.tokenize: expect `input` be non-empty string or buffer')
}
this.run(this.input)
return this.tokens
}
})
.use(function () {
return function (input, i) {
console.log(input, i) // => 'foo bar!', undefined
}
})
.use(function () {
return function (input, i) {
console.log(this.first) // => true
console.log(input, i) // => 'foo bar!', undefined
}
})
.tokenize('foo bar!')