This file contains hidden or 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
/** | |
* 获取对象obj的属性key的值,属性key支持多层,如 a.b.c | |
* | |
* @sample | |
* var obj = { a: { b: { c: 1 } } } | |
* var result = getProperty(c,'a.b.c'); | |
* // 结果为 1 | |
* | |
* @param obj 目标对象 |
This file contains hidden or 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
var identityCodeValid = function (code) { | |
var city = { | |
11: "北京", | |
12: "天津", | |
13: "河北", | |
14: "山西", | |
15: "内蒙古", | |
21: "辽宁", | |
22: "吉林", |
This file contains hidden or 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
/** | |
* 下载统一接口,判断浏览器是否支持a标签download属性,如果不支持采用form表单提交方式下载文件 | |
* @param url | |
* @param fileName | |
*/ | |
export function download(url: string, fileName?: string) { | |
const isSupportDownload = 'download' in document.createElement('a'); | |
if (isSupportDownload) { |
This file contains hidden or 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
// download & parse | |
if ('serviceWorker' in navigator) { | |
navigator.serviceWorker.register('./sw.js?' + new Date().getTime()).then(function(registration) { | |
// 注册成功 | |
console.log('ServiceWorker registration successful with scope:' + registration.scope); | |
}).catch(function(err) { | |
// 注册失败1 | |
console.log('ServiceWorker registration failed:', err); | |
}); | |
} |
This file contains hidden or 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
/*-------------------------------------------------------------- | |
* Copyright (c) Nickbing Lao<[email protected]>. All rights reserved. | |
* Licensed under the MIT License. | |
*-------------------------------------------------------------*/ | |
const fs = require("fs"); | |
const path = require("path"); | |
const reg = /(main|styles|scripts|polyfills|inline).[0-9a-z]*.bundle.(css|js)/g; | |
let indexPagePath = path.join(__dirname, './dist/index.html'); |
This file contains hidden or 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
"use strict" | |
/**事件式编程 */ | |
class EventEmiter { | |
constructor(debug) { | |
this._debuger_ = !!debug; | |
this._callback_ = {}; | |
this.commonApi(); | |
} |
This file contains hidden or 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 Stack = (() => { | |
// 闭包使得item为私有变量,避免外部调用(ES6无私有变量) | |
let item = new WeakMap(); | |
// 模拟实现栈 Stack | |
class Stack { | |
constructor() { | |
item.set(this, []); | |
} |
This file contains hidden or 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
/** | |
* @author: giscafer ,https://github.com/giscafer | |
* @date: 2018-07-25 15:59:02 | |
* @description: 类实现队列模拟 | |
*/ | |
const Queue = (() => { | |
// 闭包实现私有变量 | |
let item = new WeakMap(); |
This file contains hidden or 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 LinkNode { | |
constructor(element) { | |
this.element = element; | |
this.next = null; | |
} |
This file contains hidden or 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 HashTable { | |
constructor() { | |
this.table = []; | |
} | |
/* 散列函数 */ | |
loseloseHashCode(key) { |