-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove for loop in favor of single pass using Set
- Loading branch information
1 parent
c7ad145
commit a969ff2
Showing
3 changed files
with
21 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
packages/payloadset/packages/xns/plugins/record/src/validation/name/lib/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './removeDisallowedCharacters.ts' |
18 changes: 18 additions & 0 deletions
18
...loadset/packages/xns/plugins/record/src/validation/name/lib/removeDisallowedCharacters.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { DisallowedModuleIdentifierCharacters } from '@xyo-network/module-model' | ||
|
||
const DISALLOWED_CHARACTERS = new Set(Object.keys(DisallowedModuleIdentifierCharacters)) | ||
|
||
/** | ||
* Iterates over a string removing disallowed characters | ||
* @param xnsName The XNS name to remove disallowed characters from | ||
* @returns The XNS name with disallowed characters removed | ||
*/ | ||
export const removeDisallowedCharacters = (xnsName: string): string => { | ||
let result = '' | ||
for (const char of xnsName) { | ||
if (!DISALLOWED_CHARACTERS.has(char)) { | ||
result += char | ||
} | ||
} | ||
return result | ||
} |