T
import { patterns } from "@stephen-shopopop/standard"
import assert from 'assert/strict'
const createEmailByName = patterns.compose(
(name: string) => name + 'example.org',
(name: string) => name + '@',
)
const email = createEmailByName('jean')
assert.equal(email, 'jean@example.org')
Pattern matching
import { patterns } from "@stephen-shopopop/std"
import assert from 'assert/strict'
const predicate = (name: string) => typeof name === 'string'
const execution = (name: string) => name.toUpperCase()
const pattern = patterns.when(predicate)(execution)
const name = patterns.match('lorem')(pattern)()
assert.equal(name, 'LOREM')
Handle
T
import { patterns } from "@stephen-shopopop/standard"
import assert from 'assert/strict'
const sanitizeName = patterns.pipe(
(name: string) => name.trim(),
(name: string) => name.charAt(0).toUpperCase() + name.slice(1)
)
const name = sanitizeName(' jean ')
assert.equal(name, 'Jean')
const sanitizeName = patterns.pipe( (name: string) => name.trim(), (name: string) => name.charAt(0).toUpperCase() + name.slice(1), async(name: string) => await Promise.resolve(name + '!') )
const name = await sanitizeName(' jean ')
assert.equal(name, 'Jean!')
Pattern for pattern matching
import { patterns } from "@stephen-shopopop/standard"
const predicate = (name: string) => typeof name === 'string'
const execution = (name: string) => name.toUpperCase()
const pattern = patterns.when(predicate)(execution)
Generated using TypeDoc
Handle