stash
This commit is contained in:
parent
f46eff65fd
commit
d56784eb8d
8 changed files with 335 additions and 93 deletions
|
|
@ -204,6 +204,22 @@ export function deserializeShortId(ints) {
|
|||
return schema.interpret(fieldValues)
|
||||
}
|
||||
|
||||
export function encodeDomainQualifiedShortId(domain, ints) {
|
||||
return domain + ':' + encodeShortId(ints)
|
||||
}
|
||||
|
||||
export function decodeDomainQualifiedShortId(text) {
|
||||
const i = text.indexOf(':~')
|
||||
if (i === -1) {
|
||||
throw new Error("not a domain-qualified short id: expected '<domain>:~<token>'")
|
||||
}
|
||||
return {domain: text.slice(0, i), token: text.slice(i + 1), ints: decodeShortId(text.slice(i + 1))}
|
||||
}
|
||||
|
||||
export function isDomainQualifiedShortId(text) {
|
||||
return typeof text === 'string' && /^[^\s~]+:~/.test(text)
|
||||
}
|
||||
|
||||
export function serializeShortId({kind, ...fieldValues}) {
|
||||
const entry = Object.entries(SCHEMAS).find(([, s]) => s.name === kind)
|
||||
if (!entry) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue