Comparing version 0.0.38 to 0.0.39
@@ -5,2 +5,4 @@ /// <reference types="node" /> | ||
crc32(buf: Buffer, offset?: number, length?: number): number; | ||
crc16modbus(buf: Buffer, offset?: number, length?: number): number; | ||
crc16ccitt(buf: Buffer, offset?: number, length?: number): number; | ||
crc64(buf: Buffer, offset?: number, length?: number): number[]; | ||
@@ -648,4 +650,4 @@ adler32(buf: Buffer, offset?: number, length?: number): number; | ||
}; | ||
export * from './logger'; | ||
export { Formatters, Log as debug, Log, Logger as IDebugger, Logger, LoggerLevel, LoggerLevelType } from './logger'; | ||
export * from './process'; | ||
export * from './timer'; |
@@ -10,5 +10,8 @@ "use strict"; | ||
exports.Utils = Object.assign(Object.assign({}, lo), utils); | ||
__export(require("./logger")); | ||
var logger_1 = require("./logger"); | ||
exports.debug = logger_1.Log; | ||
exports.Log = logger_1.Log; | ||
exports.LoggerLevel = logger_1.LoggerLevel; | ||
__export(require("./process")); | ||
__export(require("./timer")); | ||
//# sourceMappingURL=index.js.map |
@@ -99,19 +99,77 @@ /// <reference types="node" /> | ||
var endIcon: string; | ||
var log: (...args: any[]) => void; | ||
var emerg: (...args: any[]) => void; | ||
var fatal: (...args: any[]) => void; | ||
var alert: (...args: any[]) => void; | ||
var critical: (...args: any[]) => void; | ||
var error: (...args: any[]) => void; | ||
var warn: (...args: any[]) => void; | ||
var notice: (...args: any[]) => void; | ||
var info: (...args: any[]) => void; | ||
var debug: (...args: any[]) => void; | ||
var trace: (...args: any[]) => void; | ||
var time: (...args: any[]) => [number, number]; | ||
var end: (...args: any[]) => [number, number]; | ||
var timeEnd: (...args: any[]) => [number, number]; | ||
var log: typeof import("./logger").log; | ||
var emerg: typeof import("./logger").emerg; | ||
var fatal: typeof import("./logger").fatal; | ||
var alert: typeof import("./logger").alert; | ||
var critical: typeof import("./logger").critical; | ||
var error: typeof import("./logger").error; | ||
var warn: typeof import("./logger").warn; | ||
var notice: typeof import("./logger").notice; | ||
var info: typeof import("./logger").info; | ||
var debug: typeof import("./logger").debug; | ||
var trace: typeof import("./logger").trace; | ||
var time: typeof import("./logger").time; | ||
var end: typeof import("./logger").end; | ||
var timeEnd: typeof import("./logger").timeEnd; | ||
var millis: (span: [number, number], offset?: number) => string; | ||
} | ||
export { Log as debug, Logger as IDebugger }; | ||
/** | ||
* Invokes `util.format()` with the specified arguments and writes to stderr. | ||
*/ | ||
export declare function log(...args: any[]): void; | ||
export declare namespace log { | ||
var level: string; | ||
} | ||
export declare function emerg(...args: any[]): void; | ||
export declare namespace emerg { | ||
var level: string; | ||
} | ||
export declare function fatal(...args: any[]): void; | ||
export declare namespace fatal { | ||
var level: string; | ||
} | ||
export declare function alert(...args: any[]): void; | ||
export declare namespace alert { | ||
var level: string; | ||
} | ||
export declare function critical(...args: any[]): void; | ||
export declare namespace critical { | ||
var level: string; | ||
} | ||
export declare function error(...args: any[]): void; | ||
export declare namespace error { | ||
var level: string; | ||
} | ||
export declare function warn(...args: any[]): void; | ||
export declare namespace warn { | ||
var level: string; | ||
} | ||
export declare function notice(...args: any[]): void; | ||
export declare namespace notice { | ||
var level: string; | ||
} | ||
export declare function info(...args: any[]): void; | ||
export declare namespace info { | ||
var level: string; | ||
} | ||
export declare function debug(...args: any[]): void; | ||
export declare namespace debug { | ||
var level: string; | ||
} | ||
export declare function trace(...args: any[]): void; | ||
export declare namespace trace { | ||
var level: string; | ||
} | ||
export declare function time(...args: any[]): any; | ||
export declare namespace time { | ||
var level: string; | ||
} | ||
export declare function end(...args: any[]): any; | ||
export declare namespace end { | ||
var level: string; | ||
} | ||
export declare function timeEnd(...args: any[]): any; | ||
export declare namespace timeEnd { | ||
var level: string; | ||
} | ||
export default Log; |
@@ -158,3 +158,2 @@ "use strict"; | ||
exports.Log = Log; | ||
exports.debug = Log; | ||
Log.get = function get(namespace, enable) { | ||
@@ -475,2 +474,3 @@ return Log(namespace, enable === undefined ? true : enable); | ||
} | ||
exports.log = log; | ||
log.level = 'INFO'; | ||
@@ -483,2 +483,3 @@ Log.log = log; | ||
} | ||
exports.emerg = emerg; | ||
emerg.level = 'EMERG'; | ||
@@ -491,2 +492,3 @@ Log.emerg = emerg; | ||
} | ||
exports.fatal = fatal; | ||
fatal.level = 'ALERT'; | ||
@@ -499,2 +501,3 @@ Log.fatal = fatal; | ||
} | ||
exports.alert = alert; | ||
alert.level = 'ALERT'; | ||
@@ -507,2 +510,3 @@ Log.alert = alert; | ||
} | ||
exports.critical = critical; | ||
critical.level = 'CRITICAL'; | ||
@@ -515,2 +519,3 @@ Log.critical = critical; | ||
} | ||
exports.error = error; | ||
error.level = 'ERROR'; | ||
@@ -523,2 +528,3 @@ Log.error = error; | ||
} | ||
exports.warn = warn; | ||
warn.level = 'WARN'; | ||
@@ -531,2 +537,3 @@ Log.warn = warn; | ||
} | ||
exports.notice = notice; | ||
notice.level = 'NOTICE'; | ||
@@ -539,2 +546,3 @@ Log.notice = notice; | ||
} | ||
exports.info = info; | ||
info.level = 'INFO'; | ||
@@ -547,2 +555,3 @@ Log.info = info; | ||
} | ||
exports.debug = debug; | ||
debug.level = 'DEBUG'; | ||
@@ -555,2 +564,3 @@ Log.debug = debug; | ||
} | ||
exports.trace = trace; | ||
trace.level = 'TRACE'; | ||
@@ -563,2 +573,3 @@ Log.trace = trace; | ||
} | ||
exports.time = time; | ||
time.level = 'TIME'; | ||
@@ -571,2 +582,3 @@ Log.time = time; | ||
} | ||
exports.end = end; | ||
end.level = 'END'; | ||
@@ -579,2 +591,3 @@ Log.end = end; | ||
} | ||
exports.timeEnd = timeEnd; | ||
timeEnd.level = 'END'; | ||
@@ -581,0 +594,0 @@ Log.timeEnd = timeEnd; |
/// <reference types="node" /> | ||
export declare function crc32(buf: Buffer, offset?: number, length?: number): number; | ||
export declare function crc16modbus(buf: Buffer, offset?: number, length?: number): number; | ||
export declare function crc16ccitt(buf: Buffer, offset?: number, length?: number): number; | ||
export declare function crc64(buf: Buffer, offset?: number, length?: number): number[]; | ||
export declare function adler32(buf: Buffer, offset?: number, length?: number): number; |
"use strict"; | ||
// http://www.sunshine2k.de/coding/javascript/crc/crc_js.html | ||
// https://crccalc.com | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const CRC16_MODBUS_TABLE = [ | ||
0x0000, 0xC0C1, 0xC181, 0x0140, 0xC301, 0x03C0, 0x0280, 0xC241, 0xC601, 0x06C0, 0x0780, 0xC741, 0x0500, 0xC5C1, 0xC481, 0x0440, | ||
0xCC01, 0x0CC0, 0x0D80, 0xCD41, 0x0F00, 0xCFC1, 0xCE81, 0x0E40, 0x0A00, 0xCAC1, 0xCB81, 0x0B40, 0xC901, 0x09C0, 0x0880, 0xC841, | ||
0xD801, 0x18C0, 0x1980, 0xD941, 0x1B00, 0xDBC1, 0xDA81, 0x1A40, 0x1E00, 0xDEC1, 0xDF81, 0x1F40, 0xDD01, 0x1DC0, 0x1C80, 0xDC41, | ||
0x1400, 0xD4C1, 0xD581, 0x1540, 0xD701, 0x17C0, 0x1680, 0xD641, 0xD201, 0x12C0, 0x1380, 0xD341, 0x1100, 0xD1C1, 0xD081, 0x1040, | ||
0xF001, 0x30C0, 0x3180, 0xF141, 0x3300, 0xF3C1, 0xF281, 0x3240, 0x3600, 0xF6C1, 0xF781, 0x3740, 0xF501, 0x35C0, 0x3480, 0xF441, | ||
0x3C00, 0xFCC1, 0xFD81, 0x3D40, 0xFF01, 0x3FC0, 0x3E80, 0xFE41, 0xFA01, 0x3AC0, 0x3B80, 0xFB41, 0x3900, 0xF9C1, 0xF881, 0x3840, | ||
0x2800, 0xE8C1, 0xE981, 0x2940, 0xEB01, 0x2BC0, 0x2A80, 0xEA41, 0xEE01, 0x2EC0, 0x2F80, 0xEF41, 0x2D00, 0xEDC1, 0xEC81, 0x2C40, | ||
0xE401, 0x24C0, 0x2580, 0xE541, 0x2700, 0xE7C1, 0xE681, 0x2640, 0x2200, 0xE2C1, 0xE381, 0x2340, 0xE101, 0x21C0, 0x2080, 0xE041, | ||
0xA001, 0x60C0, 0x6180, 0xA141, 0x6300, 0xA3C1, 0xA281, 0x6240, 0x6600, 0xA6C1, 0xA781, 0x6740, 0xA501, 0x65C0, 0x6480, 0xA441, | ||
0x6C00, 0xACC1, 0xAD81, 0x6D40, 0xAF01, 0x6FC0, 0x6E80, 0xAE41, 0xAA01, 0x6AC0, 0x6B80, 0xAB41, 0x6900, 0xA9C1, 0xA881, 0x6840, | ||
0x7800, 0xB8C1, 0xB981, 0x7940, 0xBB01, 0x7BC0, 0x7A80, 0xBA41, 0xBE01, 0x7EC0, 0x7F80, 0xBF41, 0x7D00, 0xBDC1, 0xBC81, 0x7C40, | ||
0xB401, 0x74C0, 0x7580, 0xB541, 0x7700, 0xB7C1, 0xB681, 0x7640, 0x7200, 0xB2C1, 0xB381, 0x7340, 0xB101, 0x71C0, 0x7080, 0xB041, | ||
0x5000, 0x90C1, 0x9181, 0x5140, 0x9301, 0x53C0, 0x5280, 0x9241, 0x9601, 0x56C0, 0x5780, 0x9741, 0x5500, 0x95C1, 0x9481, 0x5440, | ||
0x9C01, 0x5CC0, 0x5D80, 0x9D41, 0x5F00, 0x9FC1, 0x9E81, 0x5E40, 0x5A00, 0x9AC1, 0x9B81, 0x5B40, 0x9901, 0x59C0, 0x5880, 0x9841, | ||
0x8801, 0x48C0, 0x4980, 0x8941, 0x4B00, 0x8BC1, 0x8A81, 0x4A40, 0x4E00, 0x8EC1, 0x8F81, 0x4F40, 0x8D01, 0x4DC0, 0x4C80, 0x8C41, | ||
0x4400, 0x84C1, 0x8581, 0x4540, 0x8701, 0x47C0, 0x4680, 0x8641, 0x8201, 0x42C0, 0x4380, 0x8341, 0x4100, 0x81C1, 0x8081, 0x4040 | ||
]; | ||
const CRC16_CCITT_TABLE = [ | ||
0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50A5, 0x60C6, 0x70E7, 0x8108, 0x9129, 0xA14A, 0xB16B, 0xC18C, 0xD1AD, 0xE1CE, 0xF1EF, | ||
0x1231, 0x0210, 0x3273, 0x2252, 0x52B5, 0x4294, 0x72F7, 0x62D6, 0x9339, 0x8318, 0xB37B, 0xA35A, 0xD3BD, 0xC39C, 0xF3FF, 0xE3DE, | ||
0x2462, 0x3443, 0x0420, 0x1401, 0x64E6, 0x74C7, 0x44A4, 0x5485, 0xA56A, 0xB54B, 0x8528, 0x9509, 0xE5EE, 0xF5CF, 0xC5AC, 0xD58D, | ||
0x3653, 0x2672, 0x1611, 0x0630, 0x76D7, 0x66F6, 0x5695, 0x46B4, 0xB75B, 0xA77A, 0x9719, 0x8738, 0xF7DF, 0xE7FE, 0xD79D, 0xC7BC, | ||
0x48C4, 0x58E5, 0x6886, 0x78A7, 0x0840, 0x1861, 0x2802, 0x3823, 0xC9CC, 0xD9ED, 0xE98E, 0xF9AF, 0x8948, 0x9969, 0xA90A, 0xB92B, | ||
0x5AF5, 0x4AD4, 0x7AB7, 0x6A96, 0x1A71, 0x0A50, 0x3A33, 0x2A12, 0xDBFD, 0xCBDC, 0xFBBF, 0xEB9E, 0x9B79, 0x8B58, 0xBB3B, 0xAB1A, | ||
0x6CA6, 0x7C87, 0x4CE4, 0x5CC5, 0x2C22, 0x3C03, 0x0C60, 0x1C41, 0xEDAE, 0xFD8F, 0xCDEC, 0xDDCD, 0xAD2A, 0xBD0B, 0x8D68, 0x9D49, | ||
0x7E97, 0x6EB6, 0x5ED5, 0x4EF4, 0x3E13, 0x2E32, 0x1E51, 0x0E70, 0xFF9F, 0xEFBE, 0xDFDD, 0xCFFC, 0xBF1B, 0xAF3A, 0x9F59, 0x8F78, | ||
0x9188, 0x81A9, 0xB1CA, 0xA1EB, 0xD10C, 0xC12D, 0xF14E, 0xE16F, 0x1080, 0x00A1, 0x30C2, 0x20E3, 0x5004, 0x4025, 0x7046, 0x6067, | ||
0x83B9, 0x9398, 0xA3FB, 0xB3DA, 0xC33D, 0xD31C, 0xE37F, 0xF35E, 0x02B1, 0x1290, 0x22F3, 0x32D2, 0x4235, 0x5214, 0x6277, 0x7256, | ||
0xB5EA, 0xA5CB, 0x95A8, 0x8589, 0xF56E, 0xE54F, 0xD52C, 0xC50D, 0x34E2, 0x24C3, 0x14A0, 0x0481, 0x7466, 0x6447, 0x5424, 0x4405, | ||
0xA7DB, 0xB7FA, 0x8799, 0x97B8, 0xE75F, 0xF77E, 0xC71D, 0xD73C, 0x26D3, 0x36F2, 0x0691, 0x16B0, 0x6657, 0x7676, 0x4615, 0x5634, | ||
0xD94C, 0xC96D, 0xF90E, 0xE92F, 0x99C8, 0x89E9, 0xB98A, 0xA9AB, 0x5844, 0x4865, 0x7806, 0x6827, 0x18C0, 0x08E1, 0x3882, 0x28A3, | ||
0xCB7D, 0xDB5C, 0xEB3F, 0xFB1E, 0x8BF9, 0x9BD8, 0xABBB, 0xBB9A, 0x4A75, 0x5A54, 0x6A37, 0x7A16, 0x0AF1, 0x1AD0, 0x2AB3, 0x3A92, | ||
0xFD2E, 0xED0F, 0xDD6C, 0xCD4D, 0xBDAA, 0xAD8B, 0x9DE8, 0x8DC9, 0x7C26, 0x6C07, 0x5C64, 0x4C45, 0x3CA2, 0x2C83, 0x1CE0, 0x0CC1, | ||
0xEF1F, 0xFF3E, 0xCF5D, 0xDF7C, 0xAF9B, 0xBFBA, 0x8FD9, 0x9FF8, 0x6E17, 0x7E36, 0x4E55, 0x5E74, 0x2E93, 0x3EB2, 0x0ED1, 0x1EF0 | ||
]; | ||
const CRC64_TABLE = [ | ||
@@ -86,2 +123,18 @@ 0x00000000, 0x00000000, 0xB32E4CBE, 0x03A75F6F, 0xF4843657, 0xA840A05B, 0x47AA7AE9, 0xABE7FF34, | ||
exports.crc32 = crc32; | ||
function crc16modbus(buf, offset, length) { | ||
let crc = 0xFFFF; | ||
for (let i = (offset || 0); i < (length || buf.length); i++) { | ||
crc = (crc >>> 8) ^ CRC16_MODBUS_TABLE[(crc ^ buf[i]) & 0xFF]; | ||
} | ||
return (crc & 0xFFFF) >>> 0; | ||
} | ||
exports.crc16modbus = crc16modbus; | ||
function crc16ccitt(buf, offset, length) { | ||
let crc = 0xFFFF; | ||
for (let i = (offset || 0); i < (length || buf.length); i++) { | ||
crc = (crc << 8) ^ CRC16_CCITT_TABLE[((crc >>> 8) ^ buf[i]) & 0xFF]; | ||
} | ||
return (crc & 0xFFFF) >>> 0; | ||
} | ||
exports.crc16ccitt = crc16ccitt; | ||
function crc64(buf, offset, length) { | ||
@@ -120,2 +173,5 @@ let crc1 = 0 ^ (-1); | ||
// } | ||
console.log(crc32(Buffer.from('test')).toString(16)); | ||
console.log(crc16ccitt(Buffer.from('test')).toString(16)); | ||
console.log(crc16modbus(Buffer.from('test')).toString(16)); | ||
//# sourceMappingURL=crc.js.map |
{ | ||
"name": "exer", | ||
"version": "0.0.38", | ||
"version": "0.0.39", | ||
"description": "Utils in TypeScript, Debug, NanoTimer ...", | ||
@@ -41,16 +41,16 @@ "author": "kbajalc@gmail.com", | ||
"reflect-metadata": "^0.1.13", | ||
"uuid": "^3.3.3" | ||
"uuid": "^3.4.0" | ||
}, | ||
"devDependencies": { | ||
"@types/chance": "^1.0.7", | ||
"@types/lodash": "^4.14.149", | ||
"@types/node": "^10.17.6", | ||
"@types/uuid": "^3.4.6", | ||
"chance": "^1.1.3", | ||
"ts-node": "^8.5.4", | ||
"@types/chance": "^1.0.10", | ||
"@types/lodash": "^4.14.150", | ||
"@types/node": "^10.17.21", | ||
"@types/uuid": "^3.4.9", | ||
"chance": "^1.1.5", | ||
"ts-node": "^8.10.1", | ||
"tslint": "^5.20.1", | ||
"tslint-config-airbnb": "^5.11.2", | ||
"tty": "^1.0.1", | ||
"typescript": "^3.7.3" | ||
"typescript": "^3.8.3" | ||
} | ||
} |
@@ -6,4 +6,4 @@ import * as lo from 'lodash'; | ||
export * from './logger'; | ||
export { Formatters, Log as debug, Log, Logger as IDebugger, Logger, LoggerLevel, LoggerLevelType } from './logger'; | ||
export * from './process'; | ||
export * from './timer'; |
@@ -543,3 +543,3 @@ import tty = require('tty'); | ||
*/ | ||
function log(...args: any[]) { | ||
export function log(...args: any[]) { | ||
if (Log.isBellow(LoggerLevel.INFO)) return; | ||
@@ -551,3 +551,3 @@ Log.useConsole() ? console.log(...args) : process.stdout.write(util.format.call(util, ...args) + '\n'); | ||
function emerg(...args: any[]) { | ||
export function emerg(...args: any[]) { | ||
if (Log.isBellow(LoggerLevel.EMERG)) return; | ||
@@ -559,3 +559,3 @@ Log.useConsole() ? console.error(...args) : process.stderr.write(util.format.call(util, ...args) + '\n'); | ||
function fatal(...args: any[]) { | ||
export function fatal(...args: any[]) { | ||
if (Log.isBellow(LoggerLevel.ALERT)) return; | ||
@@ -567,3 +567,3 @@ Log.useConsole() ? console.error(...args) : process.stderr.write(util.format.call(util, ...args) + '\n'); | ||
function alert(...args: any[]) { | ||
export function alert(...args: any[]) { | ||
if (Log.isBellow(LoggerLevel.ALERT)) return; | ||
@@ -575,3 +575,3 @@ Log.useConsole() ? console.error(...args) : process.stderr.write(util.format.call(util, ...args) + '\n'); | ||
function critical(...args: any[]) { | ||
export function critical(...args: any[]) { | ||
if (Log.isBellow(LoggerLevel.CRITICAL)) return; | ||
@@ -583,3 +583,3 @@ Log.useConsole() ? console.error(...args) : process.stderr.write(util.format.call(util, ...args) + '\n'); | ||
function error(...args: any[]) { | ||
export function error(...args: any[]) { | ||
if (Log.isBellow(LoggerLevel.ERROR)) return; | ||
@@ -591,3 +591,3 @@ Log.useConsole() ? console.error(...args) : process.stderr.write(util.format.call(util, ...args) + '\n'); | ||
function warn(...args: any[]) { | ||
export function warn(...args: any[]) { | ||
if (Log.isBellow(LoggerLevel.WARNING)) return; | ||
@@ -599,3 +599,3 @@ Log.useConsole() ? console.warn(...args) : process.stdout.write(util.format.call(util, ...args) + '\n'); | ||
function notice(...args: any[]) { | ||
export function notice(...args: any[]) { | ||
if (Log.isBellow(LoggerLevel.NOTICE)) return; | ||
@@ -607,3 +607,3 @@ Log.useConsole() ? console.warn(...args) : process.stdout.write(util.format.call(util, ...args) + '\n'); | ||
function info(...args: any[]) { | ||
export function info(...args: any[]) { | ||
if (Log.isBellow(LoggerLevel.INFO)) return; | ||
@@ -615,3 +615,3 @@ Log.useConsole() ? console.info(...args) : process.stdout.write(util.format.call(util, ...args) + '\n'); | ||
function debug(...args: any[]) { | ||
export function debug(...args: any[]) { | ||
if (Log.isBellow(LoggerLevel.DEBUG)) return; | ||
@@ -623,3 +623,3 @@ Log.useConsole() ? console.debug(...args) : process.stdout.write(util.format.call(util, ...args) + '\n'); | ||
function trace(...args: any[]) { | ||
export function trace(...args: any[]) { | ||
if (Log.isBellow(LoggerLevel.TRACE)) return; | ||
@@ -631,3 +631,3 @@ Log.useConsole() ? console.debug(...args) : process.stdout.write(util.format.call(util, ...args) + '\n'); | ||
function time(...args: any[]): any { | ||
export function time(...args: any[]): any { | ||
if (Log.isBellow(LoggerLevel.TIME)) return; | ||
@@ -639,3 +639,3 @@ Log.useConsole() ? console.info(...args) : process.stdout.write(util.format.call(util, ...args) + '\n'); | ||
function end(...args: any[]): any { | ||
export function end(...args: any[]): any { | ||
if (Log.isBellow(LoggerLevel.TIME)) return; | ||
@@ -647,3 +647,3 @@ Log.useConsole() ? console.info(...args) : process.stdout.write(util.format.call(util, ...args) + '\n'); | ||
function timeEnd(...args: any[]): any { | ||
export function timeEnd(...args: any[]): any { | ||
if (Log.isBellow(LoggerLevel.TIME)) return; | ||
@@ -699,3 +699,2 @@ Log.useConsole() ? console.info(...args) : process.stdout.write(util.format.call(util, ...args) + '\n'); | ||
export { Log as debug, Logger as IDebugger }; | ||
export default Log; |
// http://www.sunshine2k.de/coding/javascript/crc/crc_js.html | ||
// https://crccalc.com | ||
const CRC16_MODBUS_TABLE = [ | ||
0x0000, 0xC0C1, 0xC181, 0x0140, 0xC301, 0x03C0, 0x0280, 0xC241, 0xC601, 0x06C0, 0x0780, 0xC741, 0x0500, 0xC5C1, 0xC481, 0x0440, | ||
0xCC01, 0x0CC0, 0x0D80, 0xCD41, 0x0F00, 0xCFC1, 0xCE81, 0x0E40, 0x0A00, 0xCAC1, 0xCB81, 0x0B40, 0xC901, 0x09C0, 0x0880, 0xC841, | ||
0xD801, 0x18C0, 0x1980, 0xD941, 0x1B00, 0xDBC1, 0xDA81, 0x1A40, 0x1E00, 0xDEC1, 0xDF81, 0x1F40, 0xDD01, 0x1DC0, 0x1C80, 0xDC41, | ||
0x1400, 0xD4C1, 0xD581, 0x1540, 0xD701, 0x17C0, 0x1680, 0xD641, 0xD201, 0x12C0, 0x1380, 0xD341, 0x1100, 0xD1C1, 0xD081, 0x1040, | ||
0xF001, 0x30C0, 0x3180, 0xF141, 0x3300, 0xF3C1, 0xF281, 0x3240, 0x3600, 0xF6C1, 0xF781, 0x3740, 0xF501, 0x35C0, 0x3480, 0xF441, | ||
0x3C00, 0xFCC1, 0xFD81, 0x3D40, 0xFF01, 0x3FC0, 0x3E80, 0xFE41, 0xFA01, 0x3AC0, 0x3B80, 0xFB41, 0x3900, 0xF9C1, 0xF881, 0x3840, | ||
0x2800, 0xE8C1, 0xE981, 0x2940, 0xEB01, 0x2BC0, 0x2A80, 0xEA41, 0xEE01, 0x2EC0, 0x2F80, 0xEF41, 0x2D00, 0xEDC1, 0xEC81, 0x2C40, | ||
0xE401, 0x24C0, 0x2580, 0xE541, 0x2700, 0xE7C1, 0xE681, 0x2640, 0x2200, 0xE2C1, 0xE381, 0x2340, 0xE101, 0x21C0, 0x2080, 0xE041, | ||
0xA001, 0x60C0, 0x6180, 0xA141, 0x6300, 0xA3C1, 0xA281, 0x6240, 0x6600, 0xA6C1, 0xA781, 0x6740, 0xA501, 0x65C0, 0x6480, 0xA441, | ||
0x6C00, 0xACC1, 0xAD81, 0x6D40, 0xAF01, 0x6FC0, 0x6E80, 0xAE41, 0xAA01, 0x6AC0, 0x6B80, 0xAB41, 0x6900, 0xA9C1, 0xA881, 0x6840, | ||
0x7800, 0xB8C1, 0xB981, 0x7940, 0xBB01, 0x7BC0, 0x7A80, 0xBA41, 0xBE01, 0x7EC0, 0x7F80, 0xBF41, 0x7D00, 0xBDC1, 0xBC81, 0x7C40, | ||
0xB401, 0x74C0, 0x7580, 0xB541, 0x7700, 0xB7C1, 0xB681, 0x7640, 0x7200, 0xB2C1, 0xB381, 0x7340, 0xB101, 0x71C0, 0x7080, 0xB041, | ||
0x5000, 0x90C1, 0x9181, 0x5140, 0x9301, 0x53C0, 0x5280, 0x9241, 0x9601, 0x56C0, 0x5780, 0x9741, 0x5500, 0x95C1, 0x9481, 0x5440, | ||
0x9C01, 0x5CC0, 0x5D80, 0x9D41, 0x5F00, 0x9FC1, 0x9E81, 0x5E40, 0x5A00, 0x9AC1, 0x9B81, 0x5B40, 0x9901, 0x59C0, 0x5880, 0x9841, | ||
0x8801, 0x48C0, 0x4980, 0x8941, 0x4B00, 0x8BC1, 0x8A81, 0x4A40, 0x4E00, 0x8EC1, 0x8F81, 0x4F40, 0x8D01, 0x4DC0, 0x4C80, 0x8C41, | ||
0x4400, 0x84C1, 0x8581, 0x4540, 0x8701, 0x47C0, 0x4680, 0x8641, 0x8201, 0x42C0, 0x4380, 0x8341, 0x4100, 0x81C1, 0x8081, 0x4040 | ||
]; | ||
const CRC16_CCITT_TABLE = [ | ||
0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50A5, 0x60C6, 0x70E7, 0x8108, 0x9129, 0xA14A, 0xB16B, 0xC18C, 0xD1AD, 0xE1CE, 0xF1EF, | ||
0x1231, 0x0210, 0x3273, 0x2252, 0x52B5, 0x4294, 0x72F7, 0x62D6, 0x9339, 0x8318, 0xB37B, 0xA35A, 0xD3BD, 0xC39C, 0xF3FF, 0xE3DE, | ||
0x2462, 0x3443, 0x0420, 0x1401, 0x64E6, 0x74C7, 0x44A4, 0x5485, 0xA56A, 0xB54B, 0x8528, 0x9509, 0xE5EE, 0xF5CF, 0xC5AC, 0xD58D, | ||
0x3653, 0x2672, 0x1611, 0x0630, 0x76D7, 0x66F6, 0x5695, 0x46B4, 0xB75B, 0xA77A, 0x9719, 0x8738, 0xF7DF, 0xE7FE, 0xD79D, 0xC7BC, | ||
0x48C4, 0x58E5, 0x6886, 0x78A7, 0x0840, 0x1861, 0x2802, 0x3823, 0xC9CC, 0xD9ED, 0xE98E, 0xF9AF, 0x8948, 0x9969, 0xA90A, 0xB92B, | ||
0x5AF5, 0x4AD4, 0x7AB7, 0x6A96, 0x1A71, 0x0A50, 0x3A33, 0x2A12, 0xDBFD, 0xCBDC, 0xFBBF, 0xEB9E, 0x9B79, 0x8B58, 0xBB3B, 0xAB1A, | ||
0x6CA6, 0x7C87, 0x4CE4, 0x5CC5, 0x2C22, 0x3C03, 0x0C60, 0x1C41, 0xEDAE, 0xFD8F, 0xCDEC, 0xDDCD, 0xAD2A, 0xBD0B, 0x8D68, 0x9D49, | ||
0x7E97, 0x6EB6, 0x5ED5, 0x4EF4, 0x3E13, 0x2E32, 0x1E51, 0x0E70, 0xFF9F, 0xEFBE, 0xDFDD, 0xCFFC, 0xBF1B, 0xAF3A, 0x9F59, 0x8F78, | ||
0x9188, 0x81A9, 0xB1CA, 0xA1EB, 0xD10C, 0xC12D, 0xF14E, 0xE16F, 0x1080, 0x00A1, 0x30C2, 0x20E3, 0x5004, 0x4025, 0x7046, 0x6067, | ||
0x83B9, 0x9398, 0xA3FB, 0xB3DA, 0xC33D, 0xD31C, 0xE37F, 0xF35E, 0x02B1, 0x1290, 0x22F3, 0x32D2, 0x4235, 0x5214, 0x6277, 0x7256, | ||
0xB5EA, 0xA5CB, 0x95A8, 0x8589, 0xF56E, 0xE54F, 0xD52C, 0xC50D, 0x34E2, 0x24C3, 0x14A0, 0x0481, 0x7466, 0x6447, 0x5424, 0x4405, | ||
0xA7DB, 0xB7FA, 0x8799, 0x97B8, 0xE75F, 0xF77E, 0xC71D, 0xD73C, 0x26D3, 0x36F2, 0x0691, 0x16B0, 0x6657, 0x7676, 0x4615, 0x5634, | ||
0xD94C, 0xC96D, 0xF90E, 0xE92F, 0x99C8, 0x89E9, 0xB98A, 0xA9AB, 0x5844, 0x4865, 0x7806, 0x6827, 0x18C0, 0x08E1, 0x3882, 0x28A3, | ||
0xCB7D, 0xDB5C, 0xEB3F, 0xFB1E, 0x8BF9, 0x9BD8, 0xABBB, 0xBB9A, 0x4A75, 0x5A54, 0x6A37, 0x7A16, 0x0AF1, 0x1AD0, 0x2AB3, 0x3A92, | ||
0xFD2E, 0xED0F, 0xDD6C, 0xCD4D, 0xBDAA, 0xAD8B, 0x9DE8, 0x8DC9, 0x7C26, 0x6C07, 0x5C64, 0x4C45, 0x3CA2, 0x2C83, 0x1CE0, 0x0CC1, | ||
0xEF1F, 0xFF3E, 0xCF5D, 0xDF7C, 0xAF9B, 0xBFBA, 0x8FD9, 0x9FF8, 0x6E17, 0x7E36, 0x4E55, 0x5E74, 0x2E93, 0x3EB2, 0x0ED1, 0x1EF0 | ||
]; | ||
const CRC64_TABLE = [ | ||
@@ -78,3 +117,2 @@ 0x00000000, 0x00000000, 0xB32E4CBE, 0x03A75F6F, 0xF4843657, 0xA840A05B, 0x47AA7AE9, 0xABE7FF34, | ||
} | ||
export function crc32(buf: Buffer, offset?: number, length?: number) { | ||
@@ -88,2 +126,18 @@ let crc = 0 ^ (-1); | ||
export function crc16modbus(buf: Buffer, offset?: number, length?: number) { | ||
let crc = 0xFFFF; | ||
for (let i = (offset || 0); i < (length || buf.length); i++) { | ||
crc = (crc >>> 8) ^ CRC16_MODBUS_TABLE[(crc ^ buf[i]) & 0xFF]; | ||
} | ||
return (crc & 0xFFFF) >>> 0; | ||
} | ||
export function crc16ccitt(buf: Buffer, offset?: number, length?: number) { | ||
let crc = 0xFFFF; | ||
for (let i = (offset || 0); i < (length || buf.length); i++) { | ||
crc = (crc << 8) ^ CRC16_CCITT_TABLE[((crc >>> 8) ^ buf[i]) & 0xFF]; | ||
} | ||
return (crc & 0xFFFF) >>> 0; | ||
} | ||
export function crc64(buf: Buffer, offset?: number, length?: number) { | ||
@@ -122,1 +176,5 @@ let crc1 = 0 ^ (-1); | ||
// } | ||
console.log(crc32(Buffer.from('test')).toString(16)); | ||
console.log(crc16ccitt(Buffer.from('test')).toString(16)); | ||
console.log(crc16modbus(Buffer.from('test')).toString(16)); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
280663
4476
Updateduuid@^3.4.0