Skip to content

oriente-fe/oriente-utility

Repository files navigation

Oriente Utility

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.

Document

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')

Contribute

Start development server

yarn dev

Follow the naming convention as below:

  • formatXXX: parameter type and return type are the same
  • getXXX: parameter type and return type are different
  • isXXX: return type is boolean or string (e.g. validation)
  • XXX: common helpers (e.g. string, array, ...etc)

Let's create a math utility:

  1. Create src/addOne.js file

  2. 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
  3. Update index.js

    import addOne from './addOne'
    
    export default {
      addOne,
    }
    export {
      addOne,
    }
  4. 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)
      })
    })
  5. Create PR

Deploy

Publish new version

yarn version

About

A collection of validation, normalization and business related helpers which can only be used in modern web development with transpiler.

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published