Socket
Socket
Sign inDemoInstall

@chainsafe/lodestar-utils

Package Overview
Dependencies
Maintainers
4
Versions
843
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.11.0 to 0.12.0

lib/errors.d.ts

1

lib/assert.d.ts

@@ -45,1 +45,2 @@ export declare const assert: {

}
//# sourceMappingURL=assert.d.ts.map

@@ -17,1 +17,2 @@ /// <reference types="node" />

export {};
//# sourceMappingURL=bytes.d.ts.map

13

lib/index.d.ts

@@ -0,8 +1,15 @@

export * from "./events";
export * from "./logger";
export * from "./yaml";
export * from "./assert";
export * from "./bytes";
export * from "./errors";
export * from "./math";
export * from "./bytes";
export * from "./yaml";
export * from "./misc";
export * from "./objects";
export * from "./sleep";
export * from "./sort";
export * from "./logger";
export * from "./verifyMerkleBranch";
export * from "./json";
export * from "./interop";
//# sourceMappingURL=index.d.ts.map

@@ -7,10 +7,11 @@ "use strict";

var _assert = require("./assert");
var _events = require("./events");
Object.keys(_assert).forEach(function (key) {
Object.keys(_events).forEach(function (key) {
if (key === "default" || key === "__esModule") return;
if (key in exports && exports[key] === _events[key]) return;
Object.defineProperty(exports, key, {
enumerable: true,
get: function get() {
return _assert[key];
get: function () {
return _events[key];
}

@@ -20,10 +21,11 @@ });

var _math = require("./math");
var _logger = require("./logger");
Object.keys(_math).forEach(function (key) {
Object.keys(_logger).forEach(function (key) {
if (key === "default" || key === "__esModule") return;
if (key in exports && exports[key] === _logger[key]) return;
Object.defineProperty(exports, key, {
enumerable: true,
get: function get() {
return _math[key];
get: function () {
return _logger[key];
}

@@ -33,2 +35,28 @@ });

var _yaml = require("./yaml");
Object.keys(_yaml).forEach(function (key) {
if (key === "default" || key === "__esModule") return;
if (key in exports && exports[key] === _yaml[key]) return;
Object.defineProperty(exports, key, {
enumerable: true,
get: function () {
return _yaml[key];
}
});
});
var _assert = require("./assert");
Object.keys(_assert).forEach(function (key) {
if (key === "default" || key === "__esModule") return;
if (key in exports && exports[key] === _assert[key]) return;
Object.defineProperty(exports, key, {
enumerable: true,
get: function () {
return _assert[key];
}
});
});
var _bytes = require("./bytes");

@@ -38,5 +66,6 @@

if (key === "default" || key === "__esModule") return;
if (key in exports && exports[key] === _bytes[key]) return;
Object.defineProperty(exports, key, {
enumerable: true,
get: function get() {
get: function () {
return _bytes[key];

@@ -47,10 +76,11 @@ }

var _yaml = require("./yaml");
var _errors = require("./errors");
Object.keys(_yaml).forEach(function (key) {
Object.keys(_errors).forEach(function (key) {
if (key === "default" || key === "__esModule") return;
if (key in exports && exports[key] === _errors[key]) return;
Object.defineProperty(exports, key, {
enumerable: true,
get: function get() {
return _yaml[key];
get: function () {
return _errors[key];
}

@@ -60,2 +90,28 @@ });

var _math = require("./math");
Object.keys(_math).forEach(function (key) {
if (key === "default" || key === "__esModule") return;
if (key in exports && exports[key] === _math[key]) return;
Object.defineProperty(exports, key, {
enumerable: true,
get: function () {
return _math[key];
}
});
});
var _misc = require("./misc");
Object.keys(_misc).forEach(function (key) {
if (key === "default" || key === "__esModule") return;
if (key in exports && exports[key] === _misc[key]) return;
Object.defineProperty(exports, key, {
enumerable: true,
get: function () {
return _misc[key];
}
});
});
var _objects = require("./objects");

@@ -65,5 +121,6 @@

if (key === "default" || key === "__esModule") return;
if (key in exports && exports[key] === _objects[key]) return;
Object.defineProperty(exports, key, {
enumerable: true,
get: function get() {
get: function () {
return _objects[key];

@@ -74,10 +131,11 @@ }

var _sort = require("./sort");
var _sleep = require("./sleep");
Object.keys(_sort).forEach(function (key) {
Object.keys(_sleep).forEach(function (key) {
if (key === "default" || key === "__esModule") return;
if (key in exports && exports[key] === _sleep[key]) return;
Object.defineProperty(exports, key, {
enumerable: true,
get: function get() {
return _sort[key];
get: function () {
return _sleep[key];
}

@@ -87,10 +145,11 @@ });

var _logger = require("./logger");
var _sort = require("./sort");
Object.keys(_logger).forEach(function (key) {
Object.keys(_sort).forEach(function (key) {
if (key === "default" || key === "__esModule") return;
if (key in exports && exports[key] === _sort[key]) return;
Object.defineProperty(exports, key, {
enumerable: true,
get: function get() {
return _logger[key];
get: function () {
return _sort[key];
}

@@ -104,5 +163,6 @@ });

if (key === "default" || key === "__esModule") return;
if (key in exports && exports[key] === _verifyMerkleBranch[key]) return;
Object.defineProperty(exports, key, {
enumerable: true,
get: function get() {
get: function () {
return _verifyMerkleBranch[key];

@@ -112,2 +172,28 @@ }

});
var _json = require("./json");
Object.keys(_json).forEach(function (key) {
if (key === "default" || key === "__esModule") return;
if (key in exports && exports[key] === _json[key]) return;
Object.defineProperty(exports, key, {
enumerable: true,
get: function () {
return _json[key];
}
});
});
var _interop = require("./interop");
Object.keys(_interop).forEach(function (key) {
if (key === "default" || key === "__esModule") return;
if (key in exports && exports[key] === _interop[key]) return;
Object.defineProperty(exports, key, {
enumerable: true,
get: function () {
return _interop[key];
}
});
});
//# sourceMappingURL=index.js.map

@@ -1,3 +0,6 @@

import { Context } from "./interface";
export declare const defaultLogFormat: import("logform").Format;
export declare function serializeContext(context?: Context | Error): string;
import { format } from "winston";
import { ILoggerOptions } from "./interface";
declare type Format = ReturnType<typeof format.combine>;
export declare function getFormat(opts: ILoggerOptions): Format;
export {};
//# sourceMappingURL=format.d.ts.map

@@ -6,32 +6,82 @@ "use strict";

});
exports.serializeContext = serializeContext;
exports.defaultLogFormat = void 0;
exports.getFormat = getFormat;
var _winston = require("winston");
const defaultLogFormat = _winston.format.combine(_winston.format.colorize(), _winston.format.timestamp({
format: "YYYY-MM-DD HH:mm:ss"
}), _winston.format.printf(info => {
var _json = require("../json");
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
function getFormat(opts) {
switch (opts.format) {
case "json":
return jsonLogFormat(opts);
case "human":
default:
return humanReadableLogFormat(opts);
}
}
function humanReadableLogFormat(opts) {
return _winston.format.combine(...(opts.hideTimestamp ? [] : [_winston.format.timestamp({
format: "YYYY-MM-DD HH:mm:ss"
})]), _winston.format.colorize(), _winston.format.printf(humanReadableTemplateFn));
}
function jsonLogFormat(opts) {
return _winston.format.combine(...(opts.hideTimestamp ? [] : [_winston.format.timestamp()]), (0, _winston.format)(_info => {
const info = _info;
info.context = (0, _json.toJson)(info.context);
return info;
})(), _winston.format.json());
}
/**
* Winston template function print a human readable string given a log object
*/
// eslint-disable-next-line @typescript-eslint/no-explicit-any
function humanReadableTemplateFn(_info) {
const info = _info;
const paddingBetweenInfo = 30;
const infoString = info.module || info.namespace || "";
const infoPad = paddingBetweenInfo - infoString.length;
return "".concat(info.timestamp, " [").concat(infoString.toUpperCase(), "] ").concat(info.level.padStart(infoPad), ":") + " ".concat(info.message, " ").concat(serializeContext(info.context)) + "".concat(info.durationMs ? "- duration=" + info.durationMs + "ms" : "");
}));
const {
context,
stack
} = splitContextAndStackTrace(info.context);
const logParts = [info.timestamp, "[".concat(infoString.toUpperCase(), "]"), "".concat(info.level.padStart(infoPad), ":"), info.message, context, info.durationMs && " - duration=".concat(info.durationMs, "ms"), stack && "\n".concat(stack)];
return logParts.filter(s => s).join(" ");
}
/**
* Extract stack property from context to allow appending at the end of the log
*/
exports.defaultLogFormat = defaultLogFormat;
function serializeContext(context) {
if (!context) return "";
function splitContextAndStackTrace(context) {
if (!context) {
return {};
}
if (context instanceof Error) {
return "Error: " + context.message + "\n" + context.stack;
const json = (0, _json.toJson)(context);
if (typeof json === "object" && json !== null && !Array.isArray(json) && json.stack) {
const {
stack
} = json,
errJsonData = _objectWithoutProperties(json, ["stack"]);
return {
context: (0, _json.toString)(errJsonData),
stack: (0, _json.toString)(stack)
};
} else {
return {
context: (0, _json.toString)(json)
};
}
if (typeof context === "string") return context;
if (typeof context === "number" || typeof context === "boolean" || Array.isArray(context)) return JSON.stringify(context);
return Object.keys(context).map(key => {
const value = typeof context[key] === "string" ? context[key] : JSON.stringify(context[key]);
return "".concat(key, "=").concat(value);
}).join(", ");
}
//# sourceMappingURL=format.js.map

@@ -7,1 +7,2 @@ /**

export * from "./format";
//# sourceMappingURL=index.d.ts.map

@@ -11,5 +11,6 @@ "use strict";

if (key === "default" || key === "__esModule") return;
if (key in exports && exports[key] === _winston[key]) return;
Object.defineProperty(exports, key, {
enumerable: true,
get: function get() {
get: function () {
return _winston[key];

@@ -24,5 +25,6 @@ }

if (key === "default" || key === "__esModule") return;
if (key in exports && exports[key] === _interface[key]) return;
Object.defineProperty(exports, key, {
enumerable: true,
get: function get() {
get: function () {
return _interface[key];

@@ -37,5 +39,6 @@ }

if (key === "default" || key === "__esModule") return;
if (key in exports && exports[key] === _format[key]) return;
Object.defineProperty(exports, key, {
enumerable: true,
get: function get() {
get: function () {
return _format[key];

@@ -42,0 +45,0 @@ }

@@ -5,3 +5,2 @@ /**

/// <reference types="node" />
import { Json } from "@chainsafe/ssz";
import { Writable } from "stream";

@@ -16,3 +15,3 @@ export declare enum LogLevel {

}
export declare const LogLevels: any[];
export declare const LogLevels: LogLevel[];
export declare const customColors: {

@@ -27,7 +26,13 @@ error: string;

export declare const defaultLogLevel = LogLevel.info;
export declare type LogFormat = "human" | "json";
export declare const logFormats: LogFormat[];
export interface ILoggerOptions {
level?: LogLevel;
module?: string;
format?: LogFormat;
hideTimestamp?: boolean;
}
export declare type Context = Json;
export declare type Context = string | number | boolean | bigint | null | {
[property: string]: Context;
} | Context[];
export interface ILogger {

@@ -50,1 +55,2 @@ level: LogLevel;

}
//# sourceMappingURL=interface.d.ts.map

@@ -6,3 +6,3 @@ "use strict";

});
exports.defaultLogLevel = exports.customColors = exports.LogLevels = exports.LogLevel = void 0;
exports.logFormats = exports.defaultLogLevel = exports.customColors = exports.LogLevels = exports.LogLevel = void 0;

@@ -12,4 +12,3 @@ /**

*/
let LogLevel; // @ts-ignore
let LogLevel;
exports.LogLevel = LogLevel;

@@ -26,3 +25,3 @@

const LogLevels = Object.keys(LogLevel).map(key => LogLevel[key]);
const LogLevels = Object.values(LogLevel);
exports.LogLevels = LogLevels;

@@ -40,2 +39,4 @@ const customColors = {

exports.defaultLogLevel = defaultLogLevel;
const logFormats = ["human", "json"];
exports.logFormats = logFormats;
//# sourceMappingURL=interface.js.map

@@ -34,1 +34,2 @@ /**

}
//# sourceMappingURL=winston.d.ts.map

@@ -59,3 +59,3 @@ "use strict";

},
format: _format.defaultLogFormat,
format: (0, _format.getFormat)(options),
transports: transports || [consoleTransport],

@@ -126,2 +126,4 @@ exitOnError: false

child(options) {
var _options$level;
const logger = Object.create(WinstonLogger.prototype);

@@ -131,7 +133,15 @@ const winston = this.winston.child({

level: options.level
});
winston.level = options.level || this._level;
}); //use more verbose log
if (this.winston.levels[this._level] > this.winston.levels[(_options$level = options.level) !== null && _options$level !== void 0 ? _options$level : _interface.LogLevel.error]) {
winston.level = this._level;
} else {
var _options$level2;
winston.level = (_options$level2 = options.level) !== null && _options$level2 !== void 0 ? _options$level2 : this._level;
}
return Object.assign(logger, {
winston,
_level: options.level || this._level,
_level: winston.level,
_silent: this._silent

@@ -142,2 +152,3 @@ });

createLogEntry(level, message, context) {
//don't propagate if silenced or message level is more detailed than logger level
if (this.silent || this.winston.levels[level] > this.winston.levels[this._level]) {

@@ -144,0 +155,0 @@ return;

@@ -27,1 +27,2 @@ /**

export declare function randBetweenBigInt(min: number, max: number): bigint;
//# sourceMappingURL=math.d.ts.map

@@ -55,7 +55,7 @@ "use strict";

let x = n;
let y = (x + 1n) / 2n;
let y = (x + BigInt(1)) / BigInt(2);
while (y < x) {
x = y;
y = (x + n / x) / 2n;
y = (x + n / x) / BigInt(2);
}

@@ -62,0 +62,0 @@

export declare function objectToExpectedCase(obj: Record<string, unknown>, expectedCase?: "snake" | "camel"): object;
//# sourceMappingURL=misc.d.ts.map

@@ -5,1 +5,7 @@ /**

export declare function isPlainObject(o: any): boolean;
export declare function mapValues<T, R>(obj: object | {
[key: string]: T;
}, iteratee: (value: T, key: string) => R): {
[key: string]: R;
};
//# sourceMappingURL=objects.d.ts.map

@@ -7,2 +7,3 @@ "use strict";

exports.isPlainObject = isPlainObject;
exports.mapValues = mapValues;

@@ -33,2 +34,12 @@ /**

}
function mapValues(obj, iteratee) {
const output = {};
for (const [key, value] of Object.entries(obj)) {
output[key] = iteratee(value, key);
}
return output;
}
//# sourceMappingURL=objects.js.map
export declare function isSorted(indices: number[]): boolean;
//# sourceMappingURL=sort.d.ts.map

@@ -6,1 +6,2 @@ /**

export declare function verifyMerkleBranch(leaf: Uint8Array, proof: Uint8Array[], depth: number, index: number, root: Uint8Array): boolean;
//# sourceMappingURL=verifyMerkleBranch.d.ts.map
export declare function loadYaml(yaml: string): object;
export declare function dumpYaml(yaml: any): string;
//# sourceMappingURL=index.d.ts.map
export declare const intType: any;
//# sourceMappingURL=int.d.ts.map

@@ -13,15 +13,7 @@ "use strict";

function isHexCode(c) {
return 0x30
/* 0 */
<= c && c <= 0x39
/* 9 */
|| 0x41
/* A */
<= c && c <= 0x46
/* F */
|| 0x61
/* a */
<= c && c <= 0x66
/* f */
;
return (// 0, 9
0x30 <= c && c <= 0x39 || // A, F
0x41 <= c && c <= 0x46 || // a, f
0x61 <= c && c <= 0x66
);
}

@@ -145,3 +137,3 @@

if (value === "0") return 0n;
if (value === "0") return BigInt(0);

@@ -157,7 +149,7 @@ if (ch === "0") {

});
value = 0n;
base = 1n;
value = BigInt(0);
base = BigInt(1);
digits.forEach(function (d) {
value = (BigInt(value) + BigInt(base)) * BigInt(d);
base = BigInt(base) * 60n;
base = BigInt(base) * BigInt(60);
});

@@ -183,15 +175,15 @@ return value * BigInt(sign);

// @ts-ignore
binary: function binary(obj) {
binary: function (obj) {
return obj >= 0 ? "0b" + obj.toString(2) : "-0b" + obj.toString(2).slice(1);
},
// @ts-ignore
octal: function octal(obj) {
octal: function (obj) {
return obj >= 0 ? "0" + obj.toString(8) : "-0" + obj.toString(8).slice(1);
},
// @ts-ignore
decimal: function decimal(obj) {
decimal: function (obj) {
return obj.toString(10);
},
// @ts-ignore
hexadecimal: function hexadecimal(obj) {
hexadecimal: function (obj) {
return obj >= 0 ? "0x" + obj.toString(16).toUpperCase() : "-0x" + obj.toString(16).toUpperCase().slice(1);

@@ -198,0 +190,0 @@ }

import { Schema } from "js-yaml";
export declare const schema: Schema;
//# sourceMappingURL=schema.d.ts.map

@@ -14,3 +14,3 @@ {

},
"version": "0.11.0",
"version": "0.12.0",
"main": "lib/index.js",

@@ -23,7 +23,7 @@ "files": [

"scripts": {
"build": "yarn build:lib && yarn build:types",
"build:docs": "typedoc --exclude src/index.ts --out docs src",
"build": "concurrently \"yarn build:lib\" \"yarn build:types\"",
"build:typedocs": "typedoc --exclude src/index.ts --out typedocs src",
"build:lib": "babel src -x .ts -d lib --source-maps",
"build:lib:watch": "yarn run build:lib --watch",
"build:release": "yarn clean && yarn build && yarn build:docs",
"build:release": "yarn clean && yarn build && yarn build:typedocs",
"build:types": "tsc --incremental --project tsconfig.build.json --declaration --outDir lib --emitDeclarationOnly",

@@ -33,26 +33,24 @@ "build:types:watch": "yarn run build:types --watch --preserveWatchOutput",

"clean": "rm -rf lib && rm -f tsconfig.tsbuildinfo",
"lint": "eslint --color --ext .ts src/",
"lint:fix": "eslint --color --ext .ts src/ --fix",
"lint": "eslint --color --ext .ts src/ test/",
"lint:fix": "yarn run lint --fix",
"prepublishOnly": "yarn build",
"pretest": "yarn run check-types",
"test:unit": "mocha --colors -r ./.babel-register 'test/**/*.test.ts'"
"test:unit": "TS_NODE_PROJECT=tsconfig.test.json mocha 'test/**/*.test.ts'"
},
"types": "lib/index.d.ts",
"dependencies": {
"@chainsafe/ssz": "^0.6.11",
"@chainsafe/bls": "5.0.1",
"@chainsafe/ssz": "^0.6.13",
"abort-controller": "^3.0.0",
"bigint-buffer": "^1.1.5",
"camelcase": "^5.3.1",
"chalk": "^2.4.2",
"event-iterator": "^2.0.0",
"js-yaml": "^3.13.1",
"winston": "^3.2.1",
"winston": "^3.3.3",
"winston-transport": "^4.3.0"
},
"devDependencies": {
"@types/camelcase": "^5.2.0",
"@types/chai": "4.2.0",
"@types/js-yaml": "^3.12.1",
"@types/mocha": "^5.2.7",
"@types/snake-case": "^1.1.2",
"chai": "^4.2.0",
"mocha": "^6.2.2"
"@types/triple-beam": "^1.3.2",
"triple-beam": "^1.3.0"
},

@@ -65,3 +63,3 @@ "keywords": [

],
"gitHead": "d84564bda2f3548a1d7e419c1c621f005a4f1dca"
"gitHead": "5162c9136854c8c0b3816bb7622468ee0f3cc61b"
}

@@ -0,2 +1,10 @@

# lodestar-utils
![ES Version](https://img.shields.io/badge/ES-2020-yellow)
![Node Version](https://img.shields.io/badge/node-12.x-green)
> This package is part of [ChainSafe's Lodestar](https://lodestar.chainsafe.io) project
## License
Apache-2.0 [ChainSafe Systems](https://chainsafe.io)

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

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

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

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

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc