ciam-commons
Advanced tools
Comparing version 1.3.0 to 1.4.1
export declare namespace Check { | ||
const objectIdRegex: RegExp; | ||
const discordIdRegex: RegExp; | ||
const flagRegex: RegExp; | ||
const strictFlagRegex: RegExp; | ||
function objectId(id: string, message?: string): void; | ||
function discordId(id: string, message?: string): void; | ||
function flag(flag: string, message?: string): void; | ||
@@ -7,0 +9,0 @@ function strictFlag(flag: string, message?: string): void; |
export var Check; | ||
(function (Check) { | ||
Check.objectIdRegex = /[a-f0-9]{24}/; | ||
Check.discordIdRegex = /\d{16,20}/; | ||
Check.flagRegex = /^(?:([a-z0-9]+|\?)(?:\.(?:[a-z0-9]+|\?))*(\.\*)?|\*)$/; | ||
@@ -11,2 +12,7 @@ Check.strictFlagRegex = /^[a-z0-9]+(\.[a-z0-9]+)*$/; | ||
Check.objectId = objectId; | ||
function discordId(id, message = 'Invalid discordId') { | ||
if (!id.match(Check.discordIdRegex)) | ||
throw new Error(`${message} "${id}"`); | ||
} | ||
Check.discordId = discordId; | ||
function flag(flag, message = 'Invalid permission flag') { | ||
@@ -13,0 +19,0 @@ if (!flag.match(Check.flagRegex)) |
{ | ||
"name": "ciam-commons", | ||
"version": "1.3.0", | ||
"version": "1.4.1", | ||
"description": "Common types and functions for CIAM", | ||
@@ -5,0 +5,0 @@ "scripts": { |
export namespace Check { | ||
export const objectIdRegex: RegExp = /[a-f0-9]{24}/; | ||
export const discordIdRegex: RegExp = /\d{16,20}/; | ||
export const flagRegex: RegExp = /^(?:([a-z0-9]+|\?)(?:\.(?:[a-z0-9]+|\?))*(\.\*)?|\*)$/; | ||
@@ -11,2 +12,6 @@ export const strictFlagRegex: RegExp = /^[a-z0-9]+(\.[a-z0-9]+)*$/; | ||
export function discordId(id: string, message: string = 'Invalid discordId') { | ||
if (!id.match(discordIdRegex)) throw new Error(`${message} "${id}"`); | ||
} | ||
export function flag(flag: string, message: string = 'Invalid permission flag') { | ||
@@ -13,0 +18,0 @@ if (!flag.match(flagRegex)) throw new Error(`${message} "${flag}"`); |
10586
255