212019.1
陆续收到听众的打赏,虽然不多,但是点燃了我的热情,才仅仅做了一期的Robust而已,没想到认可度很高,想我这种喜欢打持久战的人,一期根本满足不了。因为周末要去山西参加朋友婚礼,顺带完结多年想去北方玩的冲动,所以,下一期的Robust会早发(不会停更),我会趁晚上的事件陆续录好,周末之前上传到电播平台,Robust只会上传到企鹅FM和网易云音乐,其他平台要是转载,一定是盗版……竟然开始幻想盗版的事……公众号也会发,关注我的私人公众号 wwwtangshuangnet 最快收到上新消息。
12:56:26
已有0条回复
182019.1
Mimic Relative Positioning Inside an SVG with Nested SVGs
SVG动图
view-source:https://camo.githubusercontent.com/29765c4a32f03bd01d44edef1cd674225e3c906b/68747470733a2f2f63646e2e7261776769742e636f6d2f66616365626f6f6b2f6372656174652d72656163742d6170702f323762343261632f73637265656e636173742e737667
102019.1
js解析html属性列表
因为项目的一个小组件里面需要对类似html属性字符串进行解析,找了很久没有找到对应的库来做,干脆自己写一个。
function parseAttrs(source) {
let separator = /\s/;
let cursor = '';
let str = source.trim().replace(/\n+/g, ' ').replace(/\s+/g, ' ');
let length = str.length;
let attrs = [];
let current = null;
let type = 'key';
let reset = () => {
current = {
key: '',
value: ''
};
cursor = '';
};
reset();
for (let i = 0; i < length; i ++) {
let char = str.charAt(i);
let needPush = true;
// 遇到引号
if (char === '"' || char === "'") {
// 引号开始
if (!cursor) {
cursor = char;
type = 'value';
needPush = false;
}
// 引号结束
else if (cursor === char) {
cursor = '';
type = 'key';
needPush = false;
}
}
if (char === '=' && type === 'key') {
needPush = false;
}
if (/[\w\W]/.test(char) && needPush) {
current[type] += type === 'key' && char === ' ' ? '' : char;
}
// 遇到分隔符
if ((separator.test(char) && cursor === '') || i === length - 1) {
attrs.push(current);
reset();
}
}
return attrs;
}
思路非常简单,就是遍历整个字符串,遇到特殊标记就记录下来,再遇到特殊标记就结束一个属性的查找,最后得到一个数组。
19:03:52
已有0条回复

