validation_t

A small lib to valid data

Usage no npm install needed!

<script type="module">
  import validationT from 'https://cdn.skypack.dev/validation_t';
</script>

README

Validation_t

This package was written by Phạm Anh Tuấn . The destination of this package is testing and do some small stuff

Install

npm install validation_t

yarn add validation_t

GITHUB :

► GITHUB

Current Features :

** String methods

import { tStr } from "validation_t/src";
Syntax : tStr.method-name
Methods Params Result

String

removeAscent(str) str : String Return new lowercase string does not contain ascent.
Ex: removeAscent('Tuấn') -> 'tuan'
isEmail(str) str : String Return a Boolean . ⚠ ⚠ just test some regular email, not match for all case.
Ex: isEmail('example@gmail') -> false
isURL(str) str : String Return a Boolean . Check if provided string match a url pattern
Ex: isURL('https://www.npmjs.com/package/validation_t') -> true
isContainURL(str) str : String Return a Boolean . Check if provided string contain any url pattern
Ex: isURL('thisexamplehttps://www.npmjs.com/package/validation_t') -> true
isNotContainNumber(str) str : String Return a Boolean check if provided string contain number or not.
Ex: isNotContainNumber('abc') -> true
getCurrency(str) str : String Return a formated string if the string can convert to number, if not its return the string it self. Work the same with number .
Ex: getCurrency('abc') -> 'abc' getCurrency('1234567.89') -> '1,234,567.89'

** Date methods

import { tDate } from "validation_t/src";

Syntax : tDate.formatDate(_date, format, lang)
_date : Valid Date value Ex : '01/13/2020' , '01/13/2020 12:20' , GTMString, ISOString, miliseconds ... .
format : String . Listed as an Array bellow
lang | default 'vi' : define your language . only can recognize 'vi' as vietnamese, the rest will be treated as 'eng'

Format Return
day 'Monday' - 'Thứ 2'
d | dd | ddd 1 | 01 | 01
M | MM | MMM | MMMM 1 | 01 | Jan - Tháng 1 | January - Tháng 1
yy | yyyy 21 | 2021
hh | mm | ss | mili | 12 09 | 09 | 09 | 789 | Turn time to 12-hour-clock
Format Array d/M/yy | d-M-yy | dd/MM/yyyy | dd-MM-yyyy | day |MMM dd | yyyy |day |MMMM ddd | yyyy | hh:mm | hh:mm:ss | hh:mm:ss:mili | hh:mm 12 |hh:mm:ss 12 | hh:mm:ss:mili 12 | dd/MM/yyyy hh:mm | day |MMMM ddd |yyyy hh:mm | day |MMMM ddd | yyyy hh:mm:ss | day |MMMM ddd | yyyy hh:mm:mili | day |MMM dd | yyyy hh:mm | day |MMM dd | yyyy hh:mm 12 |dd/MM/yyyy hh:mm:ss | dd/MM/yyyy hh:mm:ss 12 | dd/MM/yyyyhh:mm:ss:mili | dd/MM/yyyy hh:mm:ss:mili 12
Syntax : tDate.method-name
Methods Params Result

Date

formatDateCustomize(_date, lang, timezone) _date : valid date
lang : String - default 'vi' as vietnamese, other value will be treat as 'en'
timezone : Number - default 24 . switch to 12 if you wanna change to 12'clock
Return an Object to customize format by your self
getCurrentWeek(_date) _date : valid date Return an object {
startWeek: dateObject,
endWeek: dateObject
}