UNPKG

@kodex-data/prototypes

Version:

A library of TypeScript prototypes that extend built-in types in JavaScript, providing additional functionality to make development easier and more efficient. This library includes prototypes for working with big numbers, Ethereum Virtual Machine (EVM) fu

200 lines (199 loc) 6.49 kB
import type { CIDs } from './types'; import { CID } from 'multiformats'; declare global { type CIDVersions = 'v0' | 'v1' | 'hex'; type SupportedCidsVersions = CIDVersions; interface String { /** * Parses given string as CID Instance * @date 8/17/2022 - 5:31:45 PM * * @returns {CID} */ parseCID(version?: CIDVersions): CID; /** * checks if given string is in valid ipfs hash format * @date 8/17/2022 - 5:32:13 PM * * @returns {boolean} */ isCID(version?: CIDVersions): boolean; /** * checks CID version of given string * @date 8/17/2022 - 5:32:32 PM * * @returns {CIDVersions} */ getCIDVersion(): CIDVersions; /** * Formats given string as all CID Version * @date 8/17/2022 - 5:32:49 PM * * @returns {CIDs} */ getCIDs(): CIDs; findCIDs(parse: true): CID[]; findCIDs(parse: false | undefined): string[]; findCIDs(): string[]; } } declare module 'multiformats' { interface CID { /** * Formats given CID as all CID Version * @date 8/17/2022 - 5:32:49 PM * * @returns {CIDs} */ getCIDs(): CIDs; } } /** * Regular expression pattern for matching CID v1. * @date 8.3.2023 - 09:26:36 * * @type {RegExp} */ export declare const CID_V1: RegExp; /** * Regular expression pattern for matching CID v0. * @date 8.3.2023 - 09:26:36 * * @type {RegExp} */ export declare const CID_V0: RegExp; /** * Returns an array of all CIDs that match the provided regular expression pattern in the given text. * @date 8.3.2023 - 09:27:36 * * @export * @param {RegExp} regex - Regular expression pattern to match CIDs. * @param {string} txt - Text to search for CIDs. * @returns {string[]} - An array of CIDs that match the provided regular expression pattern. */ export declare function matcher(regex: RegExp, txt: string): string[]; /** * Extracts IPFS hashes from the provided URI * @date 8.3.2023 - 09:35:03 * * @export * @param {string} uri - The URI to extract IPFS hashes from * @returns {string[]} An array of IPFS hashes */ export declare function extractIpfsHashes(uri: string): string[]; /** * Extracts the first IPFS hash from the provided URI * @date 8.3.2023 - 09:35:42 * * @export * @param {string} uri - The URI to extract the IPFS hash from * @returns {string} The first IPFS hash in the URI, or undefined if no hash was found */ export declare function extractIpfsHash(uri: string): string; /** * Finds all Content Identifiers (CIDs) in the provided string * @date 8.3.2023 - 09:36:26 * * @export * @param {string} txt - The string to search for CIDs in * @returns {string[]} An array of unique CIDs found in the string */ export default function findCIDs(txt: string): string[]; /** * Determines whether the provided string is a hexadecimal string * @date 8.3.2023 - 09:37:02 * * @export * @param {string} input - The string to test * @returns {boolean} True if the string is hexadecimal, false otherwise */ export declare function isHEX(input: string): boolean; /** * Converts the provided string to a hexadecimal string * @date 8.3.2023 - 09:37:55 * * @export * @param {string} input - The string to convert * @returns {string} The hexadecimal representation of the input string */ export declare function toHEX(input: string): string; /** * Converts the provided hexadecimal string to a regular string * @date 8.3.2023 - 09:38:00 * * @export * @param {string} input - The hexadecimal string to convert * @returns {string} The regular string representation of the input hexadecimal string */ export declare function fromHEX(input: string): string; /** * Determines whether the provided string is a CID version 0 (v0) hash * @date 8.3.2023 - 09:39:15 * * @export * @param {string} query - The string to test * @returns {boolean} True if the string is a v0 CID hash, false otherwise */ export declare function isV0(query: string): boolean; /** * Determines whether the provided string is a CID version 1 (v1) hash * @date 8.3.2023 - 09:39:15 * * @export * @param {string} query - The string to test * @returns {boolean} True if the string is a v1 CID hash, false otherwise */ export declare function isV1(query: string): boolean; /** * Determines whether the provided string is a hexadecimal CID hash * @date 8.3.2023 - 09:40:43 * * @export * @param {string} input - The string to test * @returns {boolean} True if the string is a hexadecimal CID hash, false otherwise */ export declare function isHexCID(input: string): boolean; /** * Determines whether the provided string is a valid CID hash * @date 8.3.2023 - 09:41:12 * * @export * @param {string} input - The string to test * @param {?CIDVersions} [version] - The CID version to check for (optional) * @returns {boolean} True if the string is a valid CID hash, false otherwise */ export declare function isCID(input: string, version?: CIDVersions): boolean; /** * Gets the CID version of the provided CID hash * @date 8.3.2023 - 09:41:52 * * @export * @param {string} input - The CID hash to get the version of * @returns {CIDVersions} The version of the CID hash ('v0', 'v1', or 'hex') * @throws {Error} An error if the input string is not a valid CID hash */ export declare function getCIDVersion(input: string): CIDVersions; /** * Returns an object with the string representation of the input CID in various versions. * @date 8.3.2023 - 09:43:37 * * @export * @param {CID} cid - The input CID to be converted to various versions. * @returns {{ v0: string, v1: string, hex: string }} - Object containing string representation of the input CID in various versions */ export declare function getCIDs(cid: CID): { v0: string; v1: string; hex: string; }; /** * Parses the input string into a CID object. * @date 8.3.2023 - 09:44:50 * * @export * @param {string} input - The input string to be parsed into a CID object. * @param {?CIDVersions} [version] - The version of CID to be parsed. Defaults to 'v1'. * @throws {Error} If parsing the input string fails, throws an error with message "error parsing content hash". * @returns {CID} - The CID object obtained from parsing the input string. */ export declare function parseCID(input: string, version?: CIDVersions): CID;