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
Install size
38.6 kB
Created
Weekly downloads
 

Changelog

Source

[3.7.0][] - 2023-03-04

  • Add generateUUID implementation
  • Improve AbortController polyfill and use native if available

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');

Common utilities

  • random(min: number, max?: number): number
  • sample(arr: Array<any>): any
  • parseParams(params: string): object
  • replace(str: string, substr: string, newstr: string): string
  • split(s: string, separator: string): [string, string]
  • fileExt(fileName: string): string
  • parsePath(relPath: string): Array<string>
  • between(s: string, prefix: string, suffix: string): string
  • isFirstUpper(s: string): boolean
  • toLowerCamel(s: string): string
  • toUpperCamel(s: string): string
  • isConstant(s: string): boolean
  • nowDate(date?: Date): string
  • duration(s: string | number): number
  • bytesToSize(bytes: number): string
  • sizeToBytes(size: string): number
  • namespaceByPath(namespace: object, path: string): object | null
  • parseDay(s: string): number
  • parseMonth(s: string): number
  • parseEvery(s: string): Every
  • nextEvent(every: Every, date?: Date): number
  • makePrivate(instance: object): object
  • protect(allowMixins: Array<string>, ...namespaces: Array<object>): void
  • createAbortController(): AbortController
  • timeout(msec: number, signal?: EventEmitter): Promise<void>
  • delay(msec: number, signal?: EventEmitter): Promise<void>
  • isError(instance): boolean

Network utilities

  • ipToInt(ip?: string): number
  • parseHost(host?: string): string
  • parseCookies(cookie: string): object
  • fetch(url: string): Promise<string>
  • jsonParse(buffer: Buffer): object | null
  • receiveBody(req: IncomingMessage): Promise<Buffer | null>

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
  • hashPassword(password: string): Promise<string>
  • validatePassword(password: string, serHash: string): Promise<boolean>
  • md5(fileName: string): Promise<string>

Async abstractions

  • Semaphore for limit concurrency accessing limited resource
    • new Semaphore(concurrency: number, size?: number, timeout?: number)
    • empty: boolean
    • enter(): Promise<void>
    • leave(): void
  • Pool with round-robin and exclusive item capture
    • new Pool()
    • size: number
    • available: number
    • next(): object | null
    • add(item: object): void
    • capture(): object | null
    • release(item: object): void
    • isFree(item: object): boolean

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 04 Mar 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