A collection of validation, normalization and business related helpers which can only be used in modern web development with transpiler.
This library is for internal use, it has no babel and no terser, therefore it will not compatible to all kinds of usage.
Install utilities
yarn add git+ssh://[email protected]:oriente-fe/oriente-utility
ES Module
import { formatMobile } from 'oriente-utility'
CommonJS
const { formatMobile } = require('oriente-utility')
Start development server
yarn dev
Follow the naming convention as below:
formatXXX
: parameter type and return type are the samegetXXX
: parameter type and return type are differentisXXX
: return type is boolean or string (e.g. validation)XXX
: common helpers (e.g. string, array, ...etc)
Let's create a math utility:
-
Create
src/addOne.js
file -
Write code with jsdoc and add default export
/** * Add one to the number * * @param {number} n - input number * @returns {number} */ const addOne = n => { return Number(n) + 1 } export default addOne
-
Update
index.js
import addOne from './addOne' export default { addOne, } export { addOne, }
-
Add unit test
import addOne from '~/addOne' describe('addOne', () => { it('should work when input number', () => { expect(addOne(-1)).toBe(0) }) it('should work when input string', () => { expect(addOne('0')).toBe(1) }) })
-
Create PR
Publish new version
yarn version