npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

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();
  1. Numeral high-precision four arithmetic operations

  2. Moment time processing

  3. FetchJson request and return JSON, refer to fetch for usage

  4. FetchText request and return text, refer to fetch for usage

  5. 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

  1. numeral 高精度四则运算
  2. moment 时间处理
  3. fetchJson 请求,并返回json,用法参考fetch
  4. fetchText 请求,并返回text,用法参考fetch
  5. 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()