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
// from: https://mp.weixin.qq.com/s/qxi_28ozTZqjLeJNlpR6rA | |
// 来自https://developer.mozilla.org/en-US/docs/Glossary/Base64#the_unicode_problem. | |
function base64ToBytes(base64) { | |
const binString = atob(base64); | |
return Uint8Array.from(binString, (m) => m.codePointAt(0)); | |
} | |
// 来自https://developer.mozilla.org/en-US/docs/Glossary/Base64#the_unicode_problem. | |
function bytesToBase64(bytes) { | |
const binString = String.fromCodePoint(...bytes); |
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
function loadScript(url, attributesParam, optsParam) { | |
var attributes = attributesParam || {}; | |
// optional | |
var opts = optsParam || {}; | |
var script = document.createElement('script'); | |
// default value | |
if (attributes.defer === undefined) { | |
attributes.defer = true; | |
} |
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
function handleDuplicateLink(link) { | |
if (!link) { | |
console.warn('long link was empty'); | |
return link; | |
} | |
if (!link.includes('?')) { | |
console.warn(`link(${link}) no need handle`); | |
return link; | |
} | |
const links = link.split('?') |
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
function includeKey(objectA, objectB) { | |
if (!objectA || !objectB) { | |
return false; | |
} | |
const objectAKeys = Object.keys(objectA); | |
const objectBKeys = Object.keys(objectB); | |
if (!objectBKeys || !objectBKeys) { | |
return false; | |
} | |
const _include = objectBKeys.some(objectBKey => { |
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
function copyArray(value) { | |
return JSON.parse(JSON.stringify(value)) | |
} | |
/** | |
* @name isArrayEqual | |
* @param {Array} arrayA 数组A | |
* @param {Array} arrayB 数组B | |
* @description 比较两个数组,内容可以顺序不一致 | |
* @returns |
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
// http://js.jsrun.net/ScLKp/edit | |
class EventBus { | |
constructor() { | |
/** | |
* 构造函数需要存储的 event 事件 | |
*/ | |
this.events = this.events || new Object(); | |
} | |
} |
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
function isInChina(cb) { | |
return new Promise((resolve, reject) => { | |
try { | |
let url = "//graph.facebook.com/feed?callback=h" | |
let xhr = new XMLHttpRequest() | |
let called = false | |
xhr.open("GET", url) | |
xhr.onreadystatechange = function() { | |
if (xhr.readyState === 4 && xhr.status === 200) { | |
called = true |
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 setContextOption = (newCtx, { | |
smoothEnabled = true, | |
smoothQuality = 'high' | |
} = {}) => { | |
newCtx.imageSmoothingEnabled = smoothEnabled // 图片平滑, 默认为 true | |
newCtx.msImageSmoothingEnabled = smoothEnabled | |
newCtx.webkitImageSmoothingEnabled = smoothEnabled | |
newCtx.mozImageSmoothingEnabled = smoothEnabled | |
newCtx.imageSmoothingQuality = smoothQuality // 调整平滑质量 | |
newCtx.msImageSmoothingQuality = smoothQuality |
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
/*! | |
* gulp | |
* $ npm install gulp-ruby-sass gulp-autoprefixer gulp-cssnano gulp-jshint gulp-concat gulp-uglify gulp-imagemin gulp-notify gulp-rename gulp-livereload gulp-cache del --save-dev | |
*/ | |
// Load plugins | |
var gulp = require('gulp'), | |
sass = require('gulp-ruby-sass'), | |
autoprefixer = require('gulp-autoprefixer'), | |
cssnano = require('gulp-cssnano'), |
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 gulp = require('gulp'); | |
var uglify = require('gulp-uglify'); | |
var concat = require('gulp-concat'); | |
var bower = require('main-bower-files'); | |
gulp.task('bower', function () { | |
return gulp.src(bower()) | |
.pipe(concat('vendor.js')) | |
.pipe(uglify()) | |
.pipe(gulp.dest('/build/scripts')); |