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

auxiliary-additions

v0.0.3

Published

辅助,补充underscore(工具函数,类扩展),兼容IE8+

Downloads

8

Readme

auxiliary-additions

Build Status

辅助,补充underscore(工具函数,类扩展),兼容IE8+

如何使用

如果你直接引入此文件:

<script src="./build/auxiliary.js" charset="utf-8"></script>

可以通过window.Auxiliary来使用

如果你使用模块化的机制:

var Auxiliary = require('auxiliary-additions');

直接require进来即可。

auxiliary-additions主要提供了一些日常用到的函数或者类,比如cookie表单跨域等,使用时你可以详细的阅读下列的文档。

Api

cookie

Create a cookie, valid across the entire site:

cookie.set('name', 'value');

Create a cookie that expires 7 days from now, valid across the entire site:

cookie.set('name', 'value', { expires: 7 });

Create an expiring cookie, valid to the path of the current page:

cookie.set('name', 'value', { expires: 7, path: '' });

Read cookie:

cookie.get('name'); // => 'value'
cookie.get('nothing'); // => undefined

Read all visible cookie:

cookie.get(); // => { name: 'value' }

Delete cookie:

cookie.remove('name');

Delete a cookie valid to the path of the current page:

cookie.set('name', 'value', { path: '' });
cookie.remove('name'); // fail!
cookie.remove('name', { path: '' }); // removed!

引用:https://github.com/js-cookie/js-cookie

url

处理一个字符串URL:

    var urlString = 'https://github.com/icepy?id=1';
    var obj = url.parse(urlString);

obj结构:

{
    "port": temp.port,
    "protocol": temp.protocol.replace(':', ''),
    "hash": temp.hash.replace('#', ''),
    "host": temp.host,
    "href": temp.href,
    "hostname": temp.hostname,
    "pathname": temp.pathname,
    "search": temp.search,
    "query": {}
}

拼接一个完整的url字符串:

    var urlString = 'https://github.com/icepy'
    var href = url.format(urlString,{
        query: {
            id: 1
        }
    });

    //https://github.com/icepy?id=1

将参数 to 位置的字符解析到一个绝对路径里:

    var url = url.resolve('github/icepy','../co')

返回指定文件名的扩展名称:

    var name = url.extname('img.jpg');

    // jpg

将search参数转换为obj:

    var obj = url.parseSearch('?id=1&k=2')

    //{id:1,k:2}

sheet

新建一个style.sheet对象,来标注新的css规则:

    sheet.insertRule()//

isNativeFunction

判断是否为原生函数

    isNativeFunction('alert')  //true

uniqueId

生成一个唯一id

    uniqueId('icepy')  //icepy1

AjaxForm

模拟表单Ajax提交:


//this.$el 为表单对象

var ajaxForm = AjaxForm.classInstanceAjaxForm(this.$el,{
    type:'img'
});
this.ajaxForm.done(function(cw){
    var loc = cw.location;
    var search = decodeURIComponent(loc.search);
    var query = url.parseSearch(search);
});
this.ajaxForm.fail(function(){
    
});

UploadFile

表单上传文件:

var uploadParams = {
  el: this.formDOM, //form dom 对象
  url: '', //上传地址
  data: ctrlData, //上传的元数据
  filename: 'img', //上传标识
  className: 'file' //上传input的 class name
};
this.upload = new UploadFile(uploadParams);
this.upload.done(function (response) {
  self.imageStateDOM.html(uploadDone);
  self.previewImage(response);
  self.trigger('uploadFileSuccess', response);
});
this.upload.fail(function () {
    //上传失败
});