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

@nsrd/nus

v1.1.1

Published

nus is a javascript utils for NeuqSoft RD

Downloads

1

Readme

@nsrd/nus

nus is a javascript utils for NeuqSoft RD.

Install

iife

<script src="https://cdn.jsdelivr.net/npm/@nsrd/nus/dist/nus.min.js"></script>

nus will be registered as a global variable.

esm

$ npm install @nsrd/nus --save
import nus from "@nsrd/nus";

Usage

date

/**
 * 日期格式化
 * @param1 {String/Date} Date 实例 new Date() 或时间戳 new Date().getTime(),支持 ISO 8601、RFC 2822
 * @param2 {String} 期待格式,日期字符格式与 https://momentjs.com/docs/#/parsing/string-format/ 保持一致
 * @returns {String} 期待格式的日期字符串
 */

nus.date.format(new Date(), "YYYY-MM-DD HH:mm:ss [或] YYYY[年]MM[月]DD[日] HH[时]mm[分]ss[秒]");
// output = 2020-10-28 15:17:13 或 2020年10月28日 15时17分13秒

/**
 * 日期格式化
 * @param1 {String} 日期字符串
 * @param2 {String} 日期字符串的格式,日期字符格式与 https://momentjs.com/docs/#/parsing/string-format/ 保持一致
 * @param3 {String} 期待格式,日期字符格式与 https://momentjs.com/docs/#/parsing/string-format/ 保持一致
 * @returns {String} 期待格式的日期字符串
 */
nus.date.format("20201027085959", "YYYYMMDDHHmmss", "YYYY-MM-DD HH:mm:ss [或] YYYY[年]MM[月]DD[日] HH[时]mm[分]ss[秒]");
// output = 2020-10-27 08:59:59 或 2020年10月27日 08时59分59秒

device

/**
 * 获取设备系统
 * @returns {String} 可能值如下
 *   - unknown 未知系统
 *   - windows Windows 系统
 *   - osx OSX 系统
 *   - linux Linux 系统
 *   - android Android 系统
 *   - ios iOS 系统
 */
nus.device.getDevice();
// output = windows

/**
 * 获取浏览器信息
 * @returns {Object} 可能值如下
 *   - {type:"unknown",version:"unknown"} 未知浏览器
 *   - {type:"ie",version:"11.0"} IE 浏览器与版本号,支持 IE11 及以下版本号
 *   - {type:"chrome",version:"unknown"} Chrome 浏览器,无版本号
 *   - {type:"firefox",version:"unknown"} Firefox 浏览器,无版本号
 *   - {type:"safari",version:"unknown"} Safari 浏览器,无版本号
 *   - {type:"opera",version:"unknown"} Opera 浏览器,无版本号
 *   其他国产浏览器当前未判断
 */
nus.device.getBrowser();
// output = {type: "chrome", version: "unknown"}

generator

/**
 * 生成 uuid
 * @param1 {Boolean}
 *   - true uuid 为 32 位,无连字符 -
 *   - void/false uuid 为 36 位,其中 4 位连字符 -
 * @returns {String} uuid
 */
nus.generator.uuid(true);
// output = 53fd33f206b1415090b20477d9ec554a
nus.generator.uuid();
// output = 6d0d801d-909f-4ada-9d2f-c7f64c8372b4

/**
 * 生成 MD5
 * @param1 {String} 原始字符串
 * @param2 {Boolean}
 *   - true md5 为大写字符
 *   - void/false md5 为小写字符
 * @returns {String} 原始字符串的 MD5
 */
nus.generator.MD5("huangrx", true);
// output = DF34F01DA54CB20ED583980B91DDA7AD
nus.generator.MD5("huangrx");
// output = df34f01da54cb20ed583980b91dda7ad

/**
 * 重复字符串
 * @param1 {String} 原始字符串
 * @param2 {Number} 重复次数
 * @returns {String} 重复字符串
 */
nus.generator.repeatedString("huangrx666 ", 6);
// output = huangrx666 huangrx666 huangrx666 huangrx666 huangrx666 huangrx666 

jsbridge

/**
 * 调用原生 APP JSBridge 方法
 * iOS 实现 https://github.com/marcuswestin/WebViewJavascriptBridge
 * Android 实现 https://github.com/lzyzsd/JsBridge
 * @param1 {String} 与 APP 约定的方法名
 * @param1 {Object} 向 APP 传递的参数
 * @returns {Promise} then 中返回 APP 回传数据,catch 中返回异常信息 can't find jsbridge!
 */
nus.jsbridge.callAPP("login", {username: "your_name", password: "your_pwd"}).then(res => {
  console.log("[jsbridge][callAPP]", res);
}).catch(err => {
  console.error("[jsbridge][callAPP]", err);
});

masker

/**
 * 身份证号掩码
 * @param1 {String} 身份证号
 * @param2 {Number} 结尾保留几位
 * @returns {String} 掩码身份证号
 */
nus.masker.maskIDCard("110101199003079032", 4);
// output = **************9032
nus.masker.maskIDCard("110101199003079032", 8);
// output = **********03079032

/**
 * 社保卡号掩码
 * @param1 {String} 社保卡号
 * @returns {String} 掩码社保卡号
 */
nus.masker.maskSSCard("C12345678");
// output = C****5678

/**
 * 银行卡号掩码
 * @param1 {String} 银行卡号
 * @returns {String} 掩码银行卡号
 */
nus.masker.maskBankNo("998801123456789112");
// output = **** **** **** 9112

/**
 * 中文姓名掩码
 * @param1 {String} 中文姓名
 * @returns {String} 掩码中文姓名
 */
nus.masker.maskChineseName("张三");
// output = 张*
nus.masker.maskChineseName("张三丰");
// output = 张*丰

url

/**
 * 获取 URL Query 参数对象
 * @param1 {Void/String} URL
 * @returns {Object} query 对象
 */
nus.url.getQuery();
// output = {}
nus.url.getQuery("https://www.baidu.com?a=b&c=d&d_e=f_j");
// output = {a: "b", c: "d", d_e: "f_j"}

validator

/**
 * 是否是中文
 * @param1 {String} 字符串
 * @returns {boolean}
 */
nus.validator.isChinese("我是大好人");
// output = true

/**
 * 是否是中文姓名
 * @param1 {String} 字符串
 * @returns {boolean}
 */
nus.validator.isChineseName("张三丰");
// output = true
nus.validator.isChineseName("张3丰");
// output = false

/**
 * 是否是身份证号
 * @param1 {String} 字符串
 * @returns {boolean}
 */
nus.validator.isIDCard("110101199003079032");
// output = true
nus.validator.isIDCard("123456789012345678");
// output = false

/**
 * 是否是手机号
 * @param1 {String} 字符串
 * @returns {boolean}
 */
nus.validator.isMobileNumber("15712341234");
// output = true
nus.validator.isMobileNumber("12312341234");
// output = false

/**
 * 是否是邮编
 * @param1 {String} 字符串
 * @returns {boolean}
 */
nus.validator.isPostCode("066000");
// output = true

/**
 * 是否是电子邮箱
 * @param1 {String} 字符串
 * @returns {boolean}
 */
nus.validator.isEmail("[email protected]");
// output = true

/**
 * 是否是 URL 地址
 * @param1 {String} 字符串
 * @returns {boolean}
 */
nus.validator.isURL("https://google.com");
// output = true
nus.validator.isURL("https://google.com/#/i?q=p");
// output = true

/**
 * 是否是 IP 地址
 * @param1 {String} 字符串
 * @returns {boolean}
 */
nus.validator.isIP("10.19.92.210");
// output = true