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

@sanhuamao1/methodjs

v1.0.5

Published

EMS

Downloads

1

Readme

使用

EMS

import { download } from '@sanhuamao1/methodjs';
download('xxx');

CJS

const { formatTime } = require('@sanhuamao1/methodjs');
formatTime(new Date());

方法

Browser 浏览器相关

  • 普通下载:download(url: string, fileName?:string)
  • 下载音频:downloadMedia(url: string, fileName?:string)
  • 播放音频:playAudio(url: string, onError?:(err:Error)=>void)(只有当用户跟页面互动过,才会生效,否则会报错)

Date 时间相关

  • 解析时间:parseTime(timestamp: number | string, options)

    // 选项
    type TOptions = {
        type?: 'local' | 'utc' // 默认 local
    }
    
    // 调用
    parseTime(new Date().getTime(), {type:'local'})
    parseTime('2024-07-30 10:10:10')
    
    // 返回值
    {
        year:2024,
        month:7,
        day:30,
        hour:12,
        minute:20,
        second:20
    }
  • 格式化时间:formatTime(value: number | string, format = "YYYY-MM-DD hh:mm:ss")

    // 调用
    formatTime(new Date().getTime());
    formatTime('2024-07-30 10:10:10', 'YYYY年MM月DD日 hh:mm:ss'); // '2024年07月30日 10:10:10'
  • 格式化时间段:getDuration(seconds: number | string, options)

    // 选项
    type TOptions = {
       lang?: 'EN' | 'CN'; // 格式 默认CN
    };
    
    // 调用
    getDuration(3000); // 50分
  • 输入的时间距离当前时间的描述:getLatestDes(value: number | string, options)

    // 选项
    type TOption = {
       lang?: 'EN' | 'CN';
       maxDiff?: number; // 当间隔超过 maxDiff 时,显示具体时间
       minDiff?: number; // 当间隔小于 minDiff 时,显示“刚刚/just now”
    };
    
    // 调用
    getLatestDes('2024-07-30 10:10:10'); // 4 minutes ago

Tree

  • 根据id生成树:getTree(list: Array<any>, options)
    // 选项
    type TOptions = {
        selfField?: string, // 标识自身的字段名称
        parentField?: string // 指向父节点的字段名称
    }
    
    // 调用
    getTree([
        { id:1, value:1, parentId: null}
        { id:2, value:2, parentId: 1}
    ])