x2-utils
v1.3.2
Published
tools
Downloads
5
Readme
x2-utils
Installation
npm install x2-utils
const x2utils= require('x2-utils')
API
data processing utils
x2utils.tojson2(options)
{
from: string, // need to transfer excel path /excel/a.xls
to: string, // need to save json path /json/a.json
sheetName: string // need to transfer excel's sheet
}
x2utils.toMap(keyName, valueName, data)
keyName: map's key
valueName: map's value
x2utils.toTree(options)
{
rows: array, // the data array
parentId: string, // the root value
idKey: string, // id's field name
pidKey: string, // pid's field name
nameKey: string // name's field name
}
x2utils.findTreeNode = ({ rows=[], id='' }))
{
rows: array, // the data array
id: string // to find the id's node
}
x2utils.col2row = ({data, idField, colField, valueField})
{
data:array, // data
idField: string, // unique col field
colField: string, // col to rows's field name
valueField: string // colField's value
}
x2utils.row2col = ({data, idField, colField, valueField})
{
data:array, // data
idField: string, // unique col field
colField: string, // row to col's field name
valueField: string // colField's value
}
http utils
x2utils.getUrl(url, params, tokenId)
url: string, // request url
params: object, // request params
tokenId: string // request required tokenId
x2utils.postUrl(url, params, tokenId)
url: string, // request url
params: object, // request params
tokenId: string // request required tokenId
number utils
Number format thousands: x2utils.addKannma(value, deg)
value: number, // numbers
deg: int // Retain decimal places
Number format thousands: x2utils.format(value, option)
value: number, // numbers
option: {
type: string,// num , percent, flowNum
deg: 2,//
kannma: boolean,//is add Thousandths
autoUnit: boolean,//is auto calc
unit: int // Unit conversion value/unit
}
Number format thousands and tofixed 2 deg: x2utils.numFormat(value)
value: number, // numbers
date utils
date utils: x2utils.getPreMonthsByNum(yearMonth, num)
yearMonth: number, // yyyy-MM
num: number // to get a few month ago
date utils: x2utils.getPreYearsByNum(yearMonth, num)
yearMonth: number, // yyyy-MM or yyyy
num: number // to get a few year ago
date utils: x2utils.getMonthBetween(startDate, endDate)
startDate: number, // yyyy-MM
endDate: number // yyyy-MM
formula processing utils
x2utils.formulaValue(formula = '', data = {})
formula:string, // formula like '{value1} / {value2}'
data: object // {value1:1, value2: 1}
x2utils.formulaValues({formula='', data=[], dataKey='formulaName', fields=['value1', 'value2']})
formula:string, // formula like '{name1} + {name2}'
data: object // [{value1:1, value2: 1, formulaName: 'name1'},{value1:1, value2: 1, formulaName: 'name2'}]
fields:arr, // need to calc field
dataKey: string // data's mapping formula's field name
x2utils.computed({formulas = [], data = [], dataKey='formulaName', fields = ['value1', 'value2']})
formula:array, // formula like {formulaName:'name1', formula: '{{name11}} + {{name12}}'}, {formulaName: 'name0', formula: '{{name1}} + {{name2}} - {{name3}}'}]
data: object // [{value1:1, value2: 1, formulaName: 'name1'},{value1:1, value2: 1, formulaName: 'name2'}]
fields:arr, // need to calc field
dataKey: string // data's mapping formula's field name