Coder Social home page Coder Social logo

metautil's Introduction

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
  • 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>

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
  • 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-2021 Metarhia contributors. Metautil is MIT licensed.
Metautil is a part of Metarhia technology stack.

metautil's People

Contributors

aqrln avatar belochub avatar dzyubspirit avatar eternal-rise avatar ivan-tymoshenko avatar ivhc avatar juliagerasymenko avatar lundibundi avatar mille-nium avatar nechaido avatar olewar avatar semenchenkovitaliy avatar semigradsky avatar tshemsedinov avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.