This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
* | |
*:after | |
*:before | |
box-sizing border-box | |
:root | |
--bg #fafafa | |
body | |
display flex |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 查看元素信息 | |
(function SpyOn() { | |
const _id = 'spyon-container', | |
_posBuffer = 3; | |
function init() { | |
document.body.addEventListener('mousemove', glide); | |
document.body.addEventListener('mouseover', show); | |
document.body.addEventListener('mouseleave', hide); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Tree { | |
constructor(arr) { | |
let obj = {} | |
let subObj = obj | |
arr.forEach((item, index) => { | |
if (index == arr.length - 1) { | |
subObj['leaves'] = [item] | |
} else { | |
subObj[item] = {} | |
subObj = subObj[item] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Intl { | |
constructor(set) { | |
this.set = set | |
} | |
get(keyStr) { | |
const keys = keyStr.split('.') | |
let value = this.set | |
for (let i = 0; i < keys.length; i++) { | |
if (value[keys[i]]) { | |
value = value[keys[i]] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 小数部分也会被加千分位 | |
// const regex = /(?=(\B\d{3})+(?!\d))/gm; | |
// 小数部分不转换 | |
const regex = /(^|\s)\d+/g, (m) => m.replace(/(?=(?!\b)(\d{3})+$)/g; | |
const str = `1234567890`; | |
const subst = `,`; | |
// The substituted value will be contained in the result variable |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const str = 'https://www.baidu.com?name=jawil&age=23' | |
function transformQuery(url) { | |
const r = new RegExp(`[?&]([a-zA-Z]+)=([^&]*)`, 'g') | |
let obj = {} | |
let match = r.exec(url) | |
while (match !== null) { | |
obj[match[1]] = match[2] | |
match = r.exec(url) | |
} | |
return obj |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 别看这个模板引擎代码很少,但是活用了正则、将字符串转为可以行代码两个知识点 | |
const a = { | |
a: 1, | |
b: { | |
c: 2, | |
e: ['Array'] | |
} | |
} | |
const tpl = `你好{{ a ? '真' : '假'}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function baseGet(object, path) { | |
path = isKey(path, object) ? [path + ''] : baseCastPath(path); | |
var index = 0, | |
length = path.length; | |
while (object != null && index < length) { | |
object = object[path[index++]]; | |
} | |
return (index && index == length) ? object : undefined; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private function __removeRedlock() | |
{ | |
Redis::del("{$this->redisKey}_redlock"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 加锁——允许设置最长等待时间,单位秒 | |
* 在等待期内持续争锁 | |
*/ | |
private function __addRedlock($expire = 3) | |
{ | |
$time = time(); | |
$lock = null; | |
do { | |
$lock = Redis::set("{$this->redisKey}_redlock", true, 'ex', 1, 'nx'); |
NewerOlder