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

yanjs

v3.1.0

Published

This is just a common toolkit for the Front End

Downloads

21

Readme

yanjs

NPM version Build Status Coverage Status

This is a tiny common toolkit for the Front End

Installation

$ npm install yanjs

Example

var yanjs = require('yanjs');

API

快速使用

  • base64转换
yan.toBase64("中文abc123"); // "JUU0JUI4JUFEJUU2JTk2JTg3YWJjMTIz"
yan.fromBase64("JUU0JUI4JUFEJUU2JTk2JTg3YWJjMTIz"); // "中文abc123"
  • 格式转换
yan.toThousands(123456789); // 123,456,789

yan.toFormatDate("YYYY-MM-DD hh:ii:ss.mss WWW qq"); // "2018-01-08 03:50:39.102 星期一 01"
yan.toFormatDate("YYYY-MM-DD hh:ii:ss.mss WWWW qqqq",new Date(2018,00,02)); // "2018-01-02 12:00:00.000 星期二 01"

yan.toCamelCase('background-color'); // "backgroundColor"
yan.toCamelCase('-webkit-background-image'); // "WebkitBackgroundImage"
yan.toPascalCase('background-color'); // "BackgroundColor"
yan.toPascalCase('-webkit-background-image'); // "WebkitBackgroundImage"

yan.toUnicode("你好"); // '\u4f60\u597d'

yan.toByte('2k'); // 2048

yan.formatStr('My name is {0}', 'Yangfan'); // 'My name is Yangfan'
yan.formatStr("My name is {0}, and I'm {1} years old", ['Yangfan', 24]); // "My name is Yangfan, and I'm 24 years old"
  • 数据序列化
yan.params.serialize({"name": "Yangfan","age": 24}); // 'name=Yangfan&age=24'
yan.params.serialize({"name":"Yangfan","fruits":["apple","banana"]}, true); // 'name=Yangfan&fruits=apple&fruits=banana'
yan.params.reSerialize('name=Yangfan&age=24'); // {"name": "Yangfan","age": "24"}
yan.params.reSerialize('name=Yangfan&fruits=apple&fruits=banana'); // {"name": "Yangfan","fruits": ["apple", "banana"]}
  • Url解析
yan.urlParse("http://yanfan.com:83/home/disc/test.html#query?name=yan&age=100"); // {protocol: "http", username: "", password: "", host: "yanfan.com:83", port: "83", …}
  • 获取、设置、删除cookie
// 判断是否存在此cookie
yan.docCookie.has("user_id");
// 设置
yan.docCookie.set("user_id", "12fdsa4f4a", {
  expires:new Date(2018,12,31), 
  path:"/blog", 
  domain:".yangfan.com",
  isSecure: true
});
// 获取
yan.docCookie.get("user_id");
// 删除
yan.docCookie.remove("user_id");
  • Ajax
// ajax
yan.http2({
  url:"yangfan.com/post",
  method:"post",
  data:{
    name:"jobs",
    age:100
  },
  success:function (data) {},
  error:function (err) {}
});
// jsonp
yan.getJSON("yangfan.com/get",{
  name:"jobs",
  age:100
},success:function (data) {},
error:function (err) {});
  • 浏览器
yan.isIE; // true | false
yan.browserDetail; // {name: "chrome", version: "69.0.3497.100"}

完整配置

yan.docCookie.has(key)
yan.docCookie.get(key)
yan.docCookie.set(key, val[,{ expires, path, domain, isSecure }])
yan.docCookie.remove(key[,{ path, domain }])

yan.http2({url[ ,method[ ,data[ ,responseType[ ,success[ ,error[ ,isAuth[ ,cancelToken[ ,timeout]]]]]]]]}) yan.getJSON(url,data,success,error);

yan.toFormatDate(fmt[ ,date])

Contributing

  • Fork this Repo first
  • Clone your Repo
  • Install dependencies by $ npm install
  • Checkout a feature branch
  • Feel free to add your features
  • Make sure your features are fully tested
  • Publish your local branch, Open a pull request
  • Enjoy hacking <3

MIT license

Copyright (c) 2018 Yangfan

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.


built upon love by docor v0.3.0