0.5.0 • Published 3 years ago

@nicolastoulemont/utilities v0.5.0

Weekly downloads
1
License
MIT
Repository
github
Last release
3 years ago

Utilities

This utilities functions aims to share and re-use useful typed utilities functions I came accross.

Disclaimer

This is a work in progress tool and mainly aimed at my personal use accross my projects.

Installation

npm install @nicolastoulemont/utilities
or
yarn add @nicolastoulemont/utilities

Functions

Colors

  • randomHex()
function randomHex(): string;
  • isHex()
function isHex(hex: string): boolean;
  • isRgb()
function isRgb({ r: number, g: number, b: number }): boolean;
  • hexToRgb()
function hexToRgb(hex: string): { r: number; g: number; b: number };
  • rgbToHex()
function rgbToHex({ r: number, g: number, b: number }): string;
  • colorBasedOnBg()
function colorBasedOnBg(
  bgHex: string,
  lightColor: string,
  darkColor: string
): string;

Arrays

  • flatten()
function flatten<T>(deepArray: Array<T>): Array<T>;
  • arrayToRecord()
function arrayToRecord<T extends { [key: string]: any }>(
  array: Array<T>,
  key: string
): Record<string, T>;

Other Data structures

  • Stack
const stack = new Stack<T>()
stack.push(value: T): void
stack.pop(): T
stack.peek(): T
stack.clear(): void
stack.print(): void
stack.isEmpty(): boolean
stack.reverse(stack: Stack<T>): void
stack.sort(stack: Stack<T>): void
  • Queue
const queue = new Queue<T>()
queue.enqueue(value: T): void
queue.dequeue(): T | null
queue.peek(): T | null
queue.clear(): void
queue.print(): void
queue.reverse(queue: Queue<T>): Queue<T>
  • PriorityQueue
const pq = new PriorityQueue<T>()
pq.enqueue(value: T): void
pq.dequeue(): T | null
pq.peek(): T | null
pq.clear(): void
pq.print(): void
pq.reverse(queue: Queue<T>): Queue<T>
  • LinkedList
const list = new LinkedList<T>()
list.insertFirst(data: T)
list.insertLast(data: T)
list.insertAt(data: T, index: number)
list.getAt(index: number): T | null
list.removeAt(index: number)
list.clearList()
list.getListAsArray(): Array<T>
list.printList()
  • HashTable
const hashTable = new HashTable<T>(size:number)
hashTable.insert(key:string, value: T)
hashTable.get(key:string) T | null
hashTable.remove(key:string)
  • Binary Search Tree
const bst = new BST<T>()
bst.add(value: T): void
bst.getMin(): T | null
bst.getMax(): T | null
bst.find(value: T): Node<T> | null
bst.contains(): boolean
bst.remove(value: T): Node<T> | "Tree is empty" | null

Misc

  • randomString()
function randomString(): string;

Built with

Versionning

This tool use SemVer for versioning.

Licence

MIT

0.5.0

3 years ago

0.4.0

3 years ago

0.3.0

3 years ago

0.2.9

4 years ago

0.2.7

4 years ago

0.2.6

4 years ago

0.2.8

4 years ago

0.2.5

4 years ago

0.2.4

4 years ago

0.2.3

4 years ago

0.2.2

4 years ago

0.2.1

4 years ago

0.2.0

4 years ago

0.1.8

4 years ago

0.1.9

4 years ago

0.1.7

4 years ago

0.1.6

4 years ago

0.1.4

4 years ago

0.1.5

4 years ago

0.1.3

4 years ago

0.1.2

4 years ago

0.1.1

4 years ago

0.1.0

4 years ago