
This is a tiny common toolkit for the Front End
$ npm install yanjs
var yanjs = require('yanjs');
yan.toBase64("中文abc123");
yan.fromBase64("JUU0JUI4JUFEJUU2JTk2JTg3YWJjMTIz");
yan.toThousands(123456789);
yan.toFormatDate("YYYY-MM-DD hh:ii:ss.mss WWW qq");
yan.toFormatDate("YYYY-MM-DD hh:ii:ss.mss WWWW qqqq",new Date(2018,00,02));
yan.toCamelCase('background-color');
yan.toCamelCase('-webkit-background-image');
yan.toPascalCase('background-color');
yan.toPascalCase('-webkit-background-image');
yan.toUnicode("你好");
yan.toByte('2k');
yan.formatStr('My name is {0}', 'Yangfan');
yan.formatStr("My name is {0}, and I'm {1} years old", ['Yangfan', 24]);
yan.params.serialize({"name": "Yangfan","age": 24});
yan.params.serialize({"name":"Yangfan","fruits":["apple","banana"]}, true);
yan.params.reSerialize('name=Yangfan&age=24');
yan.params.reSerialize('name=Yangfan&fruits=apple&fruits=banana');
yan.urlParse("http://yanfan.com:83/home/disc/test.html#query?name=yan&age=100");
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");
yan.http2({
url:"yangfan.com/post",
method:"post",
data:{
name:"jobs",
age:100
},
success:function (data) {},
error:function (err) {}
});
yan.getJSON("yangfan.com/get",{
name:"jobs",
age:100
},success:function (data) {},
error:function (err) {});
yan.isIE;
yan.browserDetail;
yan.docCookie.has(key)
yan.docCookie.get(key)
yan.docCookie.set(key, val[,{ expires, path, domain, isSecure }])
yan.docCookie.remove(key[,{ path, domain }])
| prop |
value |
ps |
| key |
String |
cookie名 |
| val |
String |
cookie值 |
| expires |
Date|String(UTC) |
过期时间 |
| path |
String |
默认为当前文档位置的路径,路径必须为绝对路径 |
| domain |
String |
默认为当前文档位置的路径的域名部分 |
| isSecure |
Boolean |
cookie只会被https传输 |
yan.http2({url[ ,method[ ,data[ ,responseType[ ,success[ ,error[ ,isAuth[ ,cancelToken[ ,timeout]]]]]]]]})
yan.getJSON(url,data,success,error);
| prop |
value |
ps |
| url |
String |
请求地址 |
| method |
String |
请求方法,默认“GET” |
| headers |
Object |
请求头信息 |
| responseType |
String('arraybuffer','blob','document','json','text','stream') |
请求返回数据的类型,默认“json” |
| data |
Object|String |
请求数据 |
| success |
Function |
请求成功的回调,接受一个参数(data) |
| error |
Function |
请求失败的回调,接受一个参数(err) |
| complete |
Function |
无论成功失败,都会调用次函数,并且在success或error之前执行 |
| isAuth |
Boolean |
是否添加验证头信息,默认不添加 |
| cancelAllRequest |
Boolean |
是否取消其他进行中的请求 |
| timeout |
Number(ms) |
超时(单位毫秒) |
yan.toFormatDate(fmt[ ,date])
| prop |
value |
ps |
| fmt |
String |
自定义格式(注意大小写) (“Y”:年,“M”:月,“D”:日,“h”:时,“i”:分,“s”:秒,“mss”:毫秒,“W”:星期,“q”:季度) |
| date |
Date |
指定日期 |
- 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
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