1.4.2 • Published 1 year ago

@cantinc/utils v1.4.2

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

 utils

 

NPM downloads changelog license

Abstract

Here you can find some utils of CANT inc.

stars watchers

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.

issues

1.4.2

1 year ago

1.4.1

1 year ago

1.2.7

2 years ago

1.2.6

2 years ago

1.2.5

2 years ago

1.4.0

1 year ago

1.3.1

1 year ago

1.3.0

2 years ago

1.2.4

2 years ago

1.2.3

2 years ago

1.2.2

2 years ago

1.2.1

2 years ago

1.2.0

2 years ago

1.1.1

2 years ago

1.1.0

2 years ago

1.1.3

2 years ago

1.1.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago