Skip to content

Commit 49a4fdf

Browse files
committed
Initial commit
0 parents  commit 49a4fdf

21 files changed

Lines changed: 11026 additions & 0 deletions

.editorconfig

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# http://editorconfig.org
2+
3+
root = true
4+
5+
[*]
6+
charset = utf-8
7+
indent_style = space
8+
indent_size = 2
9+
end_of_line = lf
10+
insert_final_newline = true
11+
trim_trailing_whitespace = true
12+
13+
[*.md]
14+
insert_final_newline = false
15+
trim_trailing_whitespace = false

.gitignore

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
node_modules
2+
*.log
3+
.idea
4+
.vscode
5+
.DS_Store
6+
lib
7+
dist
8+
.rollup.cache
9+
.env
10+
!.env.example
11+
.*.env
12+
!.*.example.env
13+
tsconfig.tsbuildinfo
14+
.tsconfig.tsbuildinfo
15+
.tsbuildinfo
16+
____*

README.md

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# Unique utils
2+
3+
Package containing some low-level utils useful for everyday coding with Substrate and web3.
4+
5+
Provides neat and no-extra-dependencies tools to interact with Substrate and Ethereum addresses,
6+
strings (utf8 and utf16 encoding/decoding) and more.
7+
8+
For example, Address doesn't depend on Polkadot libraries, WASM, and even ethers.js.
9+
Minified version of address.js weights just 8 Kb with all hashing and crypto being bundled in.
10+
And there is no WASM at all when you need just check or convert an address.
11+
12+
Zero dependencies. Definitely typed. Works in browser and Node.js.
13+
14+
## Address
15+
16+
Address object provide several tools for Substrate and Ethereum addresses.
17+
Like checking, validating, mirroring, boxing and unboxing, formatting and capitalizing.
18+
19+
```ts
20+
import {Address} from '@unique-nft/utils'
21+
// or
22+
// import {Address} from '@unique-nft/utils/address'
23+
// or
24+
// import {mirror} from '@unique-nft/utils/address'
25+
26+
27+
Address.is.ethereumAddressObject({Ethereum: '0xf8cC75F76d46c3b1c5F270Fe06c8FFdeAB8E5eaB'}) //true
28+
Address.validate.substrateAddress('5HgvUDiRm5yjRSrrG9B6q6km7KLzkXMxvFLHPZpA13pmwCJQ') // true
29+
Address.mirror.substrateToEthereum('5HgvUDiRm5yjRSrrG9B6q6km7KLzkXMxvFLHPZpA13pmwCJQ') // 0xf8cC75F76d46c3b1c5F270Fe06c8FFdeAB8E5eaB
30+
Address.collection.idToAddress(105) // '0x17c4e6453CC49aaaAEAcA894e6d9683E00000069'
31+
Address.nesting.idsToAddress(10, 5) // '0xf8238CcffF8eD887463Fd5e00000000a00000005'
32+
Address.to.substrateNormalizedOrMirrorIfEthereum('0xf8cC75F76d46c3b1c5F270Fe06c8FFdeAB8E5eaB') // '5GwWnwbYRzwvcyAmQqCBB4h5JNspv8xPxpUm77wXbooxS3t5'
33+
```
34+
35+
And much more! Mirroring, packing/unpacking CrossAccountId in different formats, guessing address types and more.
36+
37+
Also, encoding, decoding and formatting Substrate addresses without WASM or any heavy libraries.
38+
39+
**[Full documentation for the Address util](https://github.com/fend25/unique_utils/blob/master/docs/Address.md)**
40+
41+
## StringUtils
42+
43+
StringUtils provides tools to encode/decode UTF-8 and UTF-16 strings and to pack/unpack hex strings.
44+
45+
```ts
46+
import {Utf8, Utf16, HexString} from '@unique-nft/utils/string'
47+
// or import just all in one entry point:
48+
// import {StringUtils} from '@unique-nft/utils'
49+
50+
Utf8.stringToU8a('a 🌷') // Uint8Array [97, 32, 240, 159, 140, 183]
51+
Utf8.u8aToString([97, 32, 240, 159, 140, 183]) // "a 🌷"
52+
Utf8.lengthInBytes('a 🌷') // 6
53+
54+
Utf16.stringToU16a('a 🌷') // Uint16Array [97, 32, 55356, 57143]
55+
Utf16.u16aToString([97, 32, 55356, 57143]) // "a 🌷"
56+
Utf16.lengthInBytes('a 🌷') // 4
57+
58+
HexString.toU8a('0x6120f09f8cb7') // Uint8Array [97, 32, 240, 159, 140, 183]
59+
HexString.fromU8a([97, 32, 240, 159, 140, 183]) // "0x6120f09f8cb7"
60+
61+
// even super complex strings!
62+
Utf8.lengthInBytes('👨🏼‍👩🏼‍👧🏼‍👧🏼') // 41
63+
Utf16.lengthInBytes('👨🏼‍👩🏼‍👧🏼‍👧🏼') // 19
64+
```
65+
66+
**[Full documentation for the UTF and hex string helpers](https://github.com/fend25/utf-helpers#readme)**

configs/.release-it.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
const config = {
2+
hooks: {
3+
"before:init": ["npm run testrun"],
4+
// "after:my-plugin:bump": "./bin/my-script.sh",
5+
"after:bump": "npm run build",
6+
"after:git:release": "echo After git push, before github release",
7+
"after:release": "echo Successfully released ${name} v${version}."
8+
},
9+
npm: {
10+
publishConfig: {
11+
access: "public",
12+
},
13+
publishPath: "./dist",
14+
},
15+
// git: {
16+
// requireCleanWorkingDir: false,
17+
// changelog: 'git log --pretty=format:"* %s (%h)" ${from}...${to}',
18+
// commitMessage: 'chore: release v${version}',
19+
// requireBranch: 'master',
20+
// tagName: "v${version}",
21+
// },
22+
github: {
23+
release: false,
24+
releaseName: "Release v${version}",
25+
preRelease: true,
26+
autoGenerate: true,
27+
tokenRef: "GITHUB_TOKEN",
28+
assets: null,
29+
},
30+
}
31+
32+
module.exports = config

configs/.release.example.env

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
GITHUB_TOKEN="f941e0..."

configs/tsup.config.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import {defineConfig} from 'tsup'
2+
3+
export default defineConfig([
4+
{
5+
entry: {
6+
index: "src/index.ts",
7+
string: "src/StringUtils/index.ts",
8+
address: "src/Address/index.ts",
9+
},
10+
format: [
11+
"esm",
12+
"cjs"
13+
],
14+
target: 'es2020',
15+
dts: true,
16+
splitting: false,
17+
sourcemap: true,
18+
// noExternal: [/^base/, /\^@noble/],
19+
},
20+
])

0 commit comments

Comments
 (0)