@markuplint/types
Advanced tools
Comparing version 4.0.0-alpha.3 to 4.0.0-alpha.4
@@ -33,3 +33,3 @@ import { fork } from 'css-tree'; | ||
}; | ||
Object.keys(types).forEach(key => { | ||
for (const key of Object.keys(types)) { | ||
const valueOrChecker = types[key]; | ||
@@ -42,8 +42,10 @@ if (typeof valueOrChecker === 'string') { | ||
} | ||
}); | ||
} | ||
propsExtended = { ...type.syntax.properties }; | ||
if (type.caseSensitive) { | ||
caseSensitive = true; | ||
Object.keys(typesExtended).forEach(key => eachMimicCases(key, typesExtended)); | ||
Object.keys(propsExtended).forEach(key => eachMimicCases(key, propsExtended)); | ||
for (const key of Object.keys(typesExtended)) | ||
eachMimicCases(key, typesExtended); | ||
for (const key of Object.keys(propsExtended)) | ||
eachMimicCases(key, propsExtended); | ||
value = mimicCases(value); | ||
@@ -58,7 +60,7 @@ } | ||
}).lexer; | ||
Object.keys(typesCheckers).forEach(key => { | ||
for (const key of Object.keys(typesCheckers)) { | ||
const checker = typesCheckers[key]; | ||
// @ts-ignore | ||
lexer.addType_(key, (token, getNextToken) => checker?.(token, getNextToken, cssSyntaxMatch)); | ||
}); | ||
} | ||
const { isProp, name } = detectName(defName); | ||
@@ -122,3 +124,3 @@ // @ts-ignore | ||
const isProp = def.search("<'") === 0; | ||
const name = def.replace(/^<'?|'?>$/g, ''); | ||
const name = def.replaceAll(/^<'?|'?>$/g, ''); | ||
return { | ||
@@ -147,6 +149,6 @@ isProp, | ||
function mimicCases(value) { | ||
return value.replace(/[A-Z]/g, $0 => `${MIMIC_TAG_L}${$0}${MIMIC_TAG_R}`); | ||
return value.replaceAll(/[A-Z]/g, $0 => `${MIMIC_TAG_L}${$0}${MIMIC_TAG_R}`); | ||
} | ||
function deMimicCases(value) { | ||
return value.replace(new RegExp(`${MIMIC_TAG_L}([A-Z])${MIMIC_TAG_R}`, 'g'), (_, $1) => $1); | ||
return value.replaceAll(new RegExp(`${MIMIC_TAG_L}([A-Z])${MIMIC_TAG_R}`, 'g'), (_, $1) => $1); | ||
} |
@@ -23,3 +23,3 @@ import { checkMultiTypes } from './check-multi-types.js'; | ||
ref: '', | ||
is: value => (0 < value.length ? matched() : unmatched(value, 'empty-token')), | ||
is: value => (value.length > 0 ? matched() : unmatched(value, 'empty-token')), | ||
}, | ||
@@ -95,5 +95,5 @@ OneLineAny: { | ||
// NameChar ::= NameStartChar | "-" | "." | [0-9] | #xB7 | [#x0300-#x036F] | [#x203F-#x2040] | ||
const nameCharTail = /-|[.0-9\u00B7]|[\u0300-\u036F\u203F-\u2040]/; | ||
const nameCharTail = /-|[\d.\u00B7]|[\u0300-\u036F\u203F\u2040]/; | ||
// Name ::= NameStartChar (NameChar)* | ||
const name = RegExp(`(?:${nameStartChar.source})(?:${nameCharTail})*`, 'u'); | ||
const name = new RegExp(`(?:${nameStartChar.source})(?:${nameCharTail})*`, 'u'); | ||
return name.test(value) ? matched() : unmatched(value, 'unexpected-token'); | ||
@@ -100,0 +100,0 @@ }, |
@@ -8,3 +8,3 @@ import { matched, unmatched } from './match-result.js'; | ||
} | ||
let values = type.enum.slice(); | ||
let values = [...type.enum]; | ||
if (caseInsensitive) { | ||
@@ -11,0 +11,0 @@ value = value.toLowerCase(); |
@@ -9,3 +9,3 @@ import leven from 'leven'; | ||
let maxRatio = 0; | ||
list.forEach(word => { | ||
for (const word of list) { | ||
const dist = leven(value.trim().toLowerCase(), word.trim().toLowerCase()); | ||
@@ -17,3 +17,3 @@ const ratio = 1 - dist / word.length; | ||
maxRatio = Math.max(ratio, maxRatio); | ||
}); | ||
} | ||
if (value === candidate) { | ||
@@ -20,0 +20,0 @@ return; |
@@ -38,8 +38,8 @@ import { isCSSSyntax } from './check.js'; | ||
} | ||
catch (e) { | ||
if (e instanceof Error && e.message === 'MARKUPLINT_TYPE_NO_EXIST') { | ||
catch (error) { | ||
if (error instanceof Error && error.message === 'MARKUPLINT_TYPE_NO_EXIST') { | ||
log("Allow all of any value because the type doesn't exist"); | ||
return matched(); | ||
} | ||
throw e; | ||
throw error; | ||
} | ||
@@ -46,0 +46,0 @@ } |
import type { Result } from './types.js'; | ||
import type { Number } from './types.schema.js'; | ||
export declare function checkNumber(value: string, type: Readonly<Number>, ref?: string): Result; | ||
import type { Number as TypeNumber } from './types.schema.js'; | ||
export declare function checkNumber(value: string, type: Readonly<TypeNumber>, ref?: string): Result; |
@@ -9,4 +9,4 @@ import { matched, unmatched } from './match-result.js'; | ||
if (syntaxMatched) { | ||
const n = parseFloat(value); | ||
if (!isFinite(n)) { | ||
const n = Number.parseFloat(value); | ||
if (!Number.isFinite(n)) { | ||
return unmatched(value, 'unexpected-token'); | ||
@@ -13,0 +13,0 @@ } |
@@ -7,3 +7,3 @@ /** | ||
export function isFloat(value) { | ||
return value === value.trim() && Number.isFinite(parseFloat(value)); | ||
return value === value.trim() && Number.isFinite(Number.parseFloat(value)); | ||
} |
@@ -7,3 +7,3 @@ /** | ||
export function isInt(value) { | ||
return /^-?[0-9]+$/.test(value); | ||
return /^-?\d+$/.test(value); | ||
} |
@@ -7,3 +7,3 @@ /** | ||
export function isNonZeroUint(value) { | ||
return /^[0-9]+$/.test(value) && !/^0+$/.test(value); | ||
return /^\d+$/.test(value) && !/^0+$/.test(value); | ||
} |
@@ -7,7 +7,7 @@ /** | ||
export function isUint(value, options) { | ||
const matched = /^[0-9]+$/.test(value); | ||
const matched = /^\d+$/.test(value); | ||
if (matched && options) { | ||
const n = parseInt(value, 10); | ||
const n = Number.parseInt(value, 10); | ||
if (options.gt != null) { | ||
return isFinite(n) && options.gt < n; | ||
return Number.isFinite(n) && options.gt < n; | ||
} | ||
@@ -14,0 +14,0 @@ } |
@@ -9,4 +9,4 @@ /** | ||
export function range(value, from, to) { | ||
const num = parseFloat(value); | ||
if (isNaN(num)) { | ||
const num = Number.parseFloat(value); | ||
if (Number.isNaN(num)) { | ||
return false; | ||
@@ -13,0 +13,0 @@ } |
@@ -8,3 +8,3 @@ /** | ||
value = value.trim().toLowerCase(); | ||
const matched = value.match(/(^-?\.[0-9]+|^-?[0-9]+(?:\.[0-9]+(?:e[+-][0-9]+)?)?)([a-z]+$)/i); | ||
const matched = value.match(/(^-?\.\d+|^-?\d+(?:\.\d+(?:e[+-]\d+)?)?)([a-z]+$)/i); | ||
if (!matched) { | ||
@@ -11,0 +11,0 @@ return { |
@@ -24,14 +24,14 @@ import { matched, unmatched } from '../match-result.js'; | ||
let value; | ||
if (!res) { | ||
isBroken = true; | ||
value = ''; | ||
} | ||
else { | ||
if (res.index !== 0) { | ||
value = strings.slice(res.index + res[0].length); | ||
if (res) { | ||
if (res.index === 0) { | ||
value = res[0] ?? ''; | ||
} | ||
else { | ||
value = res[0] ?? ''; | ||
value = strings.slice(res.index + res[0].length); | ||
} | ||
} | ||
else { | ||
isBroken = true; | ||
value = ''; | ||
} | ||
const token = addToken(value); | ||
@@ -83,3 +83,3 @@ // @ts-ignore | ||
} | ||
const chars = value.split(''); | ||
const chars = [...value]; | ||
const values = []; | ||
@@ -102,12 +102,11 @@ let char; | ||
else { | ||
values.push(last); | ||
values.push(char); | ||
values.push(last, char); | ||
} | ||
} | ||
let offset = 0; | ||
values.forEach(v => { | ||
for (const v of values) { | ||
const token = new Token(v, offset, value, separators); | ||
this.push(token); | ||
offset += v.length; | ||
}); | ||
} | ||
} | ||
@@ -274,3 +273,3 @@ get value() { | ||
else { | ||
if (head?.value && !head.match(/^\s*$/)) { | ||
if (head?.value && !head.matches(/^\s*$/)) { | ||
passCount += 4 * wait; | ||
@@ -334,3 +333,3 @@ } | ||
has(value) { | ||
return this.some(t => t.match(value)); | ||
return this.some(t => t.matches(value)); | ||
} | ||
@@ -337,0 +336,0 @@ headAndTail() { |
@@ -45,3 +45,3 @@ import type { TokenValue } from './types.js'; | ||
*/ | ||
match(value: TokenValue, caseInsensitive?: boolean): boolean; | ||
matches(value: TokenValue, caseInsensitive?: boolean): boolean; | ||
toJSON(): { | ||
@@ -48,0 +48,0 @@ type: number; |
export class Token { | ||
static getCol(value, offset) { | ||
const lines = value.slice(0, offset).split(/\n/g); | ||
return (lines[lines.length - 1] ?? '').length + 1; | ||
return (lines.at(-1) ?? '').length + 1; | ||
} | ||
@@ -15,4 +15,5 @@ static getLine(value, offset) { | ||
switch (value[0]) { | ||
case ',': | ||
case ',': { | ||
return Token.Comma; | ||
} | ||
} | ||
@@ -65,5 +66,5 @@ } | ||
*/ | ||
match(value, caseInsensitive) { | ||
matches(value, caseInsensitive) { | ||
if (Array.isArray(value)) { | ||
return value.some(v => this.match(v)); | ||
return value.some(v => this.matches(v)); | ||
} | ||
@@ -89,4 +90,4 @@ if (typeof value === 'string') { | ||
toNumber() { | ||
const num = parseFloat(this.value); | ||
return isNaN(num) ? 0 : num; | ||
const num = Number.parseFloat(this.value); | ||
return Number.isNaN(num) ? 0 : num; | ||
} | ||
@@ -93,0 +94,0 @@ unmatched(options) { |
@@ -69,3 +69,3 @@ import { log } from '../debug.js'; | ||
*/ | ||
/[^\s]*/, | ||
/\S*/, | ||
/** | ||
@@ -93,3 +93,3 @@ * RWS (Required whitespace) | ||
*/ | ||
if (!featureIdentifier || !featureIdentifier.match(/^[a-z0-9-]+$/i)) { | ||
if (!featureIdentifier || !featureIdentifier.matches(/^[\da-z-]+$/i)) { | ||
return featureIdentifier.unmatched({ | ||
@@ -117,3 +117,3 @@ reason: 'unexpected-token', | ||
// Value | ||
/[^\s]*/, | ||
/\S*/, | ||
// Separator | ||
@@ -145,6 +145,6 @@ /\s*/, | ||
} | ||
if (allow.match(['*', "'self'", "'src'", "'none'"], true)) { | ||
if (allow.matches(['*', "'self'", "'src'", "'none'"], true)) { | ||
continue; | ||
} | ||
if (allow.match(['self', 'src', 'none'], true)) { | ||
if (allow.matches(['self', 'src', 'none'], true)) { | ||
return allow.unmatched({ | ||
@@ -151,0 +151,0 @@ reason: 'missing-token', |
@@ -131,3 +131,3 @@ import { log } from '../debug.js'; | ||
// > (i.e. the "on" and "off" keywords are not allowed). | ||
if (head.match(['on', 'off'], true)) { | ||
if (head.matches(['on', 'off'], true)) { | ||
if (tail[0]) { | ||
@@ -151,3 +151,3 @@ acLog('[Unmatched ("%s")] Unexpected pair with "on" or "off": "%s"', value, tail.value); | ||
// > meaning that the field belongs to the named group. | ||
if (head.match(namedGroup, true)) { | ||
if (head.matches(namedGroup, true)) { | ||
hasNamedGroup = true; | ||
@@ -175,3 +175,3 @@ const sectionToken = tail.search(namedGroup); | ||
// > - "billing", meaning the field is part of the billing address or contact information | ||
if (head.match(partOfAddress, true)) { | ||
if (head.matches(partOfAddress, true)) { | ||
hasPartOfAddress = true; | ||
@@ -200,3 +200,3 @@ const partToken = tail.search(partOfAddress); | ||
} | ||
if (head.match(contactingTokens, true)) { | ||
if (head.matches(contactingTokens, true)) { | ||
hasContactingToken = true; | ||
@@ -208,3 +208,3 @@ const contactableFiledToken = tail[0]; | ||
} | ||
if (!contactableFiledToken.match(contactableFieldNames, true)) { | ||
if (!contactableFiledToken.matches(contactableFieldNames, true)) { | ||
const candidate = getCandidate(contactableFiledToken.value, contactableFieldNames); | ||
@@ -223,3 +223,3 @@ acLog('[Unmatched ("%s")] Unexpected token: "%s"', value, contactableFiledToken.value); | ||
if (tail[1]) { | ||
if (tail[1].match(webauthnFieldNames)) { | ||
if (tail[1].matches(webauthnFieldNames)) { | ||
return matched(); | ||
@@ -247,5 +247,5 @@ } | ||
} | ||
if (head.match([...autofillFieldNames, ...contactableFieldNames], true)) { | ||
if (head.matches([...autofillFieldNames, ...contactableFieldNames], true)) { | ||
if (tail[0]) { | ||
if (tail[0].match(webauthnFieldNames)) { | ||
if (tail[0].matches(webauthnFieldNames)) { | ||
return matched(); | ||
@@ -273,3 +273,3 @@ } | ||
} | ||
if (head.match(webauthnFieldNames)) { | ||
if (head.matches(webauthnFieldNames)) { | ||
return matched(); | ||
@@ -297,6 +297,3 @@ } | ||
else if (!hasPartOfAddress) { | ||
expects.unshift(...partOfAddress | ||
.slice() | ||
.reverse() | ||
.map(token => ({ | ||
expects.unshift(...[...partOfAddress].reverse().map(token => ({ | ||
type: 'const', | ||
@@ -303,0 +300,0 @@ value: token, |
@@ -13,9 +13,9 @@ import { log } from '../../debug.js'; | ||
// - | ||
/[^0-9]?/, | ||
/\D?/, | ||
// MM | ||
/[^-]*/, | ||
// - | ||
/[^0-9]/, | ||
/\D/, | ||
// DD | ||
/.[0-9]*/, | ||
/.\d*/, | ||
]); | ||
@@ -22,0 +22,0 @@ log('Date: "%s" => %O', tokens.value, tokens); |
@@ -24,3 +24,3 @@ import { log } from '../../debug.js'; | ||
} | ||
if (!year.match(/^[0-9]+$/)) { | ||
if (!year.matches(/^\d+$/)) { | ||
return year.unmatched({ | ||
@@ -60,3 +60,3 @@ reason: 'unexpected-token', | ||
} | ||
if (!month.match(/^[0-9]+$/)) { | ||
if (!month.matches(/^\d+$/)) { | ||
return month.unmatched({ | ||
@@ -104,3 +104,3 @@ reason: 'unexpected-token', | ||
} | ||
if (!date.match(/^[0-9]+$/)) { | ||
if (!date.matches(/^\d+$/)) { | ||
return date.unmatched({ | ||
@@ -146,3 +146,3 @@ reason: 'unexpected-token', | ||
} | ||
if (!hour.match(/^[0-9]+$/)) { | ||
if (!hour.matches(/^\d+$/)) { | ||
return hour.unmatched({ | ||
@@ -181,3 +181,3 @@ reason: 'unexpected-token', | ||
} | ||
if (!minute.match(/^[0-9]+$/)) { | ||
if (!minute.matches(/^\d+$/)) { | ||
return minute.unmatched({ | ||
@@ -216,3 +216,3 @@ reason: 'unexpected-token', | ||
} | ||
if (!second.match(/^[0-9]+$/)) { | ||
if (!second.matches(/^\d+$/)) { | ||
return second.unmatched({ | ||
@@ -251,3 +251,3 @@ reason: 'unexpected-token', | ||
} | ||
if (!secondFP.match(/^[0-9]+$/)) { | ||
if (!secondFP.matches(/^\d+$/)) { | ||
return secondFP.unmatched({ | ||
@@ -259,3 +259,3 @@ reason: 'unexpected-token', | ||
} | ||
if (!(1 <= secondFP.length && secondFP.length <= 3)) { | ||
if (!(secondFP.length > 0 && secondFP.length <= 3)) { | ||
return secondFP.unmatched({ | ||
@@ -279,3 +279,3 @@ reason: { type: 'out-of-range-length-digit', gte: 1, lte: 3 }, | ||
} | ||
if (!week.match(/^[0-9]+$/)) { | ||
if (!week.matches(/^\d+$/)) { | ||
return week.unmatched({ | ||
@@ -315,3 +315,3 @@ reason: 'unexpected-token', | ||
} | ||
if (!hyphen.match('-')) { | ||
if (!hyphen.matches('-')) { | ||
return hyphen.unmatched({ | ||
@@ -335,3 +335,3 @@ reason: 'unexpected-token', | ||
} | ||
if (!colon.match(':')) { | ||
if (!colon.matches(':')) { | ||
return colon.unmatched({ | ||
@@ -353,3 +353,3 @@ reason: 'unexpected-token', | ||
} | ||
if (!colon.match(':')) { | ||
if (!colon.matches(':')) { | ||
return colon.unmatched({ | ||
@@ -371,3 +371,3 @@ reason: 'unexpected-token', | ||
} | ||
if (!dot.match('.')) { | ||
if (!dot.matches('.')) { | ||
return dot.unmatched({ | ||
@@ -393,3 +393,3 @@ reason: 'unexpected-token', | ||
} | ||
if (!sep.match(['T', ' '])) { | ||
if (!sep.matches(['T', ' '])) { | ||
return sep.unmatched({ | ||
@@ -414,3 +414,3 @@ reason: 'unexpected-token', | ||
} | ||
if (!sep.match('T')) { | ||
if (!sep.matches('T')) { | ||
return sep.unmatched({ | ||
@@ -438,3 +438,3 @@ reason: 'unexpected-token', | ||
} | ||
if (!colon.match(['+', '-'])) { | ||
if (!colon.matches(['+', '-'])) { | ||
return colon.unmatched({ | ||
@@ -461,3 +461,3 @@ reason: 'unexpected-token', | ||
} | ||
if (!weekSign.match('W')) { | ||
if (!weekSign.matches('W')) { | ||
return weekSign.unmatched({ | ||
@@ -522,3 +522,3 @@ reason: 'unexpected-token', | ||
} | ||
return NaN; | ||
return Number.NaN; | ||
} |
@@ -13,7 +13,7 @@ import { log } from '../../debug.js'; | ||
// Start sign P | ||
/[^0-9T]?/, | ||
/[^\dT]?/, | ||
// date part | ||
/[^T]*/, | ||
// Time sign T | ||
/[^0-9]?/, | ||
/\D?/, | ||
// Time part | ||
@@ -30,3 +30,3 @@ /.*/, | ||
} | ||
if (!p.match('P', false)) { | ||
if (!p.matches('P', false)) { | ||
return p.unmatched({ | ||
@@ -42,3 +42,3 @@ reason: 'unexpected-token', | ||
} | ||
const [num, sign, extra] = TokenCollection.fromPatterns(d, [/[0-9]+/, /./]); | ||
const [num, sign, extra] = TokenCollection.fromPatterns(d, [/\d+/, /./]); | ||
if (!num) { | ||
@@ -48,3 +48,3 @@ return; | ||
log('Date part: "%s" => %O', d.value, { num, sign }); | ||
if (!num.match(/^[0-9]+$/)) { | ||
if (!num.matches(/^\d+$/)) { | ||
return num.unmatched({ | ||
@@ -62,3 +62,3 @@ reason: 'unexpected-token', | ||
} | ||
if (!sign.match('D', false)) { | ||
if (!sign.matches('D', false)) { | ||
return sign.unmatched({ | ||
@@ -82,3 +82,3 @@ reason: 'unexpected-token', | ||
} | ||
if (!t.match('T', false)) { | ||
if (!t.matches('T', false)) { | ||
return t.unmatched({ | ||
@@ -102,7 +102,7 @@ reason: 'unexpected-token', | ||
// Hour part | ||
/[0-9]+(\.[0-9]*)?[^0-9]?/, | ||
/\d+(\.\d*)?\D?/, | ||
// Minute part | ||
/[0-9]+(\.[0-9]*)?[^0-9]?/, | ||
/\d+(\.\d*)?\D?/, | ||
// Second part | ||
/[0-9]+(\.[0-9]*)?[^0-9]?/, | ||
/\d+(\.\d*)?\D?/, | ||
]); | ||
@@ -130,3 +130,3 @@ log('Time part: "%s" => %O', timeTokens.value, timeTokens); | ||
} | ||
const [num, dpfp, sign] = TokenCollection.fromPatterns(t, [/[0-9]+/, /(\.[0-9]*)?/, /[^0-9]+/]); | ||
const [num, dpfp, sign] = TokenCollection.fromPatterns(t, [/\d+/, /(\.\d*)?/, /\D+/]); | ||
if (!num) { | ||
@@ -136,3 +136,3 @@ continue; | ||
log('Time part (h|m|s): "%s" => %O', t.value, { num, dpfp, sign }); | ||
if (!num.match(/^[0-9]+$/)) { | ||
if (!num.matches(/^\d+$/)) { | ||
return num.unmatched({ | ||
@@ -145,3 +145,3 @@ reason: 'unexpected-token', | ||
if (dpfp && dpfp.value) { | ||
const [dp, fp] = TokenCollection.fromPatterns(dpfp, [/\./, /[0-9]+/]); | ||
const [dp, fp] = TokenCollection.fromPatterns(dpfp, [/\./, /\d+/]); | ||
if (!dp) { | ||
@@ -151,3 +151,3 @@ continue; | ||
log('Second fractional part (h|m|s): "%s" => %O', dpfp.value, { dp, fp }); | ||
if (!dp.match('.')) { | ||
if (!dp.matches('.')) { | ||
return dp.unmatched({ | ||
@@ -165,3 +165,3 @@ reason: 'unexpected-token', | ||
} | ||
if (!fp.match(/^[0-9]+$/)) { | ||
if (!fp.matches(/^\d+$/)) { | ||
return fp.unmatched({ | ||
@@ -173,3 +173,3 @@ reason: 'unexpected-token', | ||
} | ||
if (!(1 <= fp.length && fp.length <= 3)) { | ||
if (!(fp.length > 0 && fp.length <= 3)) { | ||
return fp.unmatched({ | ||
@@ -193,3 +193,3 @@ reason: { type: 'out-of-range-length-digit', gte: 1, lte: 3 }, | ||
} | ||
if (specified.has('M') && sign.match('H', false)) { | ||
if (specified.has('M') && sign.matches('H', false)) { | ||
return sign.unmatched({ | ||
@@ -201,5 +201,5 @@ reason: 'unexpected-token', | ||
} | ||
if (!sign.match(['H', 'M', 'S'], false) || | ||
(sign.match('H', false) && specified.has('H')) || | ||
(sign.match('M', false) && specified.has('M'))) { | ||
if (!sign.matches(['H', 'M', 'S'], false) || | ||
(sign.matches('H', false) && specified.has('H')) || | ||
(sign.matches('M', false) && specified.has('M'))) { | ||
return sign.unmatched({ | ||
@@ -232,7 +232,7 @@ reason: 'unexpected-token', | ||
// to represent a number of seconds. | ||
/[0-9]+/, | ||
/\d+/, | ||
// 3. If the duration time component scale specified is 1 (i.e. the units are seconds), | ||
// then, optionally, a U+002E FULL STOP character (.) followed by | ||
// one, two, or three ASCII digits, representing a fraction of a second. | ||
/(\.[0-9]*)?/, | ||
/(\.\d*)?/, | ||
// 4. Zero or more ASCII whitespace. | ||
@@ -242,3 +242,3 @@ /\s*/, | ||
// of the time unit used in the numeric part of the duration time component: | ||
/[^0-9]/, | ||
/\D/, | ||
// 6. Zero or more ASCII whitespace. | ||
@@ -252,3 +252,4 @@ /\s*/, | ||
log('Duration Component: "%s" => %O', component.value, component); | ||
const [, , dpfp, , unit] = component; | ||
const dpfp = component[2]; | ||
const unit = component[4]; | ||
const res = component.eachCheck(ws => { }, num => { | ||
@@ -279,3 +280,3 @@ if (!num || !num.value) { | ||
} | ||
const [, fp] = TokenCollection.fromPatterns(dpfp, [/\./, /[0-9]+/]); | ||
const [, fp] = TokenCollection.fromPatterns(dpfp, [/\./, /\d+/]); | ||
if (!fp || !fp.value) { | ||
@@ -287,3 +288,3 @@ return unmatched('', 'missing-token', { | ||
} | ||
if (!fp.match(/[0-9]+/)) { | ||
if (!fp.matches(/\d+/)) { | ||
return fp.unmatched({ | ||
@@ -295,3 +296,3 @@ reason: 'unexpected-token', | ||
} | ||
if (!(1 <= fp.length && fp.length <= 3)) { | ||
if (!(fp.length > 0 && fp.length <= 3)) { | ||
return fp.unmatched({ | ||
@@ -325,3 +326,3 @@ reason: { type: 'out-of-range-length-digit', gte: 1, lte: 3 }, | ||
} | ||
if (dpfp && dpfp.value && unit.match(['w', 'd', 'h', 'm'])) { | ||
if (dpfp && dpfp.value && unit.matches(['w', 'd', 'h', 'm'])) { | ||
return unit.unmatched({ | ||
@@ -333,3 +334,3 @@ reason: 'unexpected-token', | ||
} | ||
if (!unit.match(['w', 'd', 'h', 'm', 's'])) { | ||
if (!unit.matches(['w', 'd', 'h', 'm', 's'])) { | ||
return unit.unmatched({ | ||
@@ -336,0 +337,0 @@ reason: 'unexpected-token', |
@@ -15,19 +15,19 @@ import { log } from '../../debug.js'; | ||
// - | ||
/[^0-9]?/, | ||
/\D?/, | ||
// MM | ||
/[^-]*/, | ||
// - | ||
/[^0-9]?/, | ||
/\D?/, | ||
// DD | ||
/[^T\s]*/, | ||
/[^\sT]*/, | ||
// T \s | ||
/[^0-9]?/, | ||
/\D?/, | ||
// hh | ||
/[^:]*/, | ||
// : | ||
/[^0-9]?/, | ||
/\D?/, | ||
// mm | ||
/[^:Z+-]*/, | ||
/[^+:Z-]*/, | ||
// :ss.sss | ||
/(:[^Z+-]*)?/, | ||
/(:[^+Z-]*)?/, | ||
// time-zone | ||
@@ -41,3 +41,3 @@ /.*/, | ||
} | ||
const secondTokens = TokenCollection.fromPatterns(second, [/:?/, /[0-9]*/, /\.?/, /[0-9]*/]); | ||
const secondTokens = TokenCollection.fromPatterns(second, [/:?/, /\d*/, /\.?/, /\d*/]); | ||
log('Second Part: "%s" => %O', secondTokens.value, secondTokens); | ||
@@ -44,0 +44,0 @@ const res = secondTokens.eachCheck(datetimeTokenCheck.colon, datetimeTokenCheck.second, datetimeTokenCheck.decimalPointOrEnd, datetimeTokenCheck.secondFractionalPart); |
@@ -13,25 +13,25 @@ import { log } from '../../debug.js'; | ||
// - | ||
/[^0-9]?/, | ||
/\D?/, | ||
// MM | ||
/[^-]*/, | ||
// - | ||
/[^0-9]?/, | ||
/\D?/, | ||
// DD | ||
/[^T\s]*/, | ||
/[^\sT]*/, | ||
// T | ||
/[^0-9]?/, | ||
/\D?/, | ||
// hh | ||
/[^:]*/, | ||
// : | ||
/[^0-9]?/, | ||
/\D?/, | ||
// mm | ||
/[^:]*/, | ||
// : | ||
/[^0-9]?/, | ||
/\D?/, | ||
// ss | ||
/[^.]*/, | ||
// . | ||
/[^0-9]?/, | ||
/\D?/, | ||
// sss | ||
/.[0-9]*/, | ||
/.\d*/, | ||
]); | ||
@@ -54,25 +54,25 @@ log('Local Date and Time: "%s" => %O', tokens.value, tokens); | ||
// - | ||
/[^0-9]?/, | ||
/\D?/, | ||
// MM | ||
/[^-]*/, | ||
// - | ||
/[^0-9]?/, | ||
/\D?/, | ||
// DD | ||
/[^T]*/, | ||
// T | ||
/[^0-9]?/, | ||
/\D?/, | ||
// hh | ||
/[^:]*/, | ||
// : | ||
/[^0-9]?/, | ||
/\D?/, | ||
// mm | ||
/[^:]*/, | ||
// : | ||
/[^0-9]?/, | ||
/\D?/, | ||
// ss | ||
/[^.]*/, | ||
// . | ||
/[^0-9]?/, | ||
/\D?/, | ||
// sss | ||
/.[0-9]*/, | ||
/.\d*/, | ||
]); | ||
@@ -91,3 +91,4 @@ log('Normalized Local Date and Time: "%s" => %O', tokens.value, tokens); | ||
*/ | ||
const [, , , , , , , , , , second, , fp] = tokens; | ||
const second = tokens[10]; | ||
const fp = tokens[12]; | ||
if (!second || !fp) { | ||
@@ -94,0 +95,0 @@ log('Failed: %O', res); |
@@ -9,3 +9,3 @@ import { log } from '../../debug.js'; | ||
log('CHECK: month-string'); | ||
const tokens = TokenCollection.fromPatterns(value, [/[^-]*/, /[^0-9]?/, /.[0-9]*/]); | ||
const tokens = TokenCollection.fromPatterns(value, [/[^-]*/, /\D?/, /.\d*/]); | ||
log('Month: "%s" => %O', tokens.value, tokens); | ||
@@ -12,0 +12,0 @@ const res = tokens.eachCheck(datetimeTokenCheck.year, datetimeTokenCheck.hyphen, datetimeTokenCheck.month, datetimeTokenCheck.extra); |
@@ -13,13 +13,13 @@ import { log } from '../../debug.js'; | ||
// : | ||
/[^0-9]?/, | ||
/\D?/, | ||
// mm | ||
/[^:]*/, | ||
// : | ||
/[^0-9]?/, | ||
/\D?/, | ||
// ss | ||
/[^.]*/, | ||
// . | ||
/[^0-9]?/, | ||
/\D?/, | ||
// sss | ||
/.[0-9]*/, | ||
/.\d*/, | ||
]); | ||
@@ -26,0 +26,0 @@ log('Time: "%s" => %O', tokens.value, tokens); |
@@ -16,9 +16,9 @@ import { log } from '../../debug.js'; | ||
// Z + - | ||
/[^0-9]?/, | ||
/\D?/, | ||
// hh | ||
/[^:]{0,2}/, | ||
// : | ||
/[^0-9]?/, | ||
/\D?/, | ||
// mm | ||
/.[0-9]*/, | ||
/.\d*/, | ||
]); | ||
@@ -37,3 +37,3 @@ log('Time-zone Part: "%s" => %O', value, zoneTokens); | ||
} | ||
if (sign.match('Z')) { | ||
if (sign.matches('Z')) { | ||
if (tail.value) { | ||
@@ -46,3 +46,3 @@ return (tail[0]?.unmatched({ | ||
} | ||
if (!sign.match(['+', '-'])) { | ||
if (!sign.matches(['+', '-'])) { | ||
return sign.unmatched({ | ||
@@ -61,3 +61,3 @@ reason: 'unexpected-token', | ||
} | ||
if (!colon.match(':')) { | ||
if (!colon.matches(':')) { | ||
return colon.unmatched({ | ||
@@ -64,0 +64,0 @@ reason: 'unexpected-token', |
@@ -15,5 +15,5 @@ import { log } from '../../debug.js'; | ||
// W | ||
/[^0-9]?/, | ||
/\D?/, | ||
// ww | ||
/.[0-9]*/, | ||
/.\d*/, | ||
]); | ||
@@ -20,0 +20,0 @@ log('Week: "%s" => %O', tokens.value, tokens); |
@@ -13,5 +13,5 @@ import { log } from '../../debug.js'; | ||
// - | ||
/[^0-9]?/, | ||
/\D?/, | ||
// DD | ||
/.[0-9]*/, | ||
/.\d*/, | ||
]); | ||
@@ -18,0 +18,0 @@ log('Yearless Date: "%s" => %O', tokens.value, tokens); |
@@ -19,10 +19,10 @@ /** | ||
} | ||
catch (e) { | ||
if (e && typeof e === 'object' && 'code' in e) { | ||
// @ts-ignore | ||
if (e.code === 'ERR_INVALID_URL') { | ||
return false; | ||
} | ||
catch (error) { | ||
if (error && | ||
typeof error === 'object' && | ||
'code' in error && // @ts-ignore | ||
error.code === 'ERR_INVALID_URL') { | ||
return false; | ||
} | ||
throw e; | ||
throw error; | ||
} | ||
@@ -29,0 +29,0 @@ return true; |
{ | ||
"name": "@markuplint/types", | ||
"version": "4.0.0-alpha.3", | ||
"version": "4.0.0-alpha.4", | ||
"description": "Type declaration and value checker", | ||
@@ -28,6 +28,5 @@ "repository": "git@github.com:markuplint/markuplint.git", | ||
"dependencies": { | ||
"@types/bcp-47": "^2.0.0", | ||
"@types/css-tree": "^2.3.2", | ||
"@types/debug": "^4.1.9", | ||
"@types/whatwg-mimetype": "3.0.0", | ||
"@types/css-tree": "^2.3.3", | ||
"@types/debug": "^4.1.10", | ||
"@types/whatwg-mimetype": "3.0.1", | ||
"bcp-47": "^2.1.0", | ||
@@ -37,6 +36,6 @@ "css-tree": "^2.3.1", | ||
"leven": "^4.0.0", | ||
"type-fest": "^4.3.1", | ||
"type-fest": "^4.5.0", | ||
"whatwg-mimetype": "^3.0.0" | ||
}, | ||
"gitHead": "380836f7adc1ff7e8eaf9d869e68d29eee8f3b7e" | ||
"gitHead": "991b3aef77fde42c79343ee8c807257a35c589d7" | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
9
5685
224606
+ Added@types/whatwg-mimetype@3.0.1(transitive)
- Removed@types/bcp-47@^2.0.0
- Removed@types/bcp-47@2.0.4(transitive)
- Removed@types/whatwg-mimetype@3.0.0(transitive)
Updated@types/css-tree@^2.3.3
Updated@types/debug@^4.1.10
Updated@types/whatwg-mimetype@3.0.1
Updatedtype-fest@^4.5.0