1.0.6 • Published 7 years ago

formatting v1.0.6

Weekly downloads
2
License
MIT
Repository
github
Last release
7 years ago

Formatting

Process data like value, file, url, array and object. Demo page: https://goo.gl/djJJ17

Installation

  1. node
npm install formatting --save
  1. browser
find node_modules/formatting/bin/browser.js
and use <script src=""></script> to require it

Usage

  1. node
import Formatting from 'formatting';

const valueFormat = new Formatting('value');
valueFormat.leading(1, 3, 0);
  1. browser
<script>
const valueFormat = new Formatting('value');
valueFormat.leading(1, 3, 0);
</script>

API

Create a Constructor like const format = new Formatting(type),and type is the mode which your data is. If you want to use all methods, type can be empty.

const format = new Formatting()

Object APIsexplanreturn type
format.deepMerge(obj1, obj2)Combine two nested objectobject
format.deepEuqal(obj1, obj2)Compared two nested object(use deep-equal module)boolean
Array APIsexplanreturn type
format.arrayMerge(array1, array2)Merge two nested array with non duplicate value. (array2 to array1)array
format.arraySameValue(array1, array2)Compare two nested array, and get duplicate valuearray
format.arrayRemoveValue(array1, array2)Remove children value that array2 has from array1array
format.arrayNonrepeatValue(array1, array2)Compare two nested array, and get non duplicate valuearray
Value APIsexplanreturn type
format.leading(value, length, letter)value: the data you want to format. length the result string length. letter: fill leading characterstring
format.tailing(value, length, letter)value: the data you want to format. length the result string length. letter: fill tailing characterstring
format.sequence(value, letter, number)value: the data you want to format. letter: the character want to insert. number: loop number.string
format.insert(value, letter, start)value: the data you want to format. letter: the character want to insert. start: insert index.string
format.replace(value, letter, replaceLetter)value: the data you want to format. letter: the character want to be replaced. replaceLetter: the replace character.string
format.replaceWithRange(value, replaceLetter, start, end)value: the data you want to format. replaceLetter: the replace character. start: replace start index. end: replace end index.string
File APIsexplanreturn type
format.file(selector)Get input file info, selector is className / id / etc selectorarray
format.size(value)Compute file size, minimal unit is Bytesstring
format.duration(Second)Convert Time to HH:MM:SSstring
format.videoInfo(selector)Get input file info with formatted size, type and duration. Selector is className / id / etc selector. The return value is promise, so if want to see the result, it would look like format.videoInfo(selector).then(data) => { console.log(data) }promise
format.imageInfo(selector)Get input file info with formatted size and type. Selector is className / id / etc selector. The return value is promise, so if want to see the result, it would look like format.imageInfo(selector).then(data) => { console.log(data) }promise
Url APIsexplanreturn type
format.getHash(url)Get url hash value, if url variable is empty, it will get location.href.object
format.getParamByName(url, name)Get url param value with indicate name. If url variable is empty, it will get location.href.string
format.getParams(url)Get all url params value. If url variable is empty, it will get location.href.object
1.0.6

7 years ago

1.0.5

7 years ago

1.0.4

7 years ago

1.0.0

7 years ago