0.4.7 • Published 3 years ago

@pcs/utils v0.4.7

Weekly downloads
91
License
ISC
Repository
-
Last release
3 years ago

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'
0.4.7

3 years ago

0.4.6

3 years ago

0.4.5

3 years ago

0.4.4

3 years ago

0.4.1

3 years ago

0.4.0

3 years ago

0.4.3

3 years ago

0.4.2

3 years ago

0.3.0

4 years ago

0.2.2

4 years ago

0.2.1

4 years ago

0.2.0

5 years ago

0.1.11

5 years ago

0.1.10

5 years ago

0.1.9

5 years ago

0.1.8

5 years ago

0.1.7

5 years ago

0.1.6

5 years ago

0.1.5

5 years ago

0.1.4

5 years ago

0.1.3

5 years ago

0.1.2

5 years ago

0.1.1

5 years ago

0.1.0

5 years ago

0.0.6

5 years ago

0.0.5

5 years ago

0.0.4

6 years ago

0.0.2

6 years ago

0.0.1

6 years ago