A comprehensive standard library for TypeScript that provides utility functions and types commonly used in web applications. This package serves as a natural complement to the Tempo libraries but can be used independently in any TypeScript project.
# npm
npm install @tempots/std
# yarn
yarn add @tempots/std
# pnpm
pnpm add @tempots/std
The library provides utility functions for working with:
import { filterArray, mapArray, uniquePrimitives } from '@tempots/std'
// or
import { filterArray, mapArray, uniquePrimitives } from '@tempots/std/array'
// Filter an array
const numbers = [1, 2, 3, 4, 5]
const evenNumbers = filterArray(numbers, n => n % 2 === 0) // [2, 4]
// Map an array
const doubled = mapArray(numbers, n => n * 2) // [2, 4, 6, 8, 10]
// Get unique values
const withDuplicates = [1, 2, 2, 3, 3, 3]
const unique = uniquePrimitives(withDuplicates) // [1, 2, 3]
import { capitalizeWords, ellipsis } from '@tempots/std'
// or
import { capitalizeWords, ellipsis } from '@tempots/std/string'
// Capitalize words
const capitalized = capitalizeWords('hello world') // 'Hello World'
// Truncate with ellipsis
const truncated = ellipsis('This is a very long text', 10) // 'This is a...'
import { deferred } from '@tempots/std'
// or
import { deferred } from '@tempots/std/deferred'
// Create a deferred promise
const { promise, resolve, reject } = deferred<number>()
// Use the promise
promise.then(value => console.log(value))
// Resolve it later
setTimeout(() => resolve(42), 1000)
import { delayed, interval } from '@tempots/std'
// or
import { delayed, interval } from '@tempots/std/timer'
// Delay execution
const cancelDelay = delayed(() => {
console.log('Executed after 1 second')
}, 1000)
// Set up an interval
const cancelInterval = interval(() => {
console.log('Executed every 2 seconds')
}, 2000)
// Cancel if needed
cancelDelay() // Cancel the delayed execution
cancelInterval() // Stop the interval
import { Result, success, failure } from '@tempots/std'
// or
import { Result, success, failure } from '@tempots/std/result'
// Create success or failure results
const successResult = success(42)
const failureResult = failure('Something went wrong')
// Handle results
successResult.match({
success: value => console.log(`Success: ${value}`),
failure: error => console.error(`Error: ${error}`)
})
The library is organized into the following modules:
-
array
- Array manipulation utilities -
async-result
- Asynchronous result handling -
bigint
- BigInt utilities -
boolean
- Boolean utilities -
deferred
- Promise deferral utilities -
domain
- Domain-specific types -
equal
- Deep equality comparison -
error
- Error handling utilities -
function
- Function composition and manipulation -
json
- JSON utilities -
number
- Number utilities -
object
- Object manipulation -
promise
- Promise utilities -
regexp
- Regular expression utilities -
result
- Result type for error handling -
string
- String manipulation utilities -
timer
- Timing utilities -
validation
- Data validation utilities
For comprehensive documentation, visit the Tempo Documentation Site.
This package is licensed under the Apache License 2.0.