// GUID
Math.trueRandom = (function (){
if (crypto.getRandomValues) {
// if we have a crypto library, use it
return function (){
var array = new Uint32Array(1);
crypto.getRandomValues(array);
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
/*! | |
Math.uuid.js (v1.4) | |
http://www.broofa.com | |
mailto:[email protected] | |
Copyright (c) 2010 Robert Kieffer | |
Dual licensed under the MIT and GPL licenses. | |
*/ | |
/** |
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
/** | |
* Base64 | |
* http://blog.csdn.net/cuixiping/article/details/409468 | |
* ADODB.Stream 实例有 LoadFromFile 方法可以读取文件内容 | |
* ADODB.Stream 实例有 state 属性 0 和 1,分别对应 Open 状态: adStateClosed 和 adStateOpen | |
* ADODB.Stream 实例有 LineSeparator 属性 13、-1 和 10,分别对应换行符: adCR、adCRLF 和 adLF | |
* ADODB.Stream 实例的其他属性和方法可参考相应文档 | |
*/ | |
var Base64 = { | |
/** |
/**
* strip utf-8 BOM
*
* @param {any} buffer
* @returns {Buffer}
*/
function stripBOM(buffer) {
//EF BB BF 239 187 191
if (buffer[0] === 0xef && buffer[1] === 0xbb && buffer[2] === 0xbf) {
'use strict'
// 兼容模式,兼容老版本浏览器
function pad(value, length, placeholder) {
length = length || 15;
placeholder = placeholder || ' ';
var diff = Math.max(0, length - value.length) + 1;
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() { | |
// refactor process.argv to determine the app entry point and remove the interceptor parameter | |
var appFile; | |
var newArgs = []; | |
process.argv.forEach(function(item, index) { | |
if (index === 2) appFile = item; | |
if (index !== 1) newArgs.push(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
// https://jsperf.com/utf8-encoder-decoder | |
var encoder = new TextEncoder(); | |
var decoder = new TextDecoder(); | |
// https://developer.mozilla.org/zh-CN/docs/Web/API/TextEncoder | |
var native = { | |
encode: encoder.encode.bind(encoder), | |
decode: decoder.decode.bind(decoder) | |
}; |
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 LCGRandom | |
* @description 线性同余随机数 | |
* @param {number} seed | |
* @returns {number} | |
* @see https://gist.github.com/Protonk/5389384 | |
*/ | |
function LCGRandom1(seed = 0) { | |
return ((seed * 11 + 17) % 25) / 25; | |
} |
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 rgb2hex(red, green, blue) { | |
const rgb = (red << 16) | (green << 8) | blue; | |
return `#${rgb.toString(16).padStart(6, '0')}`; | |
} | |
function hex2rgb(hex) { | |
return [(hex >> 16) & 0xff, (hex >> 8) & 0xff, hex & 0xff]; | |
} |
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 hashCode | |
* @param {string} string | |
* @returns {number} | |
*/ | |
function hashCode(string: string): number { | |
let hash: number = 0; | |
const { length }: string = string; |