@cantinc/utils
v1.4.2
Published
Cant inc. utils
Downloads
78
Readme
utils
Abstract
Here you can find some utils of CANT inc.
Install
npm
npm i @cantinc/utils
yarn
yarn add @cantinc/utils
Decorators
Now it supports old way of decorators, to use it with TypeScript flag experimentalDecorators
once
Run getter or method once
import { once } from '@cantinc/utils'
let count = 0
class Test {
@once
get value () {
count++
return 'success'
}
}
const test = new Test()
console.log(test.value)
// 'success'
console.log(test.value)
// 'success'
console.log(count)
// 1
Validation
The next utils helps validate a data
Validation
Use validation
to make validation of an object
import {
email,
maxLength,
minLength,
required,
validation,
ValidationMap,
} from '@cantinc/utils'
interface Data {
email: string
password: string
name: string
birthday?: string
}
const validationMap: ValidationMap<Data> = {
email: required([email, maxLength(128)]),
password: required([minLength(9)]),
name: required([maxLength(128)]),
}
console.log(validation(validationMap, {}))
console.log(validation(validationMap, { email: 'error'}))
Utils
placeholder
Placeholder inserts data into a string
import { placeholder } from '@cantinc/utils'
placeholder(`Test: {test}`, { test: 'success' })
// Test: success
Issues
If you find a bug or have a suggestion, please file an issue on GitHub.