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

jj-core-fn

v2.0.10

Published

useful js func

Downloads

69

Readme

js工具函数(适用所有环境)

  • 重要更新!核心模块以及本工具函数基于typescript重构以及api简化,原基于class api废弃,暴露的$fn为自2.0改为对象,
  • 现支持typescript,以及js直接在html中引用
  • github : https://sunny-world.github.io/jj-core-fn/
  • 只要可以运行js的环境都可以支持,浏览器端、node都可以使用
  • 引用库,后续 $fn 直接当作全局进行使用
    import $fn from 'jj-core-fn'
  • html直接引用
    <script src="jj-core-fn/common/$fn.js"></script>
  • 浏览器环境js工具库请点击跳转

字符处理

默认处理非数值的内容为0

对非数字的内容,返回默认想展示的内容defaultVal || 0,否则返回原值

$fn.n(null) //返回0
$fn.n(1) //返回1
$fn.n('1') //返回'1'
$fn.n('1a') //返回0
$fn.n('1a',null) //返回null

默认处理空字符串为'--'

对undefined/null/''(空字符串),返回默认想展示的内容defaultVal || '--',否则返回原值

$fn.s(null) //返回'--'

判断是否有值

对undefined/null/''(空字符串)返回false,其他返回true

$fn.hasValue(null) //返回false

给URL添加参数

$fn.urlAddParams(url,{
    user:'admin'
})

将编码由utf8转为utf16

$fn.utf8to16(str) 

将编码由utf16转为utf8

$fn.utf16to8(str) 

对字符串进行base64编码

$fn.encodeBase64(str) 

对字符串进行base64解码

$fn.decodeBase64(str) 

数字处理

显示两位小数的金额

$fn.showMoney(34) //返回0.34
$fn.showMoney(1234) //返回12.34

千位符显示数字

$fn.showThousandMoney(1234) //返回1,234.00

时间处理

自定义格式

  • YMDhms直接替换对应时间单位,格式可自由替换
  • 没有参数直接返回Y-M-D h:m:s(如2018-01-01 12:21:45)
  • 有参数则直接替换
$fn.showDate() //返回当前时间2018-01-01 12:21:45
$fn.showDate('Y-M-D h:m:s',new Date('2018-01-01 12:21:45')) //返回2018-01-01 12:21:45
$fn.showDate('Y-M',new Date('2018-01-01 12:21:45')) //返回2018-01

距离当前时间差处理

获取参数时间戳距离当前的时差,超过1秒显示秒,超过1分显示分,超过1时显示时,超过1天显示天,超过1年显示*年

$fn.diffToNow(new Date()) //返回0秒

请我喝杯果汁呗~

Image textImage text