npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@mysticaldragon/utils

v1.0.9

Published

NodeJS utilities for all kind of repetitive tasks.

Downloads

25

Readme

@mysticaldragon/utils

NodeJS utilities for repetitive tasks

  • [x] Object
  • [x] Functions
  • [x] Math
  • [x] String
  • [x] Events
  • [x] Array
  • [x] Buffer

Object Module

export  declare  class  ObjectUtils {
  // If object[property] === undefined, object[property] = defaultValue
  static setDefault<T>(object: any, property: string, defaultValue: T): void;
  // For each property in properties, set default property on object
  static setDefaults(object: any, properties: any): void;
  
  // Creates a new object where values = map(key, value) of the original object
  static map<T, U>(obj: { [key: string]: T; }, map: (key: string, value: T) =>  U): { [key: string]: U; };
  
  // Build object from array, keys = filter return value
  static fromArray<T>(array: T[], filter: (e: T, i: number) =>  string): { [key: string]: T[]; };
  // Creates { key, value }[] array from object
  static toArray<T>(obj: { [key: string]: T; }): { key: string; value: T; }[];
}

Function Module

class FunctionUtils {
  // Get the array of parameter names of function, ex. getParamNames((foo, bar) => 0) => ["foo", "bar"]
  static  getParamNames(func: Function): Array<string>;
  // Get object property ignoring the case, ex. getObjectPropertyIgnoreCase({ Name: "Peter" }, "naMe") => "Peter"
  static  getObjectPropertyIgnoreCase(obj: any, prop: string): any;
}

Events Module

class EventsUtils {
  // Wait event emitter to emit event, if timeout (ms) is providen promise will fail after that time
  static waitOnce(emitter: EventEmitter, event: string, timeout?: number): Promise<unknown>;
}

Array Module

export class ArrayUtils {

  // Awaits all, shorthand for Promise.all(array.map(asyncFunction))
  static awaitAll<T, U> (array: T[], asyncFunction: (...args: any[]) => U): Promise<U[]>;

}

String Module

export declare class StringUtils {
  // Remove all ansi colors from text
  static escapeANSI(text: string): string;
  // Replaces {{ key }} inside string for data[key]
  static template(input: string, data: any): string;
  // Count number of matches inside a text
  static countMatches(text: string, match: string | RegExp): number;
}

Buffer Module

export declare class BufferUtils {
  // Iterates buffer bit by bit, receives a callback indicating (bit, number index [0, buf.length) and bit index, [0, 7])
  static forEachBit(buf: Buffer, callback: (bit: number, i: number, j: number) => any): void;
  // Returns 4 bytes buffer from number, useful for size headers
  static sizeHeader(size: number): Buffer;
  // Iterates buffer bit by bit, bits are yield as generator
  static bitStream(buf: Buffer): Generator<number, void, unknown>;
}

FileSystem Module

class FileSystem {
  // Read CSV file
  static readCSV(path: string, separator?: string): Promise<{}[]>;
  // Read file as UTF-8
  static read(path: string): Promise<String>;
  // Write file
  static write(path: string, data: string | Buffer): Promise<void>;
  // Remove File
  static remove(path: string): Promise<void>;
  // Read File Sync as String
  static readSync(path: string): String;
  // Synchronously write file
  static writeSync(path: string, data: string): void;
  // Search file in a group of directories
  static lookup(dirs: string[], name: string): Promise<String | null>;
}

Math Module

class Vector2 {
  constructor(x: number, y: number, listener?: ((prev: Vector2, next: Vector2) =>  any) | undefined);
  get  x(): number;
  get  y(): number;
  set  x(val: number);
  set  y(val: number);
  update(x: number, y: number): void;
  minus(vec: Vector2): Vector2;
  plus(vec: Vector2): Vector2;
}

class Vector3 {
  constructor(x: any, y: any, z: any, listener?: ((prev: Vector3, next: Vector3) =>  any) | undefined);

  get  x(): number;
  get  y(): number;
  get  z(): number;
  abs(): number;
  set  x(val: number);
  set  y(val: number);
  set  z(val: number);
  update(x: number, y: number, z: number): void;
  minus(vec: Vector3): Vector3;
  plus(vec: Vector3): Vector3;
  toString(): string;
}

class  Maths {
  static max(a: number, b: number): number;
  static randInt(from: number, to: number): number;
}