UNPKG

next-translate-scanner

Version:

Scan next-translate code for translations and update json files.

34 lines (33 loc) 1.09 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); class BaseLexer { constructor(options = {}) { this.keys = []; this.functions = options.functions || ['t']; this.defaultNS = options.defaultNS; this.nsSeparator = options.nsSeparator || ':'; } extract(string, filename) { throw new Error('extract not implemented'); } validateString(string) { const regex = new RegExp('^' + BaseLexer.stringPattern + '$', 'i'); return string ? regex.test(string) : false; } functionPattern() { return '(?:' + this.functions.join('|').replace('.', '\\.') + ')'; } static get singleQuotePattern() { return '\'(?:[^\'].*?[^\\\\])?\''; } static get doubleQuotePattern() { return '"(?:[^"].*?[^\\\\])?"'; } static get variablePattern() { return '(?:[A-Z0-9_.-]+)'; } static get stringPattern() { return ('(?:' + [BaseLexer.singleQuotePattern, BaseLexer.doubleQuotePattern].join('|') + ')'); } } exports.default = BaseLexer;