-
Notifications
You must be signed in to change notification settings - Fork 174
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Output a smaller regular expression using regexgen
Closes #8.
- Loading branch information
1 parent
edd87c3
commit fd743e7
Showing
4 changed files
with
8 additions
and
21 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,21 @@ | ||
var fs = require('fs'); | ||
var path = require('path'); | ||
|
||
var jsesc = require('jsesc'); | ||
var regenerate = require('regenerate'); | ||
var regExpTrie = require('regex-trie'); | ||
var regexgen = require('regexgen'); | ||
var template = require('lodash.template'); | ||
require('string.fromcodepoint'); | ||
|
||
var emojiCodePoints = require('unicode-tr51/code-points'); | ||
|
||
var multipleCodePointsTrie = regExpTrie(); | ||
var loneCodePointsSet = regenerate(); | ||
emojiCodePoints.forEach(function(value) { | ||
var strings = emojiCodePoints.map(function(value) { | ||
if (Array.isArray(value)) { | ||
var string = String.fromCodePoint.apply(null, value); | ||
multipleCodePointsTrie.add(string); | ||
} else { | ||
loneCodePointsSet.add(value); | ||
return String.fromCodePoint.apply(null, value); | ||
} | ||
return String.fromCodePoint(value); | ||
}); | ||
|
||
var loneCodePointsPart = loneCodePointsSet.toString(); | ||
var multipleCodePointsPart = multipleCodePointsTrie.toString(); | ||
|
||
var ROOT = path.resolve(__dirname, '..'); | ||
var sourceTemplate = template(fs.readFileSync(ROOT + '/templates/index.js')); | ||
var result = sourceTemplate({ | ||
'multipleCodePointsPart': multipleCodePointsPart, | ||
'loneCodePointsPart': loneCodePointsPart | ||
'regex': regexgen(strings, 'g') | ||
}); | ||
fs.writeFileSync(ROOT + '/index.js', result); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
module.exports = function() { | ||
return /<%= multipleCodePointsPart %>|<%= loneCodePointsPart %>/g; | ||
return <%= regex %>; | ||
}; |