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

vcore

v0.5.7

Published

`vcore` 是一个用于处理url,元素选择器,dom事件绑定,jsonp数据请求的基础库。

Downloads

4

Readme

vcore

vcore 是一个用于处理url,元素选择器,dom事件绑定,jsonp数据请求的基础库。

USE

npm install vcore
const vcore = require('vcore'),
    $cookie = vcore.cookie,
    $url = vcore.url,
    $element = vcore.element,
    $event = vcore.event,
    $jsonp = vcore.jsonp;

COOKIE

Get cookie

/**
 * 获取cookie值
 * @param  {string} name 需要获取的cookie名称
 * @return {string} 对应的cookie值或''
 */
$cookie.get(name);

Set cookie

/**
 * 设置cookie
 * @param  {string} name    cookie名称
 * @param  {string} val     cookie值
 * @param  {object} option  [选填] 设置选项
 */
$cookie.set(name,val,option)

option选项:

{
    path:'/',
    domain:location.hostname,
    expires:0
} 

Del cookie

/**
 * 删除cookie
 * @param  {string} name    需要删除的cookie名称
 */
$cookie.del(name);

URL

Get url parameter

/**
 * 获取url参数
 * @function get
 * @param  {string} name 参数名称
 * @return {string} 对应的参数
 */
$url.get(name);

Set url parameter

/**
 * 设置url参数
 * @function set
 * @param  {string} name 参数名称
 * @param  {string} val  参数值
 */
$url.set(name,val);

Url to Json

/**
 * 将url参数转为Json对象
 * @function toJson
 * @param  {string} search [选填] url参数,默认即`location.search`参数部分
 * @return {Object} 返回转换出的json对象
 */
$url.toJson(search)

Json to url parameter

/**
 * 将Json对象转换为url参数
 * @function parse
 * @param  {Object} obj json
 * @return {string} 返回url参数字符串
 */
$url.parse(obj)

Element

Create Element

/**
 * 创建HTML元素
 * @param  {string} html html字符串
 * @returns Array   返回html元素
 */
$element.create(html);

Get Dom

/**
 * 获取HTML元素
 * @param  {string} selector 选择器('.class'、'#id'、'tag'),父级元素
 * @param  {HTMLElement} parent [选填] 父元素以提升低版本下元素获取速度,默认为document
 * @returns Array 返回一个数组元素
 */
$element.get(html,parent);

Event

Add Event

/**
 * 为HTML元素添加事件
 * @param  {HTMLElement} dom 需要绑定事件的dom元素
 * @param  {string} type 事件类型,例如:`click、mouseover、...`
 * @param  {functon} fun 需要执行的函数
 */
$event.add(dom,type,fun);

Remove Event

/**
 * 移除HTML元素上的指定事件
 * @param  {HTMLElement} dom 需要移除事件的dom元素
 * @param  {string} type 事件类型,例如:`click、mouseover、...`
 * @param  {functon} fun 需要移除的函数
 */
$event.remove(dom,type,fun);

Remove all events

/**
 * 移除HTML元素上所有指定类型的事件
 * @param  {HTMLElement} dom 需要移除事件的dom元素
 * @param  {string} type 事件类型,例如:`click、mouseover、...`
 */
$event.removeAll(dom,type);

Prevent default

/**
 * 阴止HTML元素的默认事件
 * @param  {Event} event 对应的event
 */
$event.preventDefault(event);

Stop propagation

/**
 * 阴止HTML元素事件冒泡
 * @param  {Event} event 对应的event
 */
$event.stopPropagation(event);

JSONP

/**
 * Jsonp封装
 * @param  {option} Object 请求参数(见下方示例)
 */
$jsonp({
    url:'',                     // 需要请求的url
    data:{},                    // url参数
    success:(data)=>{           // 成功回调
    },
    fail:(err)=>{               // [选填] 出错回调
    },
    callback:'jsoncallback',    // [选填] 约定的名称,默认:`jsoncallback`
    timeout:5000                // [选填] 超时设置,默认:`5000ms`
})

License

MIT