From 8e47f6b503e7bb02b545f08d0d8c3c1b39b7b0c0 Mon Sep 17 00:00:00 2001 From: Rosco Kalis Date: Tue, 7 Nov 2023 16:59:57 +0100 Subject: [PATCH] Small (breaking) compatibility changes and bump version to v23.0.0 --- index.ts | 5 ++++- package.json | 2 +- src/index.ts | 14 ++++++-------- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/index.ts b/index.ts index 9660202..444bc32 100644 --- a/index.ts +++ b/index.ts @@ -1,5 +1,8 @@ export { - default as chains, + getChain, + getChainById, + getChainByName, + allChains, Chain, ChainId, ChainName, diff --git a/package.json b/package.json index 066dac7..4e44778 100644 --- a/package.json +++ b/package.json @@ -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": [ diff --git a/src/index.ts b/src/index.ts index 335d850..487aafa 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,23 +1,22 @@ 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) || {} /** @@ -25,13 +24,12 @@ const getByName = (name: string): Chain | undefined => * @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 }