Skip to content

Commit

Permalink
Small (breaking) compatibility changes and bump version to v23.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
rkalis committed Nov 7, 2023
1 parent fa887c5 commit 8e47f6b
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
5 changes: 4 additions & 1 deletion index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
export {
default as chains,
getChain,
getChainById,
getChainByName,
allChains,
Chain,
ChainId,
ChainName,
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@revoke.cash/chains",
"version": "22.0.0",
"version": "23.0.0",
"description": "Helper module for getting EVM chains info.",
"author": "Revoke.cash",
"contributors": [
Expand Down
14 changes: 6 additions & 8 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,37 +1,35 @@
import { Chain, Chains } from './types'
import { chains } from './chains'
import { ChainId } from './enums'
export { NativeCurrency, Explorer, Parent } from './types'
export { ChainName, ChainId } from './enums'
export { chains, Chain, Chains }
export { Chain, Chains }

/**
* Get a chain by its `id`.
* @param id - The `id` of the chain
* @returns The `Chain` object associated with the chain `id`
*/
const getById = (id: number): Chain | undefined => chains[id]
export const getChainById = (id: number): Chain | undefined => chains[id]

/**
* Get a chain by its `name`.
* @param name - The `name` of the chain
* @returns The `Chain` object associated with the chain `name`
*/
const getByName = (name: string): Chain | undefined =>
export const getChainByName = (name: string): Chain | undefined =>
Object.values(chains).find(chain => chain.name === name) || {}

/**
* Get a chain by its `id` or by its `name`.
* @param idOrName - The name or id of the chain
* @returns The `Chain` object associated with the `id` or `name`
*/
const get = (idOrName: string | number): Chain | undefined =>
typeof idOrName === 'number' ? getById(idOrName) : getByName(idOrName)
export const getChain = (idOrName: string | number): Chain | undefined =>
typeof idOrName === 'number' ? getChainById(idOrName) : getChainByName(idOrName)

/**
* Gets the entire `chains` object
* @returns An object containing all chains
*/
const all = (): Chains => chains
export const allChains = (): Chains => chains

export default { getById, getByName, get, all }

0 comments on commit 8e47f6b

Please sign in to comment.