1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- export function byteToString (arr) {
- if(typeof arr === 'string') {
- return arr;
- }
- var str = '',
- _arr = arr;
- for(var i = 0; i < _arr.length; i++) {
- var one = _arr[i].toString(2),
- v = one.match(/^1+?(?=0)/);
- if(v && one.length == 8) {
- var bytesLength = v[0].length;
- var store = _arr[i].toString(2).slice(7 - bytesLength);
- for(var st = 1; st < bytesLength; st++) {
- store += _arr[st + i].toString(2).slice(2);
- }
- str += String.fromCharCode(parseInt(store, 2));
- i += bytesLength - 1;
- } else {
- str += String.fromCharCode(_arr[i]);
- }
- }
- return str;
- }
- export const broadcastScan = {
- // init,
- };
- export const Format = (fmt, date) => {
- let o = {
- "M+": date.getMonth() + 1, // 月份
- "d+": date.getDate(), // 日
- "h+": date.getHours(), // 小时
- "m+": date.getMinutes(), // 分
- "s+": date.getSeconds(), // 秒
- "q+": Math.floor((date.getMonth() + 3) / 3), // 季度
- S: date.getMilliseconds(), // 毫秒
- };
- if (/(y+)/.test(fmt)) {
- fmt = fmt.replace(
- RegExp.$1,
- (date.getFullYear() + "").substr(4 - RegExp.$1.length)
- );
- }
- for (var k in o) {
- if (new RegExp("(" + k + ")").test(fmt)) {
- fmt = fmt.replace(
- RegExp.$1,
- RegExp.$1.length === 1 ? o[k] : ("00" + o[k]).substr(("" + o[k]).length)
- );
- }
- }
- return fmt;
- };
|