proyang / outils Goto Github PK
View Code? Open in Web Editor NEW:rocket: 前端业务代码工具库
Home Page: https://www.npmjs.com/package/outils
License: MIT License
:rocket: 前端业务代码工具库
Home Page: https://www.npmjs.com/package/outils
License: MIT License
function parseQueryString(url) {
url = url == null ? window.location.href : url
var search = url.substring(url.lastIndexOf('?') + 1)
if (!search) {
return {}
}
return JSON.parse('{"' + decodeURIComponent(search).replace(/"/g, '\"').replace(/&/g, '","').replace(/=/g, '":"') + '"}')
}
以上这个方法为什么不直接写出url = url || window.location.href? 这样做是有什么好处吗?
assert.notEqual(outils.arrayEqual([0, 2, 3, 4], [1, 2, 3])) ,不管outils.arrayEqual()返回的结果是true或者false,这个测试应该都是可以通过的吧.
assert.notEqual() 我看api 好像不是这样用的.
大神能给解惑一下吗,是不是我的理解有误
请问test文件夹里面的文件是在哪里引用outils的?
建议增加判断数组包含的功能,判断一个数组是否包含另外一个数组中
现在需要手动一个个require,我自己改成了自动require,代码如下,亲测没问题。
/**
* @desc webpack打包入口文件
*/
let moduleExports = {};
const r = require.context('./', true, /^\.\/.+\/.+\.js$/);
r.keys().forEach(key => {
let attr = key.substring(key.lastIndexOf('/') + 1, key.lastIndexOf('.'));
moduleExports[attr] = r(key);
});
module.exports = moduleExports;
vue中如何全局使用?难倒要每个vue组件使用它都要import引入?
我测试了一下,如果把返回pc端的语句放在返回移动端的语句前面,这样无论是在pc端还是移动端,这样都只会返回pc端的类型,因此需要把移动端的返回语句提前,这样,先检查移动端类型后,再检查pc端的类型,这样比较准确,下面是我改完之后的代码,亲测返回准确,希望采纳
function getOS() {
var userAgent = 'navigator' in window && 'userAgent' in navigator && navigator.userAgent.toLowerCase() || '';
var vendor = 'navigator' in window && 'vendor' in navigator && navigator.vendor.toLowerCase() || '';
var appVersion = 'navigator' in window && 'appVersion' in navigator && navigator.appVersion.toLowerCase() || '';
if (/iphone/i.test(userAgent) || /ipad/i.test(userAgent) || /ipod/i.test(userAgent)) return 'ios';
if (/win/i.test(appVersion) && /phone/i.test(userAgent)) return 'WindowsPhone';
//WindowsPhone一定要放在Android前面,否则使用WindowsPhone设备时,还是会返回Android
if (/android/i.test(userAgent)) return 'Android';
if (/mac/i.test(appVersion)) return 'MaxOSX';
if (/win/i.test(appVersion)) return 'Windows';
if (/linux/i.test(appVersion)) return 'Linux';
}
假设范围为(2,10),即min = 2,max = 10;
这时用 Math.floor(Math.random() * (max-min) + min)去求值是有错误的,因为永远输出不了10.
Math.random() * (max-min) = Math.random * 8,最大不可能为8,同理Math.floor(Math.random() * (max-min) + min)不可能输出10.
正确代码为:
Math.floor(Math.random() * (max-min+1) )+ min;
我会经常用到一个通过“省份.城市”获取其经纬度,这个需要吗? @proYang
如题,我试着自己发布了一份 但是报index.d.ts' is not a module
199号段也已经开放了
你好,现在这个库使用的是commonjs,我想改成用es6的模块化,请问应该怎么修改。谢谢。
根据屏幕高度变化判断并不准确,iphoneX在 微信浏览器环境下,导航栏的显示隐藏也会导致可视高度发生变化
provider: npm
email: "$NPM_EMAIL"
api_key: "$NPM_TOKEN"
skip_cleanup: true
我也是这么写的,不过travis 报错了,我看官方文档里面email和api_key都是直接写出来的,请教该怎么写
如题,如在ng项目(typescript)中使用,需要.d.ts文件来支持智能提示
打包之后所有js,全部到根目录下了,是正常情况吗
return JSON.parse('{"' + decodeURIComponent(search).replace(/"/g, '\"').replace(/&/g, '","').replace(/=/g, '":"') + '"}')
decodeURIComponent 过早了吧,
& , = 特殊字符
JSON.parse 之后 枚举处理吧
我之前一直想封装一个获取倒计时的函数。
计算天、时、分、秒、毫秒
。这些都没问题。
计算剩余年、月
感觉太复杂,就不了了之了。
楼主这个我大概看了一下,月按30
天算的,年按12个月
算的。只能是个大致的时间。然而,作为一个强迫症患者,需要知道未来的一个时间距离现在的准确年月日时分秒
。
仅仅一点小建议~~~
不知道主人是想做 shadow equal
还是 deep equal
,感觉是两种都想实现,但都实现得不太好。想法如下,如果有错误的还请指出,一起进步哈🙃
首先,如果是第一行代码:
if (arr1 === arr2) return true;
这行代码貌似是想来个 shadow equal
,就是只比较两数组引用相等,而不是两个数组的每个值相等。
然后呢,后面的几行代码又有点想做deep equal
的味道,就是比较两个数组每个值都相等,那么他们相等。
所以建议写两个equal
函数:
// arrayShadowEqual.js
function arrayShadowEqual(arr1, arr2) {
if (arr1 === arr2) return true;
return false;
}
// arrayDeepEqual.js
function arrayDeepEqual(arr1, arr2) {
if (arr1.length !== arr2.length) {
return false;
}
for (var i = 0; i < arr1.length; i++) {
if (arr1[i] !== arr2[i]) {
return false;
}
return true;
}
再提一个小建议哈, JavaScript
中不等应该要坚持使用 !==
。
(完)
setCookie 的value 包含=号的时候,比如base64的asdasd==
getCookie 会把=号去除,变成asdasd
deploy:
...
on:
branch: production
我看文档也不是很理解on 到底是干什么用的,看你的项目分支里面也有production.能稍微给我讲解一下吗?本人有点菜,诚心学习.先谢谢了
if (/iphone/i.test(userAgent) || /ipad/i.test(userAgent) || /ipod/i.test(userAgent)) 'ios'
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.