-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
36 lines (25 loc) · 1.3 KB
/
main.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
"use strict";
const extractLiteral = (function() {
const hex2015 = String.raw`[0-9A-Fa-f]+`,
float2015 = String.raw`(?:\d+(?:\.\d*)?|\.\d+)(?:[Ee][+-]?\d+)?`,
oct2015 = String.raw`[0-7]+`,
bin2015 = String.raw`[01]+`;
const hex2018 = String.raw`[0-9A-Fa-f]+(?:_[0-9A-Fa-f]+)*`,
float2018 = String.raw`(?:\d+(?:_\d+)*(?:\.(?:\d+(?:_\d+)*)?)?|\.\d+(?:_\d+)*)(?:[Ee][+-]?\d+)?`,
oct2018 = String.raw`[0-7]+(?:_[0-7]+)*`,
bin2018 = String.raw`[01]+(?:_[0-1]+)*`;
// 2018: /x/y,
const literal2015 = String.raw`\s*(?:NaN|(?:[+-]?(?:Infinity|0(?:[Bb]${bin2015}|[Oo]${oct2015}|[Xx]${hex2015}|(?:${float2015})?)|${float2015})))\s*`,
literal2018 = String.raw`\s*(?:NaN|(?:[+-]?(?:Infinity|0(?:[Bb]${bin2018}|[Oo]${oct2018}|[Xx]${hex2018}|_?${float2018})|${float2018})))\s*`,
defaultPattern = !!Number('1_1') ? literal2018 : literal2015,
defaultExpr = new RegExp( defaultPattern, 'y' );
function extractLiteral( text, startIndex = 0 )
{
defaultExpr.lastIndex = startIndex;
return ( defaultExpr.exec( text ) || [""] )[0];
}
extractLiteral.PATTERN = defaultPattern;
return extractLiteral;
})();
if ( typeof module !== 'undefined' )
module.exports = extractLiteral;