2024-05-14 09:00:05 +02:00
|
|
|
/**
|
|
|
|
|
* Regular expressions for matching various strings.
|
|
|
|
|
* @module federation/schemas/regex
|
|
|
|
|
* @see module:federation/schemas/base
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
import {
|
|
|
|
|
charIn,
|
2024-08-25 15:47:03 +02:00
|
|
|
charNotIn,
|
2024-05-14 09:00:05 +02:00
|
|
|
createRegExp,
|
|
|
|
|
digit,
|
|
|
|
|
exactly,
|
|
|
|
|
global,
|
|
|
|
|
letter,
|
2024-08-25 15:47:03 +02:00
|
|
|
not,
|
2024-05-14 09:00:05 +02:00
|
|
|
oneOrMore,
|
|
|
|
|
} from "magic-regexp";
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Regular expression for matching emojis.
|
|
|
|
|
*/
|
2024-05-14 10:35:25 +02:00
|
|
|
export const emojiRegex: RegExp = createRegExp(
|
2024-08-25 15:47:03 +02:00
|
|
|
exactly(
|
|
|
|
|
exactly(not.letter.or(not.digit).or(charNotIn("_-"))).times(1),
|
|
|
|
|
oneOrMore(letter.or(digit).or(charIn("_-"))),
|
|
|
|
|
exactly(not.letter.or(not.digit).or(charNotIn("_-"))).times(1),
|
|
|
|
|
),
|
|
|
|
|
[global],
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
export const semverRegex: RegExp = new RegExp(
|
|
|
|
|
/^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/gm,
|
2024-05-14 09:00:05 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Regular expression for matching an extension_type
|
2024-08-25 15:47:03 +02:00
|
|
|
* @example pub.versia:custom_emojis/Emoji
|
2024-05-14 09:00:05 +02:00
|
|
|
*/
|
2024-05-14 10:35:25 +02:00
|
|
|
export const extensionTypeRegex: RegExp = createRegExp(
|
2024-05-14 09:00:05 +02:00
|
|
|
// org namespace, then colon, then alphanumeric/_/-, then extension name
|
|
|
|
|
exactly(
|
|
|
|
|
oneOrMore(exactly(letter.lowercase.or(digit).or(charIn("_-.")))),
|
|
|
|
|
exactly(":"),
|
|
|
|
|
oneOrMore(exactly(letter.lowercase.or(digit).or(charIn("_-")))),
|
|
|
|
|
exactly("/"),
|
|
|
|
|
oneOrMore(exactly(letter.or(digit).or(charIn("_-")))),
|
|
|
|
|
),
|
|
|
|
|
);
|
2024-08-25 15:47:03 +02:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Regular expression for matching an extension
|
|
|
|
|
* @example pub.versia:custom_emojis
|
|
|
|
|
*/
|
|
|
|
|
export const extensionRegex: RegExp = createRegExp(
|
|
|
|
|
// org namespace, then colon, then alphanumeric/_/-, then extension name
|
|
|
|
|
exactly(
|
|
|
|
|
oneOrMore(exactly(letter.lowercase.or(digit).or(charIn("_-.")))),
|
|
|
|
|
exactly(":"),
|
|
|
|
|
oneOrMore(exactly(letter.lowercase.or(digit).or(charIn("_-")))),
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
export const isISOString = (val: string | Date) => {
|
|
|
|
|
const d = new Date(val);
|
|
|
|
|
return !Number.isNaN(d.valueOf()) && d.toISOString() === val;
|
|
|
|
|
};
|