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

ujs_js

v1.0.4

Published

javascript methods

Downloads

4

Readme

ujs - 各类方法集

  • 调用方法

// common.js方式
const ujs = require('ujs')

// 直接调用
<script src="ujs.js"></script>
  • EmitClass 事件监听

const ujs = require('ujs')
const Events = new ujs.EmitClass()

Events.on(name, fn) // 注册监听方法
Events.once(name, fn) // 注册仅一次的监听方法
Events.emit(name, argv) // 事件分发
Events.off(name, fn) // 取消当前监听事件
Events.maxListenNums = nums // 设置最大监听数
Events._currentListenEventsName // 获取当前所有监听事件名称
  • Worker 线程创建

const ujs = require('ujs')
const worker = new ujs.ExecWorker()

// 接收子线程发送的消息,并绑定到自定义方法
worker.bind('message', () => { // ...todo })

// 发送消息给子线程
worker.send(msg)

// 主线程window主动关闭子线程
worker.closeWorker()
  • insert 方法

// 向ujs对象注入自定义方法
ujs.insert(name, fn)
  • 变量类型判定

isString() // 是否为字符串
isObject() // 是否为对象
isFunction() // 是否为函数 
isArray() // 是否为数组
isNumber() // 是否为数字
isHas() // 数组或对象中是否有已知值
isMail() // 检测邮箱格式是否正确
isUndefined() // 变量是否存在
  • 解析地址栏参数

/**
* return {object} {参数名, 值}
*/
ujs.httpParams()
  • 格式化参数

ujs.formatParams(params) // 拼接成name=xxx&num=1格式 
  • 对象深度copy

ujs.copy(obj)
  • 文件下载

/**
* params url {string} 下载地址
* params method {string} 请求方式(post,get,head等)
* params header {Object} 请求头信息
* params progressCallback {Function} 下载进度callback
*/
ujs.downloadFile({url, method, headers, progressCallback})
  • ajax请求

/**
* params url {string} 请求地址
* params method {string} 请求方式(post,get,head等)
* params header {Object} 请求头信息
* params data {Object} 请求参数
* params type {string} 类型(区分上传与一般接口请求)
*/
ujs.ajax({url, method, headers, data, type})
  • uploadFile 文件上传

/**
* params url {string} 上传地址
* params file 文件
* params type {string} 文件类型
* params argv 扩展参数(需写入FormData中的)
*/
ujs.uploadFile({url, file, type, argv})
  • sort 数组排序(二分法快速排序)

ujs.sort([...argvs])
  • formatDate 自定义日期格式

const date = ujs.formatDate({format: 'yyyy-mm-dd'})
console.log(date)

'2019-08-24'