Socket
Socket
Sign inDemoInstall

metautil

Package Overview
Dependencies
0
Maintainers
1
Versions
54
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    metautil

Metarhia utilities


Version published
Weekly downloads
286
decreased by-52.73%
Maintainers
1
Created
Weekly downloads
 

Changelog

Source

[3.10.0][] - 2023-06-30

  • Implement DomainError
  • Improve Error class, add { cause, code }
  • Fix error handling in fetch

Readme

Source

Metarhia utilities

ci status snyk npm version npm downloads/month npm downloads license

Usage

  • Install: npm install metautil
  • Require: const metautil = require('metautil')

Async utilities

  • timeout(msec: number, signal?: AbortSignal): Promise<void>
  • delay(msec: number, signal?: AbortSignal): Promise<void>

Crypto utilities

  • cryptoRandom(): number
  • generateUUID(): string
  • generateKey(length: number, possible: string): string
  • crcToken(secret: string, key: string): string
  • generateToken(secret: string, characters: string, length: number): string
  • validateToken(secret: string, token: string): boolean
  • serializeHash(hash: Buffer, salt: Buffer): string
  • deserializeHash(phcString: string): HashInfo
  • hashPassword(password: string): Promise<string>
  • validatePassword(password: string, serHash: string): Promise<boolean>
  • md5(fileName: string): Promise<string>
  • getX509(cert: X509Certificate): Strings

Datetime utilities

  • duration(s: string | number): number
  • nowDate(date?: Date): string
  • nowDateTimeUTC(date?: Date, timeSep?: string): string
  • parseMonth(s: string): number
  • parseDay(s: string): number
  • parseEvery(s: string): Every
  • nextEvent(every: Every, date?: Date): number

Error utilities

  • Class Error
    • constructor(message: string, code: number)
  • isError(instance: object): boolean

HTTP utilities

  • parseHost(host?: string): string
  • parseParams(params: string): Cookies
  • parseCookies(cookie: string): Headers
  • parseRange(range: string): StreamRange

Network utilities

  • fetch(url: string, options?: FetchOptions): Promise<Response>
  • receiveBody(stream: IncomingMessage): Promise<Buffer | null>
  • ipToInt(ip?: string): number

Objects utilities

  • makePrivate(instance: object): object
  • protect(allowMixins: Strings, ...namespaces: Namespaces): void
  • jsonParse(buffer: Buffer): Dictionary | null
  • isHashObject(o: string | number | boolean | object): boolean
  • flatObject(source: Dictionary, fields: Strings): Dictionary
  • unflatObject(source: Dictionary, fields: Strings): Dictionary
  • getSignature(method: Function): Strings
  • namespaceByPath(namespace: Dictionary, path: string): Dictionary | null

Class Pool

  • constructor(options: { timeout?: number })
  • items: Array<unknown>
  • free: Array<boolean>
  • queue: Array<unknown>
  • current: number
  • size: number
  • available: number
  • timeout: number
  • next(): Promise<unknown>
  • add(item: unknown): void
  • capture(): Promise<unknown>
  • release(item: unknown): void
  • isFree(item: unknown): boolean

Random utilities

  • random(min: number, max?: number): number
  • sample(array: Array<unknown>): unknown

Class Semaphore

  • constructor(concurrency: number, size?: number, timeout?: number)
  • concurrency: number
  • counter: number
  • timeout: number
  • size: number
  • empty: boolean
  • queue: Array<QueueElement>
  • enter(): Promise<void>
  • leave(): void

Strings utilities

  • replace(str: string, substr: string, newstr: string): string
  • between(s: string, prefix: string, suffix: string): string
  • split(s: string, separator: string): [string, string]
  • isFirstUpper(s: string): boolean
  • isFirstLower(s: string): boolean
  • isFirstLetter(s: string): boolean
  • toLowerCamel(s: string): string
  • toUpperCamel(s: string): string
  • toLower(s: string): string
  • toCamel(separator: string): (s: string) => string
  • spinalToCamel(s: string): string
  • snakeToCamel(s: string): string
  • isConstant(s: string): boolean
  • fileExt(fileName: string): string
  • parsePath(relPath: string): Strings

Units utilities

  • bytesToSize(bytes: number): string
  • sizeToBytes(size: string): number

License & Contributors

Copyright (c) 2017-2023 Metarhia contributors. Metautil is MIT licensed.
Metautil is a part of Metarhia technology stack.

Keywords

FAQs

Last updated on 29 Jun 2023

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc