Skip to content

Commit

Permalink
extract one off code to /lib and types to /types
Browse files Browse the repository at this point in the history
  • Loading branch information
jonesmac committed Sep 4, 2024
1 parent 30af464 commit 35fe32a
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from './name/index.ts'
export * from './validation/index.ts'
Original file line number Diff line number Diff line change
@@ -1,24 +1,13 @@
import { assertEx } from '@xylabs/assert'
import { isHash } from '@xylabs/hex'
import type { Promisable } from '@xylabs/promise'
import { DisallowedModuleIdentifierCharacters } from '@xyo-network/module-model'
import type { Payload } from '@xyo-network/payload-model'
import type { DomainFields, TopLevelDomain } from '@xyo-network/xns-record-payload-plugins'
import { DomainSchema } from '@xyo-network/xns-record-payload-plugins'

import { XnsNamePublicValidators } from '../validation/index.ts'

export type ValidSourceTypes = 'xnsName' | 'hash' | null

// Escaping special regex characters in the disallowed keys
const escapeRegex = (str: string) => str.replaceAll(/[$()*+.?[\\\]^{|}]/g, String.raw`\$&`)

// Escaping and then creating the regex
const disallowedCharsPattern = Object.keys(DisallowedModuleIdentifierCharacters)
.map(escapeRegex)
.join('')
// Creating the final regex
const REMOVE_DISALLOWED_CHARS = new RegExp(`[${disallowedCharsPattern}]`, 'g')
import { REMOVE_DISALLOWED_CHARS } from './lib/index.ts'
import type { ValidSourceTypes } from './types/index.ts'

export class XnsNameHelper {
static ValidTLDs = ['.xyo'] as const
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './Name.ts'
export * from './types/index.ts'
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { DisallowedModuleIdentifierCharacters } from '@xyo-network/module-model'

// Escaping special regex characters in the disallowed keys
export const escapeRegex = (str: string) => str.replaceAll(/[$()*+.?[\\\]^{|}]/g, String.raw`\$&`)

// Escaping and then creating the regex
export const disallowedCharsPattern = Object.keys(DisallowedModuleIdentifierCharacters)
.map(escapeRegex)
.join('')

// Creating the final regex
export const REMOVE_DISALLOWED_CHARS = new RegExp(`[${disallowedCharsPattern}]`, 'g')
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './RegexHelpers.ts'
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export type ValidSourceTypes = 'xnsName' | 'hash' | null
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './ValidSources.ts'

0 comments on commit 35fe32a

Please sign in to comment.