Skip to content

Commit

Permalink
1.0.0: Chain updates + helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
taylorjdawson committed Jun 30, 2022
1 parent e898ed7 commit 9059f2a
Show file tree
Hide file tree
Showing 10 changed files with 4,284 additions and 651 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
chains.json
node_modules
dist
dist
test.ts
3 changes: 2 additions & 1 deletion index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ export {
ChainName,
NativeCurrency,
Explorer,
Parent
Parent,
chain
} from './src'
8 changes: 3 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "eth-chains",
"version": "0.4.0",
"version": "1.0.0",
"description": "Helper module for getting Ethereum chains info.",
"author": "Taylor Dawson",
"main": "dist/index.js",
Expand All @@ -11,15 +11,13 @@
],
"license": "WTFPL",
"scripts": {
"build": "tsc",
"build": "rm -r dist && tsc",
"generate": "ts-node src/build.ts",
"format": "prettier --write src/",
"prepack": "yarn build"
},
"dependencies": {
"got": "^11.8.2"
},
"devDependencies": {
"got": "^11.8.2",
"@types/node": "^14.14.37",
"@types/prettier": "^2.2.3",
"prettier": "^2.2.1",
Expand Down
9 changes: 6 additions & 3 deletions src/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { Options } from 'prettier'
import { Chain } from './types'
import { capitalize } from './helpers'
import prettierOptions from '../.prettierrc.json'
import { ENUM_KEY_OVERRIDES } from './constants'

const formatterOptions = {
...(prettierOptions as Options),
Expand All @@ -16,15 +17,15 @@ const formatterOptions = {
const getEnumKey = (chainName: string) => {
let enumKey = capitalize(chainName.replace(/\s/g, ''))
// If the key starts with a number or contains ',' or '.' then wrap it in quotes
enumKey = !!chainName.match(/^\d|[\-\.]/) ? `'${enumKey}'` : enumKey
enumKey = !!chainName.match(/^\d|[\-\.\()]/) ? `'${enumKey}'` : enumKey
return enumKey
}

const getBuildEnums = (chains: Chain[]) =>
chains
.reduce(
(enumStrings, chain, index, array) => {
const key = getEnumKey(chain.name)
const key = ENUM_KEY_OVERRIDES[chain.chainId] ?? getEnumKey(chain.name)
const tail = index === array.length - 1 ? ' }' : ', '
enumStrings[0] += `${key} = '${chain.name}'${tail}`
enumStrings[1] += `${key} = ${chain.chainId}${tail}`
Expand All @@ -49,7 +50,9 @@ const generateChainsFile = async () => {
'https://chainid.network/chains.json'
).json()

await generateEnumFile(chains)
await generateEnumFile(chains).catch(() => {
console.log('Error generating enum file')
})

const chainsJs = chains
.map(chain => `${chain.chainId}: ${inspect(chain, { depth: null })}`)
Expand Down
Loading

0 comments on commit 9059f2a

Please sign in to comment.