main
Last change
on this file since d565449 was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago |
Update repo after prototype presentation
|
-
Property mode
set to
100644
|
File size:
712 bytes
|
Rev | Line | |
---|
[d565449] | 1 | const { EOL } = require('os')
|
---|
| 2 |
|
---|
| 3 | const getFirstRegexpMatchOrDefault = (text, regexp, defaultValue) => {
|
---|
| 4 | regexp.lastIndex = 0 // https://stackoverflow.com/a/11477448/4536543
|
---|
| 5 | let match = regexp.exec(text)
|
---|
| 6 | if (match !== null) {
|
---|
| 7 | return match[1]
|
---|
| 8 | } else {
|
---|
| 9 | return defaultValue
|
---|
| 10 | }
|
---|
| 11 | }
|
---|
| 12 |
|
---|
| 13 | const DEFAULT_INDENT = ' '
|
---|
| 14 | const INDENT_REGEXP = /^([ \t]+)[^\s]/m
|
---|
| 15 |
|
---|
| 16 | module.exports.detectIndent = text =>
|
---|
| 17 | getFirstRegexpMatchOrDefault(text, INDENT_REGEXP, DEFAULT_INDENT)
|
---|
| 18 | module.exports.DEFAULT_INDENT = DEFAULT_INDENT
|
---|
| 19 |
|
---|
| 20 | const DEFAULT_EOL = EOL
|
---|
| 21 | const EOL_REGEXP = /(\r\n|\n|\r)/g
|
---|
| 22 |
|
---|
| 23 | module.exports.detectEOL = text =>
|
---|
| 24 | getFirstRegexpMatchOrDefault(text, EOL_REGEXP, DEFAULT_EOL)
|
---|
| 25 | module.exports.DEFAULT_EOL = DEFAULT_EOL
|
---|
Note:
See
TracBrowser
for help on using the repository browser.