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

yu-front

v1.7.3

Published

仅用于web前端

Downloads

4

Readme

yu-front

仅用于web前端,在webpack中引入本模块,即可使用下面dom对象的扩展函数,IE10及以上

安装

npm install yu-front --save

引入

import { 
	calendar,
	queueAnimate,
	css,
	ajax, 
	upload,
	cookie, 
	tick,
	clearTick
} from 'yu-front';

获取指定月份的月历

//calendar(year,month);
//1、返回格式的月历
let monthly = calendar(2019,8);
console.log(monthly)
//打印结果:
[
	["日", "一", "二", "三", "四", "五", "六"],
	["", "", "", "", 1, 2, 3],
	[4, 5, 6, 7, 8, 9, 10],
	[11, 12, 13, 14, 15, 16, 17],
	[18, 19, 20, 21, 22, 23, 24],
	[25, 26, 27, 28, 29, 30, 31]
]


//2、返回日期和星期x对齐的月历
let monthly = calendar(2020,2,true);
console.log(monthly)
//打印结果:
{
	date:[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29],
	week:[6, 0, 1, 2, 3, 4, 5, 6, 0, 1, 2, 3, 4, 5, 6, 0, 1, 2, 3, 4, 5, 6, 0, 1, 2, 3, 4, 5, 6]
}
//week数组中的6代表星期六,0代表星期日,1代表星期一

队列动画:queueAnimate(元素,队列动画数组,config);

let div = document.querySelector('div');
let queue = [{ width:'200px' },{ width:'300px',height:'50px' }];
let config = { duration:300,delay:0,timing:'ease' };

//队列动画
queueAnimate(div,queue,config).then(record=>{
	//动画完成
	console.log(record) //record记录该div的css样式
})

//非队列动画
queueAnimate(div,{ width:'100px',height:'100px' },300).then(record=>{
	//动画完成
	console.log(record) //record记录该div的css样式
})

获取或设置dom元素的css属性(已含兼容性处理)

let div = document.querySelector('div');
//获取dom元素当前样式
let str = css(div,"width");  

//设置dom元素的样式
css(div,{ width:"100px",height:"50px" });  

ajax(options):向服务器发送请求,返回Promise


let options = {
	method:'get'|'post'|'put'|'delete',  //请求方法
	url:'xxx/api',   			//请求地址
	data:{ id:1,user:'ming' }|'id=1&user=ming', //请求参数
	header:{ '请求头字段':'字段值' },  //请求头
	type:''|'json'|'blob'|'arraybuffer'|'document', //响应的数据类型
}

ajax(options).then( result=>{
    let { headers,data } = result;
    //headers是响应头
    //data是响应数据
} );

ajax上传文件:upload(input元素,'服务器url',上传进度回调函数).then(上传成功回调函数)

let input = document.getElementById('input_id');

input.oninput = function(event){
	upload(event.currentTarget,'/服务器地址',(e)=>{
		console.log(e);
	}).then(res=>{});		//上传成功回调
}

//如果上传文件时,也需要发送参数数据
input.oninput = function(event){
	upload(event.currentTarget,{ url:'/服务器地址',data:{ id:2,username:'小明' } },(e)=>{
		console.log(e);
	}).then(res=>{});		//上传成功回调
}

cookie:document.cookie增删改查

/* cookie.set(key,value,expires) */
cookie.set('abc','123',3600);   //增或改cookie,该cookie的有效时间是3600秒以内

/* cookie.get(key) */
cookie.get('abc');     //获取指定cookie
cookie.get();          //获取所有cookie

/* cookie.delete(key) */
cookie.delete('abc');  //删除指定的cookie

/* cookie.clear() */
cookie.clear();        //清空cookie(删除所有cookie)

tick(calback)、clearTick(timer):window.requestAnimationFrame和window.cancelAnimationFrame的简写

let num = 0;
function fn(){
    conosle.log(num++);
    if(num<100) tick(fn);
}
fn();