What is @adraffy/ens-normalize?
@adraffy/ens-normalize is an npm package designed to normalize Ethereum Name Service (ENS) names. It ensures that ENS names are in a consistent format, which is crucial for avoiding ambiguities and ensuring compatibility across different systems.
What are @adraffy/ens-normalize's main functionalities?
Normalization
This feature allows you to normalize an ENS name to ensure it is in a consistent format. The code sample demonstrates how to normalize the ENS name 'example.eth'.
const { normalize } = require('@adraffy/ens-normalize');
const normalized = normalize('example.eth');
console.log(normalized);
Validation
This feature allows you to validate an ENS name to check if it conforms to the expected format. The code sample demonstrates how to validate the ENS name 'example.eth'.
const { validate } = require('@adraffy/ens-normalize');
const isValid = validate('example.eth');
console.log(isValid);
Unicode Handling
This feature allows you to convert Punycode-encoded ENS names to their Unicode equivalents. The code sample demonstrates how to convert the Punycode-encoded ENS name 'xn--exmple-cua.eth' to its Unicode equivalent.
const { toUnicode } = require('@adraffy/ens-normalize');
const unicodeName = toUnicode('xn--exmple-cua.eth');
console.log(unicodeName);
Other packages similar to @adraffy/ens-normalize
eth-ens-namehash
The eth-ens-namehash package is another tool for generating ENS namehashes. It includes some basic normalization features but is primarily focused on the namehashing process. It is less comprehensive in normalization compared to @adraffy/ens-normalize.
punycode
The punycode package provides utilities for converting between Unicode and Punycode, which is useful for handling internationalized domain names (IDNs). While it does not specifically target ENS names, it can be used in conjunction with other packages to handle Unicode normalization.
ens-normalize.js
1-file, 0-dependancy Compact ES6 Ethereum Name Service (ENS) Name Normalizer.
Demo
import {ens_normalize} from '@adraffy/ens-normalize';
let normalized = ens_normalize('🚴♂️.eth');
ens_normalize('_')
ens_normalize('_', true)
Build Notes
- Clone the repo to access
test/
. These files are not included in the npm version. - The actual source is in
test/ens-normalize.src.js
. Use npm run render
after modification to build a new ens-normalize.js
. - Use
npm run dist
to build the minified version.