brutdecode
v1.0.1
Published
Brutdecode is common package for all BrutdeCom projects. Contain utils function and many more.
Readme
BRUTDECODE PACKAGE DOCUMENTATION
Introduction
This package is npm package in TypeScript for BDC's project.
Update this package
- Run
git clone https://github.com/BrutdeCom/brutdecode.git - Create branch for your additions, and go to your local branch
- Run
npm i - Make your code with love. Tested code is better.
- Code is finished ? Run
git add ., thengit commit -m '[your atomic commit]' - Run
npm run release. Launch tests, and update package version. Is obligatory for the rest. - Run
git push origin [your branch] - Create your pull request to
productionbranch. If actions passed, validate your PR. - It's good, package is automatically published.
- In your project, update
brutdecodeto use your new features.
Installation
For install this package, run npm i brutdecode
Use
Example for require function :
import { checkId, createEnum } from 'brutdecode'
Regex
Example for use Regex with this package :
// Require the regex you need
import { URL_REGEX } from 'brutdecode'
// Here use URL_REGEX| Regex Type | Description | Name | | :------------ | :-------------: | :-------------: | | password | 8 characters, 1 lowercase, 1 uppercase, 1 special character, 1 number | PASSWORD_REGEX | | phone | Phone and fax number | PHONE_REGEX | | city | City (2 characters minimum, not number) | CITY_REGEX | | zip | French zip code (5 numbers) | ZIP_REGEX | | email | Email format | EMAIL_REGEX | | url | URL format | URL_REGEX |
Validator
Validator part is utils for validate various data. Example for use Validator with this package :
import { isValidString } from 'brutdecode'
// Use isValidString for example
const myConst = isValidString('string')
// return true
const myConst = isValidString(14)
// return false| Name | Description | Parameters | return |
| :------------ | :-------------: | :-------------: | :-------------: |
| isValidString('string') | Verify if value is valid string | String parameters ('one string') | Return true or false |
| isValidEmail('[email protected]') | Verify if email is valid format | String parameters ('[email protected]') | Return true or false |
| isValidZip('40500') | Verify if value is valid zip code format for France. | String parameters ('40530') | Return true or false |
| isValidCountry('France') | Verify if value is valid country format. | String parameters ('France') | Return true or false |
| isValidAddress('3 rue de la Liberté') | Verify if value is valid address format. | String parameters ('3 rue de la Liberté') | Return true or false |
| isValidCity('Biarritz') | Verify if value is valid city format. | String parameters ('Biarritz') | Return true or false |
| isValidPhone('0625458769') | Verify if value is valid phone and fax number format. | String parameters ('0625458769') | Return true or false |
| isValidLastname('Lastname') | Verify if value is valid lastname format. | String parameters ('Lastname') | Return true or false |
| isValidFirstname('Firstname') | Verify if value is valid Firstname format. | String parameters ('Firstname') | Return true or false |
| isValidPassword('password') | Verify if value is valid password format (8 characters, 1 lowercase, 1 uppercase, 1 special character, 1 number). | String parameters ('password') | Return true or false |
| isValidSiret('string') | Verify if value is valid siret | String siret parameters ('12345678998765') | Return true or false |
| isValidEnum('string', array) | Verify if value is valid enumeration | String value parameters ('test'), array parameters (Enum.MyEnum) | Return true or false |
Utils
Example for use Utils with this package :
import { checkId } from 'brutdecode'
// Use utils function
const myConst = checkId(myId)
// return ...const verifyIfRequestItemsIsString = validateStringRequestItems({
value1: 'test1',
value2: 'test2',
value3: 12
})
// return false, because one value is not a string
const verifyIfRequestItemsIsString = validateStringRequestItems({
value1: 'test1',
value2: 'test2'
})
// return true, because all values is stringEnumerations
Create Enum
import { createEnum } from 'brutdecode'
const CarBrand = {
RENAULT: 'renault',
PEUGEOT_CITROEN: 'peugeot-citroen',
FORD: 'ford'
}
export const CarBrandEnum = createEnum(CarBrand, 'CarBrand')Methods
CarBrand.getValues() // return ['renault', 'peugeot-citroen', 'ford']CarBrand.next() // return 'renault'
CarBrand.next('renault') // return 'peugeot-citroen'
CarBrand.next('ford') // return 'renault'CarBrand.isValid('renault') // return true
CarBrand.isValid('test') // return false// Update CarBrand with categories for example
const CarBrand = {
frenchBrand: {
RENAULT: 'renault',
PEUGEOT_CITROEN: 'peugeot-citroen',
},
americanBrand: {
FORD: 'ford'
}
}
CarBrand.getCategories() // return ['frenchBrand', 'americanBrand']// Update CarBrand with categories for example
const CarBrand = {
frenchBrand: {
RENAULT: 'renault',
PEUGEOT_CITROEN: 'peugeot-citroen',
},
americanBrand: {
FORD: 'ford'
}
}
CarBrand.getCategory('frenchBrand') // return ['renault', 'peugeot-citroen']CarBrand.getIndex('renault') // return 0
CarBrand.getIndex('RENAULT') // return 0// Update CarBrand with categories for example
const CarBrand = {
RENAULT: 'renault',
PEUGEOT_CITROEN: 'peugeot-citroen',
FORD: {
value: 'ford',
engine: '1.2',
test: false
}
}
CarBrand.getMetaData(CarBrand.FORD, 'engine') // return '1.2'
CarBrand.getMetaData(CarBrand.FORD, 'test') // return false