@pcs/utils
TypeScript icon, indicating that this package has built-in type declarations

0.4.7 • Public • Published

PCS Utils

A collection of utility functions for handling: strings, numbers, arrays, dates and promises.

Installation

npm install @pcs/utils

Usage

Each example shows one function from each of the exported sets. For a full list of functions check the TS definitions.

Array

compactMap Map over an array and return a result array that excludes null and undefined.

import { array } from '@pcs/utils'

const result = array.compactMap([0, 1, 2, 3], (num) => (num > 1 ? null : num))
// [0, 1]

Date

startOf Get the start of a given time interval for a date:

import { date } from '@pcs/utils'

const startOfToday = date.startOf(new Date(2021, 4, 28, 14, 43), 'day')
// Date: Fri May 28 2021 00:00:00

Promise

map Map over an array, resolving with an array of the resolved values, optional concurrency option limits how many promises are currently being processed.

import { promise } from '@pcs/utils'

const result = await promise.map([1, 2, 3, 4], async (num) => num * num, { concurrency: 2 })
// [1, 4, 9, 16]

String

replaceAll Replace all occurences of a value in a string

import { string } from '@pcs/utils'

const result = await string.replaceAll('the orange fox ran over the road', 'the', 'a')
// 'a orange fox ran over a road'

Readme

Keywords

Package Sidebar

Install

npm i @pcs/utils

Weekly Downloads

34

Version

0.4.7

License

ISC

Unpacked Size

491 kB

Total Files

95

Last publish

Collaborators

  • stavrosf
  • simondweare
  • chris_train