mirror of
https://github.com/tenrok/maska.git
synced 2026-06-23 20:40:35 +03:00
style: code format
This commit is contained in:
+9
-17
@@ -63,6 +63,7 @@ export class Mask {
|
|||||||
|
|
||||||
completed (value: string): boolean {
|
completed (value: string): boolean {
|
||||||
const mask = this.findMask(value)
|
const mask = this.findMask(value)
|
||||||
|
|
||||||
if (this.opts.mask == null || mask == null) return false
|
if (this.opts.mask == null || mask == null) return false
|
||||||
|
|
||||||
const length = this.process(value, mask).length
|
const length = this.process(value, mask).length
|
||||||
@@ -96,12 +97,10 @@ export class Mask {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
private escapeMask (maskRaw: string): {
|
private escapeMask (maskRaw: string): { mask: string, escaped: number[] } {
|
||||||
mask: string
|
|
||||||
escaped: number[]
|
|
||||||
} {
|
|
||||||
const chars: string[] = []
|
const chars: string[] = []
|
||||||
const escaped: number[] = []
|
const escaped: number[] = []
|
||||||
|
|
||||||
maskRaw.split('').forEach((ch, i) => {
|
maskRaw.split('').forEach((ch, i) => {
|
||||||
if (ch === '!' && maskRaw[i - 1] !== '!') {
|
if (ch === '!' && maskRaw[i - 1] !== '!') {
|
||||||
escaped.push(i - escaped.length)
|
escaped.push(i - escaped.length)
|
||||||
@@ -113,14 +112,11 @@ export class Mask {
|
|||||||
return { mask: chars.join(''), escaped }
|
return { mask: chars.join(''), escaped }
|
||||||
}
|
}
|
||||||
|
|
||||||
private process (
|
private process (value: string, maskRaw: string | null, masked = true): string {
|
||||||
value: string,
|
|
||||||
maskRaw: string | null,
|
|
||||||
masked = true
|
|
||||||
): string {
|
|
||||||
if (maskRaw == null) return value
|
if (maskRaw == null) return value
|
||||||
|
|
||||||
const key = `value=${value},mask=${maskRaw},masked=${masked ? 1 : 0}`
|
const key = `value=${value},mask=${maskRaw},masked=${masked ? 1 : 0}`
|
||||||
|
|
||||||
if (this.memo.has(key)) return this.memo.get(key)
|
if (this.memo.has(key)) return this.memo.get(key)
|
||||||
|
|
||||||
const { mask, escaped } = this.escapeMask(maskRaw)
|
const { mask, escaped } = this.escapeMask(maskRaw)
|
||||||
@@ -147,10 +143,9 @@ export class Mask {
|
|||||||
while (check()) {
|
while (check()) {
|
||||||
const maskChar = mask.charAt(m)
|
const maskChar = mask.charAt(m)
|
||||||
const token = tokens[maskChar]
|
const token = tokens[maskChar]
|
||||||
const valueChar =
|
const valueChar = token?.transform != null
|
||||||
token?.transform != null
|
? token.transform(value.charAt(v))
|
||||||
? token.transform(value.charAt(v))
|
: value.charAt(v)
|
||||||
: value.charAt(v)
|
|
||||||
|
|
||||||
if (!escaped.includes(m) && token != null) {
|
if (!escaped.includes(m) && token != null) {
|
||||||
if (valueChar.match(token.pattern) != null) {
|
if (valueChar.match(token.pattern) != null) {
|
||||||
@@ -211,10 +206,7 @@ export class Mask {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (this.isEager()) {
|
if (this.isEager()) {
|
||||||
while (
|
while (notLastMaskChar(m) && (tokens[mask.charAt(m)] == null || escaped.includes(m))) {
|
||||||
notLastMaskChar(m) &&
|
|
||||||
(tokens[mask.charAt(m)] == null || escaped.includes(m))
|
|
||||||
) {
|
|
||||||
if (masked) {
|
if (masked) {
|
||||||
result[method](mask.charAt(m))
|
result[method](mask.charAt(m))
|
||||||
if (value.charAt(v) === mask.charAt(m)) {
|
if (value.charAt(v) === mask.charAt(m)) {
|
||||||
|
|||||||
Reference in New Issue
Block a user