2023-06-11 02:59:33 +00:00
|
|
|
import { customAlphabet, urlAlphabet } from 'nanoid'
|
|
|
|
|
|
|
|
import * as types from './types'
|
|
|
|
|
2023-06-14 04:39:19 +00:00
|
|
|
export function extractJSONObjectFromString(text: string): string | undefined {
|
|
|
|
return text.match(/\{(.|\n)*\}/gm)?.[0]
|
|
|
|
}
|
2023-05-24 06:15:59 +00:00
|
|
|
|
2023-06-14 04:39:19 +00:00
|
|
|
export function extractJSONArrayFromString(text: string): string | undefined {
|
|
|
|
return text.match(/\[(.|\n)*\]/gm)?.[0]
|
|
|
|
}
|
2023-06-07 01:03:39 +00:00
|
|
|
|
2023-06-14 04:39:19 +00:00
|
|
|
export function sleep(ms: number) {
|
|
|
|
return new Promise((resolve) => setTimeout(resolve, ms))
|
|
|
|
}
|
2023-06-11 02:59:33 +00:00
|
|
|
|
|
|
|
export const defaultIDGeneratorFn: types.IDGeneratorFunction =
|
|
|
|
customAlphabet(urlAlphabet)
|
2023-06-14 04:39:19 +00:00
|
|
|
|
|
|
|
const taskNameRegex = /^[a-zA-Z_][a-zA-Z0-9_-]{0,63}$/
|
|
|
|
export function isValidTaskIdentifier(id: string): boolean {
|
|
|
|
return !!id && taskNameRegex.test(id)
|
|
|
|
}
|