tree_moment_numberal_helper
v0.1.9
Published
moment and numberal in wasm
Downloads
49
Readme
Js helper
import {init} from "tree_moment_numberal_helper"
//Note that you need to wait for the init function to complete before the tree variable will appear in the window
await init();
Numeral high-precision four arithmetic operations
Moment time processing
FetchJson request and return JSON, refer to fetch for usage
FetchText request and return text, refer to fetch for usage
Password encrypts data and can be used as password encryption
Install the function library, and in the future, all the above functions will be hung under the tree variable in the window
interface MyWindow extends Window{
tree: Tree
}
interface Tree{
numeral: Numeral
moment: Moment
fetchJson (URL: string, config: Map<string, any>): ResponseJson
fetchText (URL: string, config: Map<string, any>): ResponseText
password (encode: string): string
}
interface Number{
/**
*Constructor accepts initialization
*@ param n
*/
constructor (n: number): Numeral
add (n: number): Numeral
sub (n: number): Numeral
mul (n: number): Numeral
div (n: number): Numeral
/**
*Advanced method
*/
ceil(): Numeral
/**
*Retain Decimal Places
*@ param n decimal places
*/
round (n: number): Numeral
/**
*Obtain the value, the parameter can be left blank, and if there is a parameter, it represents the number of decimal places
*@ param n decimal places, display original length when empty
*/
val (n: number): number
/**
*Get integer part
*/
intVal(): number
/**
*Get Decimals
*/
floatVal(): number
/**
*Obtain numerical values and convert them into RMB
*/
convertNumToCny(): string
/**
*Numeric to Financial Counting Method
*/
digitalToFinancialCounting(): string
}
interface Moment{
/**
*Constructor accepts initialization
*@ param n time string
*/
constructor (n: string): Moment
/**
*Check if the time string is in a valid time format
*/
isValid(): boolean
/**
*Check if the current time string is after the parameter time
*@ param m
*/
after (m: Moment): boolean
/**
*Check if the current time string is before the parameter time
*@ param m
*/
before (m: Moment): boolean
/**
*Check if the current time string is equal to the parameter time
*@ param m
*/
eq (m: Moment): boolean
/**
*Time addition
*The value to be added by @ param k must be a number
*The @ param t parameter is as follows: days d
*Hours h
*Minutes m
*Seconds
*Milliseconds
*/
add (k: number, t: string): boolean
/**
*Subtraction of time
*The value to be added by @ param k {number} must be a number
*The @ param t {string} parameter is as follows: days d
*Hours h
*Minutes m
*Seconds
*Milliseconds
*/
sub (k: number, t: string): boolean
/**
*Subtraction of time
*Param m {Moment}
*The @ param t {string} parameter is as follows: days d
*Hours h
*Minutes m
*Seconds
*Milliseconds
*@ return returns the number of days/hours/minutes/seconds/milliseconds corresponding to the difference between two times
*/
sub (m: Moment): number
/**
*@ return timestamp seconds
*/
getTime(): number
/**
*@ return timestamp milliseconds
*/
getMilliTime(): number
}
interface ResponseText{
data: string
headers: Map<string, any>
ok: boolean
redirected: boolean
status: number
StatusText: string
type: string
url: string
}
interface ResponseJson{
data: Map<string, any>
headers: Map<string, any>
ok: boolean
redirected: boolean
status: number
statusText: string
type: string
url: string
}
//Precision four operations
let v=trre.numerical (100). add (100). sub (50). val()
console.log (v)
//150
let v1=tree.numerical (1). mul (100). div (50). val()
console.log (v1)
//2
//Time processing
tree.moment('2022 01 01 ').after(tree.moment('2021 01 01'))
tree.moment('2022 01 01 ').before(tree.moment('2021 01 01'))
//Pay attention to formatting parameters, pay attention to letter capitalization
tree.moment('2022-01-01 ').format('YYYY-MM-DD hh: mm: ss')
js helper
- numeral 高精度四则运算
- moment 时间处理
- fetchJson 请求,并返回json,用法参考fetch
- fetchText 请求,并返回text,用法参考fetch
- password 对数据进行加密,可以作为密码加密使用
import {init} from "tree_moment_numberal_helper"
//注意需要等待init函数执行完成,window下才会有tree这个变量
await init();
安装函数库,以后上述所有的功能都被挂在window下的tree变量下
interface MyWindow extends Window {
tree: Tree
}
interface Tree {
numeral:Numeral
moment:Moment
fetchJson(url:string,config:Map<string,any>):ResponseJson
fetchText(url:string,config:Map<string,any>):ResponseText
password(encode:string):string
}
interface Numeral{
/**
* 构造函数接受初始化
* @param n
*/
constructor(n:number):Numeral
add(n:number):Numeral
sub(n:number):Numeral
mul(n:number):Numeral
div(n:number):Numeral
/**
*进一法
*/
ceil():Numeral
/**
* 保留小数位数
* @param n 小数位数
*/
round(n:number):Numeral
/**
* 获取值,参数可留空,如存在参数则表示小数位数
* @param n 小数位数,为空时显示原始长度
*/
val(n:number):number
/**
* 获取整数部分
*/
intVal():number
/**
* 获取小数
*/
floatVal():number
/**
* 获取数值转成人民币
*/
convertNumToCny():string
/**
* 数值转金融计数法
*/
digitalToFinancialCounting():string
}
interface Moment{
/**
* 构造函数接受初始化
* @param n 时间字符串
*/
constructor(n:string):Moment
/**
* 检测时间字符串是否是有效时间格式
*/
isValid():boolean
/**
* 检测当前时间字符串是否在参数时间之后
* @param m
*/
after(m:Moment):boolean
/**
* 检测当前时间字符串是否在参数时间之前
* @param m
*/
before(m:Moment):boolean
/**
* 检测当前时间字符串是否和参数时间相等
* @param m
*/
eq(m:Moment):boolean
/**
* 时间相加
* @param k 要加的数值,必须是数字
* @param t 参数为如下:天数 d
* 小时数 h
* 分钟数 m
* 秒数 s
* 毫秒数 ms
*/
add(k:number,t:string):boolean
/**
* 时间相减
* @param k {number} 要加的数值,必须是数字
* @param t {string} 参数为如下:天数 d
* 小时数 h
* 分钟数 m
* 秒数 s
* 毫秒数 ms
*/
sub(k:number,t:string):boolean
/**
* 时间相减
* @param m {Moment}
* @param t {string} 参数为如下:天数 d
* 小时数 h
* 分钟数 m
* 秒数 s
* 毫秒数 ms
* @return 返回值为两个时间的差的相应 天数/小时数/分钟数/秒数/毫秒数
*/
sub(m:Moment):number
/**
* @return 时间戳秒
*/
getTime():number
/**
* 获取年份
*/
getYear():number
/**
* 获取月份
*/
getMonth():number
/**
* 获取天
*/
getDay():number
/**
* 获取星期几
*/
getWeekday():number
/**
* 获取小时
*/
getHour():number
/**
* 获取分钟
*/
getMinute():number
/**
* 获取秒
*/
getSecond():number
/**
* @return 时间戳毫秒
*/
getMilliTime():number
}
interface ResponseText{
data:string
headers:Map<string,any>
ok:boolean
redirected:boolean
status:number
statusText:string
type:string
url:string
}
interface ResponseJson{
data:Map<string,any>
headers:Map<string,any>
ok:boolean
redirected:boolean
status:number
statusText:string
type:string
url:string
}
//精度四则运算
let v=tree.numeral(100).add(100).sub(50).val()
console.log(v)
//150
let v1=tree.numeral(1).mul(100).div(50).val()
console.log(v1)
//2
// 时间处理
tree.moment('2022-01-01').after(tree.moment('2021-01-01'))
tree.moment('2022-01-01').before(tree.moment('2021-01-01'))
//注意格式化参数注意字母大小写
tree.moment('2022-01-01').format('YYYY-MM-DD hh:mm:ss')
//将秒时间戳转换为时间格式
tree.moment(1577836800).format('YYYY-MM-DD hh:mm:ss')
//参数为空表示当前时间
tree.moment().format('YYYY-MM-DD hh:mm:ss')
//将毫秒时间戳转换为时间格式
tree.moment(1577836800123,2).format('YYYY-MM-DD hh:mm:ss')
//检测是否开启devtool
//开启后会禁止打开控制,否则会一直debuger
tree.debug.disableDebug()
//检测是否开启devtool,如果开启则返回true,否则返回false
tree.debug.isOpenDebugTool()