Socket
Socket
Sign inDemoInstall

node-object-hash

Package Overview
Dependencies
Maintainers
1
Versions
37
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

node-object-hash - npm Package Compare versions

Comparing version 2.0.0 to 2.1.0

71

CHANGELOG.md

@@ -5,2 +5,24 @@ # Changelog

## 2.1.0 (2021-01-27)
### Features
- added warnings to eslint errors ([422c893](https://github.com/SkeLLLa/node-object-hash/commit/422c8932e8ad140553259e9e49555f7ddfef4db1))
- fixed eslint errors ([e9245f7](https://github.com/SkeLLLa/node-object-hash/commit/e9245f7aa3aa14238fbb62d97dacdcc414ec0f40))
- fixed npm script issue ([0bf8c17](https://github.com/SkeLLLa/node-object-hash/commit/0bf8c175ae058bbc442628e953ff577be500d865))
- updated typescript, migrated to tslint ([3a40fcc](https://github.com/SkeLLLa/node-object-hash/commit/3a40fccbe03f265b8452b59ac1434cb1b0ceb6a3))
### Bug fixes
- remove unnecessary checks ([1bbad3a](https://github.com/SkeLLLa/node-object-hash/commit/1bbad3a2f6dc1dd28ed48ab2ca065b878b450f53))
- **lint:** fix eslint ([caeac70](https://github.com/SkeLLLa/node-object-hash/commit/caeac700031c7637448e4d76f2d2fe9276df2b01))
- **types:** fix encoding type ([cdc6958](https://github.com/SkeLLLa/node-object-hash/commit/cdc69588b781095764d574b6f14e00b2609ff4e5))
- improve checking of Hashable applicant ([3856207](https://github.com/SkeLLLa/node-object-hash/commit/38562077f9465e1aa871e607fd13de861f10582d))
### Misc
- **deps:** bump deps ([a370ea2](https://github.com/SkeLLLa/node-object-hash/commit/a370ea2bf9b89b94063d5fb3e584da20dd0eb855))
- **pj:** add prettier to docs ([77b6001](https://github.com/SkeLLLa/node-object-hash/commit/77b6001674284fc613e95fd44cddb9aec143aeb5))
- **pj:** update scripts ([dd8c778](https://github.com/SkeLLLa/node-object-hash/commit/dd8c778301899e41dacb73f83426a733bb327dda))
## [2.0.0](https://gitlab.com/m03geek/node-object-hash/compare/v2.0.0-rc.1...v2.0.0) (2019-09-07)

@@ -12,38 +34,39 @@

### ⚠ BREAKING CHANGES
* Library rewritten in typescript that could cause some side-effects, but it should not.
* With `coerce=false` `Set`s will no longer generate the same hashes as `Array`s. In order to restore previous behavior set `coerce.set=true`.
* With `coerce=false` `Symbol`s will generate hash based on symbol `.toString` value. That's useful for `Symbol.for('smth')`. If `coerce.symbol=true` all `Symbols`s will have equal hashes.
TLDR; If you use library with `Set`s or `Symbol`s with `coerce=false` in order to keep hashes the same as in `v1.X.X` you should use following constructor:
- Library rewritten in typescript that could cause some side-effects, but it should not.
- With `coerce=false` `Set`s will no longer generate the same hashes as `Array`s. In order to restore previous behavior set `coerce.set=true`.
- With `coerce=false` `Symbol`s will generate hash based on symbol `.toString` value. That's useful for `Symbol.for('smth')`. If `coerce.symbol=true` all `Symbols`s will have equal hashes.
TLDR; If you use library with `Set`s or `Symbol`s with `coerce=false` in order to keep hashes the same as in `v1.X.X` you should use following constructor:
```
const hasher = require('node-object-hash')({coerce: {set: true, symbol: true}})
```
* Object sorter sources moved to `dist` directory. If you required it directly via `require('node-object-hash/objectSorter')` you should change it to require('node-object-hash/dist/objectSorter').
* Removed old `v0` version from code.
* Changed license to MIT.
- Object sorter sources moved to `dist` directory. If you required it directly via `require('node-object-hash/objectSorter')` you should change it to require('node-object-hash/dist/objectSorter').
- Removed old `v0` version from code.
- Changed license to MIT.
### Bug Fixes
* **hasher:** fix options ([05241ca](https://gitlab.com/m03geek/node-object-hash/commit/05241ca))
- **hasher:** fix options ([05241ca](https://gitlab.com/m03geek/node-object-hash/commit/05241ca))
### Features
* major refactor ([450471e](https://gitlab.com/m03geek/node-object-hash/commit/450471e))
* New granular options. Now you can specify what types need to be sorted or coerced.
* Add new `trim` option. It can be used to remove unncecessary spaces in `string`s or `function` bodies.
* Library rewritten to typescript, so it may have better ts compatibility.
- major refactor ([450471e](https://gitlab.com/m03geek/node-object-hash/commit/450471e))
- New granular options. Now you can specify what types need to be sorted or coerced.
- Add new `trim` option. It can be used to remove unncecessary spaces in `string`s or `function` bodies.
- Library rewritten to typescript, so it may have better ts compatibility.
## [1.4.X](https://gitlab.com/m03geek/node-object-hash/compare/v1.3.0...v1.4.2)
### Features
### Features
* Add support for objects without constructor #11 [PR @futpib](https://gitlab.com/m03geek/node-object-hash/pull/12)
* Simplify eslint rules, update codestyle
- Add support for objects without constructor #11 [PR @futpib](https://gitlab.com/m03geek/node-object-hash/pull/12)
- Simplify eslint rules, update codestyle
### Fixes
* Fix npm links issues in readme
* Update dev dependencies
- Fix npm links issues in readme
- Update dev dependencies

@@ -54,8 +77,8 @@ ## [1.3.X](https://gitlab.com/m03geek/node-object-hash/compare/v1.2.0...v1.3.0)

* Add definition types to support typescript
* Add >=node-8.0.0 support in tests.
- Add definition types to support typescript
- Add >=node-8.0.0 support in tests.
## [1.2.X](https://gitlab.com/m03geek/node-object-hash/compare/v1.1.6...v1.2.0)
### Features
### Features

@@ -75,3 +98,3 @@ - Added typed arrays support

- Renamed `sortObject` function to `sort` (old one is still present in code
for backward compatibility).
for backward compatibility).
- Performed some refactoring for better codestyle and documentation.

@@ -84,9 +107,9 @@ - Old version (`0.X.X`) moved to subfolder (`./v0`).

- Sorting mechanism rewritten form ES6 Maps to simple arrays
(add <=node-4.0.0 support)
(add <=node-4.0.0 support)
- Performance optimization (~2 times faster than 0.x.x)
- API changes:
- Now module returns 'constructor' function, where you can set
default parameters: ```var objectHash = require('node-object-hash')(options);```
default parameters: `var objectHash = require('node-object-hash')(options);`
In case if you still need an old 0.x.x version it's available in `hash.js`
file.
/// <reference types="node" />
import objectSorter = require('./objectSorter');
import { HexBase64Latin1Encoding } from 'crypto';
import objectSorter from './objectSorter';
import { BinaryToTextEncoding } from 'crypto';
declare namespace hasher {

@@ -16,6 +16,14 @@ /**

* String encoding for hash
* @default 'hex'
* @default 'base64'
*/
enc?: HexBase64Latin1Encoding;
enc?: BinaryToTextEncoding;
}
/**
* If object implements Hashable interface then value from toHash
* will be used for hash function. It means that the different objects
* with the function toHash that return the same value will have the same hash
*/
interface Hashable {
toHashableString: () => string;
}
interface Hasher {

@@ -27,3 +35,3 @@ /**

*/
hash(object: any, opts?: hasher.HasherOptions): string;
hash(object: Hashable | any, opts?: hasher.HasherOptions): string;
/**

@@ -47,2 +55,3 @@ * Create sorted string from an object

* @param options hasher options
* @return hasher instance
*/

@@ -49,0 +58,0 @@ declare function hasher(options?: hasher.HasherOptions): hasher.Hasher;

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

};
var objectSorter = require("./objectSorter");
var objectSorter_1 = __importDefault(require("./objectSorter"));
var crypto_1 = __importDefault(require("crypto"));

@@ -15,19 +15,23 @@ /**

*/
var DEFAULT_ENV = 'hex';
var DEFAULT_ENC = 'hex';
/**
* Hasher constructor
* @param options hasher options
* @return hasher instance
*/
function hasher(options) {
if (options === void 0) { options = {}; }
var sortObject = objectSorter(options);
var sortObject = objectSorter_1.default(options);
/**
* Object hash function
* @param obj object to hash
* @param opts hasher options
* @returns hash string
*/
function hashObject(obj, opts) {
if (opts === void 0) { opts = {}; }
var alg = opts.alg || options.alg || DEFAULT_ALG;
var enc = opts.enc || options.enc || DEFAULT_ENV;
var enc = opts.enc || options.enc || DEFAULT_ENC;
var sorted = sortObject(obj);
return crypto_1.default
.createHash(alg)
.update(sorted)
.digest(enc);
return crypto_1.default.createHash(alg).update(sorted).digest(enc);
}

@@ -34,0 +38,0 @@ return {

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

import { Hashable } from './hasher';
declare namespace objectSorter {

@@ -159,2 +160,3 @@ /**

}
type StringifyFn = (obj: Hashable | any) => string;
}

@@ -164,6 +166,6 @@ /**

* @param options object transformation options
* @returns function that transforms object to strings
* @return function that transforms object to strings
*/
declare function objectSorter(options?: objectSorter.SorterOptions): (obj: any) => string;
declare function objectSorter(options?: objectSorter.SorterOptions): objectSorter.StringifyFn;
export = objectSorter;
//# sourceMappingURL=objectSorter.d.ts.map

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

};
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result["default"] = mod;
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;

@@ -26,3 +38,3 @@ };

* @param options object transformation options
* @returns function that transforms object to strings
* @return function that transforms object to strings
*/

@@ -34,8 +46,7 @@ function objectSorter(options) {

unknown: function _unknown(obj) {
var _a, _b;
// `unknonw` - is a typo, saved for backward compatibility
var constructorName = obj.constructor
? obj.constructor.name
: 'unknonw';
var constructorName = (_b = (_a = obj.constructor) === null || _a === void 0 ? void 0 : _a.name) !== null && _b !== void 0 ? _b : 'unknonw';
var objectName = typeof obj.toString === 'function' ? obj.toString() : 'unknown';
return '<:' + constructorName + '>:' + objectName;
return "<:" + constructorName + ">:" + objectName;
},

@@ -64,2 +75,3 @@ };

};
stringifiers.hashable = str._hashable.bind(stringifiers);
if (trimOptions.string) {

@@ -122,2 +134,6 @@ stringifiers.string = coerceOptions.string

: str._map.bind(stringifiers);
/**
* Serializes object to string
* @param obj object
*/
function objectToString(obj) {

@@ -124,0 +140,0 @@ return stringifiers[typeGuess_1.guessType(obj)](obj);

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

*/
import { Hashable } from './hasher';
/**

@@ -29,3 +30,3 @@ * List of functions responsible for converting certain types to string

/**
* Converts string to string
* Converts Hashable to string
* @private

@@ -35,2 +36,9 @@ * @param obj object to convert

*/
export declare function _hashable(obj: Hashable): string;
/**
* Converts string to string
* @private
* @param obj object to convert
* @return object string representation
*/
export declare function _stringCoerce(obj: string): string;

@@ -41,3 +49,3 @@ /**

* @param obj object to convert
* @returns object string representation
* @return object string representation
*/

@@ -49,3 +57,3 @@ export declare function _string(obj: string): string;

* @param obj object to convert
* @returns object string representation
* @return object string representation
*/

@@ -57,3 +65,3 @@ export declare function _stringTrimCoerce(obj: string): string;

* @param obj object to convert
* @returns object string representation
* @return object string representation
*/

@@ -65,3 +73,3 @@ export declare function _stringTrim(obj: string): string;

* @param obj object to convert
* @returns object string representation
* @return object string representation
*/

@@ -73,3 +81,3 @@ export declare function _numberCoerce(obj: number): string;

* @param obj object to convert
* @returns object string representation
* @return object string representation
*/

@@ -81,3 +89,3 @@ export declare function _number(obj: number): string;

* @param obj object to convert
* @returns object string representation
* @return object string representation
*/

@@ -89,3 +97,3 @@ export declare function _booleanCoerce(obj: boolean): string;

* @param obj object to convert
* @returns object string representation
* @return object string representation
*/

@@ -97,3 +105,3 @@ export declare function _boolean(obj: boolean): string;

* @param obj object to convert
* @returns object string representation
* @return object string representation
*/

@@ -105,3 +113,3 @@ export declare function _symbolCoerce(): string;

* @param obj object to convert
* @returns object string representation
* @return object string representation
*/

@@ -113,3 +121,3 @@ export declare function _symbol(obj: symbol): string;

* @param obj object to convert
* @returns object string representation
* @return object string representation
*/

@@ -121,3 +129,3 @@ export declare function _undefinedCoerce(): string;

* @param obj object to convert
* @returns object string representation
* @return object string representation
*/

@@ -129,3 +137,3 @@ export declare function _undefined(): string;

* @param obj object to convert
* @returns object string representation
* @return object string representation
*/

@@ -137,3 +145,3 @@ export declare function _nullCoerce(): string;

* @param obj object to convert
* @returns object string representation
* @return object string representation
*/

@@ -145,3 +153,3 @@ export declare function _null(): string;

* @param obj object to convert
* @returns object string representation
* @return object string representation
*/

@@ -153,3 +161,3 @@ export declare function _functionCoerce(obj: Function): string;

* @param obj object to convert
* @returns object string representation
* @return object string representation
*/

@@ -161,3 +169,3 @@ export declare function _function(obj: Function): string;

* @param obj object to convert
* @returns object string representation
* @return object string representation
*/

@@ -169,3 +177,3 @@ export declare function _functionTrimCoerce(obj: Function): string;

* @param obj object to convert
* @returns object string representation
* @return object string representation
*/

@@ -177,3 +185,3 @@ export declare function _functionTrim(obj: Function): string;

* @param obj object to convert
* @returns object string representation
* @return object string representation
*/

@@ -185,3 +193,3 @@ export declare function _dateCoerce(obj: Date): string;

* @param obj object to convert
* @returns object string representation
* @return object string representation
*/

@@ -193,3 +201,3 @@ export declare function _date(obj: Date): string;

* @param obj object to convert
* @returns object string representation
* @return object string representation
*/

@@ -201,3 +209,3 @@ export declare function _arraySort(obj: Array<any>): string;

* @param obj object to convert
* @returns object string representation
* @return object string representation
*/

@@ -209,3 +217,3 @@ export declare function _array(obj: Array<any>): string;

* @param obj object to convert
* @returns object string representation
* @return object string representation
*/

@@ -217,3 +225,3 @@ export declare function _setSortCoerce(obj: Set<any>): string;

* @param obj object to convert
* @returns object string representation
* @return object string representation
*/

@@ -225,3 +233,3 @@ export declare function _setSort(obj: Set<any>): string;

* @param obj object to convert
* @returns object string representation
* @return object string representation
*/

@@ -233,3 +241,3 @@ export declare function _set(obj: Set<any>): string;

* @param obj object to convert
* @returns object string representation
* @return object string representation
*/

@@ -241,3 +249,3 @@ export declare function _setCoerce(obj: Set<any>): string;

* @param obj object to convert
* @returns object string representation
* @return object string representation
*/

@@ -251,3 +259,3 @@ export declare function _object(obj: {

* @param obj object to convert
* @returns object string representation
* @return object string representation
*/

@@ -261,3 +269,3 @@ export declare function _objectSort(obj: {

* @param obj object to convert
* @returns object string representation
* @return object string representation
*/

@@ -269,5 +277,5 @@ export declare function _map(obj: Map<any, any>): string;

* @param obj object to convert
* @returns object string representation
* @return object string representation
*/
export declare function _mapSort(obj: Map<any, any>): string;
//# sourceMappingURL=stringifiers.d.ts.map

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

Object.defineProperty(exports, "__esModule", { value: true });
exports._mapSort = exports._map = exports._objectSort = exports._object = exports._setCoerce = exports._set = exports._setSort = exports._setSortCoerce = exports._array = exports._arraySort = exports._date = exports._dateCoerce = exports._functionTrim = exports._functionTrimCoerce = exports._function = exports._functionCoerce = exports._null = exports._nullCoerce = exports._undefined = exports._undefinedCoerce = exports._symbol = exports._symbolCoerce = exports._boolean = exports._booleanCoerce = exports._number = exports._numberCoerce = exports._stringTrim = exports._stringTrimCoerce = exports._string = exports._stringCoerce = exports._hashable = exports.PREFIX = void 0;
var typeGuess_1 = require("./typeGuess");

@@ -26,3 +27,3 @@ /**

/**
* Converts string to string
* Converts Hashable to string
* @private

@@ -32,2 +33,12 @@ * @param obj object to convert

*/
function _hashable(obj) {
return obj.toHashableString();
}
exports._hashable = _hashable;
/**
* Converts string to string
* @private
* @param obj object to convert
* @return object string representation
*/
function _stringCoerce(obj) {

@@ -41,3 +52,3 @@ return obj;

* @param obj object to convert
* @returns object string representation
* @return object string representation
*/

@@ -52,3 +63,3 @@ function _string(obj) {

* @param obj object to convert
* @returns object string representation
* @return object string representation
*/

@@ -63,3 +74,3 @@ function _stringTrimCoerce(obj) {

* @param obj object to convert
* @returns object string representation
* @return object string representation
*/

@@ -74,3 +85,3 @@ function _stringTrim(obj) {

* @param obj object to convert
* @returns object string representation
* @return object string representation
*/

@@ -85,6 +96,6 @@ function _numberCoerce(obj) {

* @param obj object to convert
* @returns object string representation
* @return object string representation
*/
function _number(obj) {
return exports.PREFIX.number + ':' + obj;
return exports.PREFIX.number + ":" + obj;
}

@@ -96,3 +107,3 @@ exports._number = _number;

* @param obj object to convert
* @returns object string representation
* @return object string representation
*/

@@ -107,3 +118,3 @@ function _booleanCoerce(obj) {

* @param obj object to convert
* @returns object string representation
* @return object string representation
*/

@@ -118,3 +129,3 @@ function _boolean(obj) {

* @param obj object to convert
* @returns object string representation
* @return object string representation
*/

@@ -129,3 +140,3 @@ function _symbolCoerce() {

* @param obj object to convert
* @returns object string representation
* @return object string representation
*/

@@ -140,3 +151,3 @@ function _symbol(obj) {

* @param obj object to convert
* @returns object string representation
* @return object string representation
*/

@@ -151,3 +162,3 @@ function _undefinedCoerce() {

* @param obj object to convert
* @returns object string representation
* @return object string representation
*/

@@ -162,3 +173,3 @@ function _undefined() {

* @param obj object to convert
* @returns object string representation
* @return object string representation
*/

@@ -173,3 +184,3 @@ function _nullCoerce() {

* @param obj object to convert
* @returns object string representation
* @return object string representation
*/

@@ -184,3 +195,3 @@ function _null() {

* @param obj object to convert
* @returns object string representation
* @return object string representation
*/

@@ -195,3 +206,3 @@ function _functionCoerce(obj) {

* @param obj object to convert
* @returns object string representation
* @return object string representation
*/

@@ -206,3 +217,3 @@ function _function(obj) {

* @param obj object to convert
* @returns object string representation
* @return object string representation
*/

@@ -222,3 +233,3 @@ function _functionTrimCoerce(obj) {

* @param obj object to convert
* @returns object string representation
* @return object string representation
*/

@@ -240,3 +251,3 @@ function _functionTrim(obj) {

* @param obj object to convert
* @returns object string representation
* @return object string representation
*/

@@ -251,3 +262,3 @@ function _dateCoerce(obj) {

* @param obj object to convert
* @returns object string representation
* @return object string representation
*/

@@ -262,3 +273,3 @@ function _date(obj) {

* @param obj object to convert
* @returns object string representation
* @return object string representation
*/

@@ -281,3 +292,3 @@ function _arraySort(obj) {

* @param obj object to convert
* @returns object string representation
* @return object string representation
*/

@@ -299,3 +310,3 @@ function _array(obj) {

* @param obj object to convert
* @returns object string representation
* @return object string representation
*/

@@ -310,6 +321,6 @@ function _setSortCoerce(obj) {

* @param obj object to convert
* @returns object string representation
* @return object string representation
*/
function _setSort(obj) {
return exports.PREFIX.set + ':' + _arraySort.call(this, Array.from(obj));
return exports.PREFIX.set + ":" + _arraySort.call(this, Array.from(obj));
}

@@ -321,6 +332,6 @@ exports._setSort = _setSort;

* @param obj object to convert
* @returns object string representation
* @return object string representation
*/
function _set(obj) {
return exports.PREFIX.set + ':' + _array.call(this, Array.from(obj));
return exports.PREFIX.set + ":" + _array.call(this, Array.from(obj));
}

@@ -332,3 +343,3 @@ exports._set = _set;

* @param obj object to convert
* @returns object string representation
* @return object string representation
*/

@@ -343,3 +354,3 @@ function _setCoerce(obj) {

* @param obj object to convert
* @returns object string representation
* @return object string representation
*/

@@ -363,3 +374,3 @@ function _object(obj) {

* @param obj object to convert
* @returns object string representation
* @return object string representation
*/

@@ -383,3 +394,3 @@ function _objectSort(obj) {

* @param obj object to convert
* @returns object string representation
* @return object string representation
*/

@@ -392,3 +403,3 @@ function _map(obj) {

var item = arr_1[_i];
var key = item[0], value = item[1];
var _a = item, key = _a[0], value = _a[1];
mapped.push([

@@ -406,3 +417,3 @@ stringifiers[typeGuess_1.guessType(key)](key),

* @param obj object to convert
* @returns object string representation
* @return object string representation
*/

@@ -415,3 +426,3 @@ function _mapSort(obj) {

var item = arr_2[_i];
var key = item[0], value = item[1];
var _a = item, key = _a[0], value = _a[1];
mapped.push([

@@ -418,0 +429,0 @@ stringifiers[typeGuess_1.guessType(key)](key),

@@ -10,11 +10,11 @@ /**

* @param obj analyzed object
* @returns object type
* @return object type
*/
export declare function guessObjectType(obj: object): string;
export declare function guessObjectType(obj: unknown): string;
/**
* Guess variable type
* @param obj analyzed variable
* @returns variable type
* @return variable type
*/
export declare function guessType(obj: any): string;
export declare function guessType(obj: unknown): string;
//# sourceMappingURL=typeGuess.d.ts.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.guessType = exports.guessObjectType = exports.TYPE_MAP = void 0;
/**

@@ -29,9 +30,13 @@ * Type mapping rules.

* @param obj analyzed object
* @returns object type
* @return object type
*/
function guessObjectType(obj) {
var _a, _b;
if (obj === null) {
return 'null';
}
var type = obj.constructor ? obj.constructor.name : 'unknown';
if (instanceOfHashable(obj)) {
return 'hashable';
}
var type = (_b = (_a = obj.constructor) === null || _a === void 0 ? void 0 : _a.name) !== null && _b !== void 0 ? _b : 'unknown';
return exports.TYPE_MAP[type] || 'unknown';

@@ -43,3 +48,3 @@ }

* @param obj analyzed variable
* @returns variable type
* @return variable type
*/

@@ -51,2 +56,11 @@ function guessType(obj) {

exports.guessType = guessType;
/**
* Identify if object is instance of Hashable interface
* @param object analyzed variable
* @return true if object has toHashableString property and this property is function
* otherwise return false
*/
function instanceOfHashable(object) {
return typeof object.toHashableString === 'function';
}
//# sourceMappingURL=typeGuess.js.map
{
"name": "node-object-hash",
"version": "2.0.0",
"version": "2.1.0",
"description": "Node.js object hash library with properties/arrays sorting to provide constant hashes",
"keywords": [
"hash",
"object",
"hash-object",
"object-hash",
"es6",
"crypto"
],
"homepage": "https://gitlab.com/m03geek/node-object-hash#README",
"bugs": {
"url": "https://gitlab.com/m03geek/node-object-hash/issues"
},
"repository": {
"type": "git",
"url": "https://github.com/SkeLLLa/node-object-hash.git"
},
"license": "MIT",
"author": "m03geek",
"main": "dist/hasher.js",
"types": "dist/hasher.d.ts",
"directories": {
"test": "test",
"lib": "dist",
"doc": "docs"
"doc": "docs",
"test": "test"
},

@@ -17,45 +35,3 @@ "files": [

],
"husky": {
"hooks": {
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS"
}
},
"standard-version": {
"scripts": {
"prerelease": "npm run test",
"postbump": "echo Version: v$npm_package_version",
"postchangelog": "replace \"https://github.com/SkeLLLa/\" \"https://gitlab.com/m03geek/\" CHANGELOG.md",
"posttag": "git push --follow-tags origin $npm_package_config_releaseBranch"
}
},
"dependencies": {},
"devDependencies": {
"@commitlint/cli": "^8.0.0",
"@commitlint/config-conventional": "^8.0.0",
"@types/jest": "^24.0.15",
"@types/node": "^12.7.4",
"codecov": "^3.5.0",
"eslint": "^6.3.0",
"eslint-config-google": "^0.14.0",
"faker": "^4.0.0",
"husky": "^3.0.5",
"jest": "^24.7.1",
"replace": "^1.1.0",
"standard-version": "^7.0.0",
"ts-jest": "^24.0.2",
"ts-node": "^8.3.0",
"tslint": "^5.18.0",
"tslint-eslint-rules": "^5.4.0",
"typedoc": "^0.15.0",
"typedoc-plugin-markdown": "^2.1.10",
"typescript": "^3.6.2"
},
"scripts": {
"lint:eslint": "eslint .",
"lint:tslint": "tslint -p ./ && tslint -p ./test",
"lint": "npm run lint:eslint && npm run lint:tslint",
"lint:fix": "eslint . --fix && tslint -p ./ --fix && tslint -p ./test --fix",
"test": "npm audit || true && npm run lint && npm run unit",
"unit": "jest --coverage",
"postunit": "codecov",
"prebenchmark": "npm i --no-save hash-object object-hash benchmark",

@@ -67,24 +43,47 @@ "benchmark": "node benchmark/bench.js",

"build:node": "tsc -p tsconfig.json",
"get-changelog": "conventional-changelog -r 2 -p angular",
"lint": "npm run lint:eslint",
"lint:eslint": "eslint . --ext js,jsx,ts,tsx",
"prerelease": "npm run typedoc && git add -A ./docs",
"release": "git add -A && standard-version -a",
"typedoc": "rm -rf ./docs/* && typedoc --excludeExternals --name \"$npm_package_name\" --readme none --mode file --includeDeclarations --excludePrivate --theme markdown --out ./docs"
"test": "npm audit --production && npm run lint && npm run unit",
"typedoc": "rm -rf ./docs/* && typedoc && pretty-quick",
"unit": "jest --coverage",
"postunit": "codecov || true"
},
"repository": {
"type": "git",
"url": "https://github.com/SkeLLLa/node-object-hash.git"
"husky": {
"hooks": {
"pre-commit": "pretty-quick --staged",
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS"
}
},
"bugs": {
"url": "https://gitlab.com/m03geek/node-object-hash/issues"
"devDependencies": {
"@commitlint/cli": "^11.0.0",
"@commitlint/config-conventional": "^11.0.0",
"@types/jest": "^26.0.0",
"@types/node": "^14.0.0",
"@typescript-eslint/eslint-plugin": "^4.14.1",
"@typescript-eslint/parser": "^4.14.1",
"codecov": "^3.5.0",
"conventional-changelog-cli": "^2.1.1",
"eslint": "^7.0.0",
"eslint-config-google": "^0.14.0",
"eslint-config-prettier": "^7.2.0",
"eslint-plugin-jest": "^24.1.3",
"eslint-plugin-prettier": "^3.3.1",
"eslint-plugin-sort-requires": "^2.1.0",
"faker": "^5.0.0",
"husky": "^4.0.0",
"jest": "^26.0.0",
"prettier": "^2.2.1",
"prettier-plugin-packagejson": "^2.2.9",
"pretty-quick": "^3.1.0",
"replace": "^1.1.0",
"standard-version": "^9.0.0",
"ts-jest": "^26.0.0",
"ts-node": "^9.0.0",
"typedoc": "^0.20.0",
"typedoc-plugin-markdown": "^3.0.0",
"typescript": "^4.0.0"
},
"homepage": "https://gitlab.com/m03geek/node-object-hash#README",
"keywords": [
"hash",
"object",
"hash-object",
"object-hash",
"es6",
"crypto"
],
"author": "m03geek",
"license": "MIT",
"engines": {

@@ -91,0 +90,0 @@ "node": ">=0.10.0"

@@ -17,5 +17,5 @@ # node-object-hash

[![Npms.io Score](https://badges.npms.io/node-object-hash.svg)](https://npms.io/search?q=node-object-hash)
[![Build Status](https://gitlab.com/m03geek/node-object-hash/badges/master/pipeline.svg)](https://gitlab.com/m03geek/node-object-hash/commits/master)
[![Build Status](https://github.com/SkeLLLa/node-object-hash/workflows/build/badge.svg)](https://github.com/SkeLLLa/node-object-hash/commits/master)
[![License](https://img.shields.io/npm/l/node-object-hash.svg)](https://gitlab.com/m03geek/node-object-hash/blob/master/LICENSE)
[![Codecov Coverage](https://img.shields.io/codecov/c/gl/m03geek/node-object-hash.svg)](https://codecov.io/gl/m03geek/node-object-hash)
[![Codecov Coverage](https://codecov.io/gh/SkeLLLa/node-object-hash/branch/master/graph/badge.svg?token=wLjMou8TT7)](https://codecov.io/gh/SkeLLLa/node-object-hash)
[![LGTM Alerts](https://img.shields.io/lgtm/alerts/github/SkeLLLa/node-object-hash.svg)](https://lgtm.com/projects/g/SkeLLLa/node-object-hash/)

@@ -29,2 +29,3 @@ [![LGTM Grade](https://img.shields.io/lgtm/grade/javascript/github/SkeLLLa/node-object-hash.svg)](https://lgtm.com/projects/g/SkeLLLa/node-object-hash/)

## ToC
- [node-object-hash](#node-object-hash)

@@ -46,2 +47,3 @@ - [ToC](#toc)

- [`sort(object)`](#sortobject)
- [Hashing custom objects](#hashing-custom-objects)
- [Requirements](#requirements)

@@ -61,20 +63,22 @@ - [version \>=1.0.0](#version-100)

### Breaking changes
### Breaking changes
* Library rewritten in typescript that could cause some side-effects, but it should not.
* With `coerce=false` `Set`s will no longer generate the same hashes as `Array`s. In order to restore previous behavior set `coerce.set=true`.
* With `coerce=false` `Symbol`s will generate hash based on symbol `.toString` value. That's useful for `Symbol.for('smth')`. If `coerce.symbol=true` all `Symbols`s will have equal hashes.
TLDR; If you use library with `Set`s or `Symbol`s with `coerce=false` in order to keep hashes the same as in `v1.X.X` you should use following constructor:
- Library rewritten in typescript that could cause some side-effects, but it should not.
- With `coerce=false` `Set`s will no longer generate the same hashes as `Array`s. In order to restore previous behavior set `coerce.set=true`.
- With `coerce=false` `Symbol`s will generate hash based on symbol `.toString` value. That's useful for `Symbol.for('smth')`. If `coerce.symbol=true` all `Symbols`s will have equal hashes.
TLDR; If you use library with `Set`s or `Symbol`s with `coerce=false` in order to keep hashes the same as in `v1.X.X` you should use following constructor:
```
const hasher = require('node-object-hash')({coerce: {set: true, symbol: true}})
```
* Object sorter sources moved to `dist` directory. If you required it directly via `require('node-object-hash/objectSorter')` you should change it to require('node-object-hash/dist/objectSorter').
* Removed old `v0` version from code.
* Changed license to MIT.
- Object sorter sources moved to `dist` directory. If you required it directly via `require('node-object-hash/objectSorter')` you should change it to require('node-object-hash/dist/objectSorter').
- Removed old `v0` version from code.
- Changed license to MIT.
### New features
* New granular options. Now you can specify what types need to be sorted or coerced.
* Add new `trim` option. It can be used to remove unncecessary spaces in `string`s or `function` bodies.
* Library rewritten to typescript, so it may have better ts compatibility.
- New granular options. Now you can specify what types need to be sorted or coerced.
- Add new `trim` option. It can be used to remove unncecessary spaces in `string`s or `function` bodies.
- Library rewritten to typescript, so it may have better ts compatibility.

@@ -101,3 +105,3 @@ ## Installation

| Initial type | Mapped type |
|---------------------------|--------------|
| ------------------------- | ------------ |
| Array ([]) | array |

@@ -116,33 +120,33 @@ | ArrayObject (new Array()) | |

| Set | |
| | |
| | |
| Map | array[array] |
| | |
| string ('') | string | string |
| | |
| string ('') | string |
| String (new String()) | |
| | |
| | |
| boolean (true) | boolean |
| Boolean (new Boolean()) | |
| | |
| | |
| number (true) | number |
| Number (new Number()) | |
| | |
| | |
| Date | date |
| | |
| | |
| Symbol | symbol |
| | |
| | |
| undefined | undefined |
| | |
| | |
| null | null |
| | |
| | |
| function | function |
| | |
| | |
| Object ({}) | object |
| Object (new Object()) | |
| | |
| | |
| other | unknown |
### Coercion map
### Coercion map
| Initial "type" | Coerced type | Example |
|----------------|----------------|--------------|
| -------------- | -------------- | ------------ |
| boolean | string | true -> 1 |

@@ -167,3 +171,3 @@ | number | string | '1' -> 1 |

```js
require('node-object-hash')([options])
require('node-object-hash')([options]);
```

@@ -174,10 +178,11 @@

Parameters:
* `options`:`object` - object with hasher config options
* `options.coerce`:`boolean|object` - if true performs type coercion (default: `true`);
e.g. `hash(true) == hash('1') == hash(1)`, `hash(false) == hash('0') == hash(0)`
* `options.sort`:`boolean|object` - if true performs sorting on objects, arrays, etc. (default: `true`);
* `options.trim`:`boolean|object` - if true performs trim of spaces and replaces space-like characters with single space (default: `false`);
* `options.alg`:`string` - sets default hash algorithm (default: `'sha256'`); can be overridden in `hash` method;
* `options.enc`:`string` - sets default hash encoding (default: `'hex'`); can be overridden in `hash` method;
- `options`:`object` - object with hasher config options
- `options.coerce`:`boolean|object` - if true performs type coercion (default: `true`);
e.g. `hash(true) == hash('1') == hash(1)`, `hash(false) == hash('0') == hash(0)`
- `options.sort`:`boolean|object` - if true performs sorting on objects, arrays, etc. (default: `true`);
- `options.trim`:`boolean|object` - if true performs trim of spaces and replaces space-like characters with single space (default: `false`);
- `options.alg`:`string` - sets default hash algorithm (default: `'sha256'`); can be overridden in `hash` method;
- `options.enc`:`string` - sets default hash encoding (default: `'hex'`); can be overridden in `hash` method;
### API methods

@@ -188,18 +193,28 @@

Returns hash string.
* `object`:`*` object for calculating hash;
* `options`:`object` object with options;
* `options.alg`:`string` - hash algorithm (default: `'sha256'`);
* `options.enc`:`string` - hash encoding (default: `'hex'`);
- `object`:`*` object for calculating hash;
- `options`:`object` object with options;
- `options.alg`:`string` - hash algorithm (default: `'sha256'`);
- `options.enc`:`string` - hash encoding (default: `'hex'`);
#### `sort(object)`
Returns sorted string generated from object (can be used for object comparison)
* `object`:`*` - object for sorting;
- `object`:`*` - object for sorting;
### Hashing custom objects
In order to serialize and hash your custom objects you may provide `.toHashableString()` method for your object. It should return `string` that will be hashed. You may use `objectSorter` and pass notable fields to it in your `.toHashableString` method.
For typescript users you may add to your classes `implements Hashable`.
## Requirements
### version \>=1.0.0
- `>=nodejs-0.10.0`
### version \>=0.1.0 && <1.0.0
- `>=nodejs-6.0.0`

@@ -213,3 +228,3 @@ - `>=nodejs-4.0.0` (requires to run node with `--harmony` flag)

var hashSortCoerce = hasher({sort:true, coerce:true});
var hashSortCoerce = hasher({ sort: true, coerce: true });
// or

@@ -223,11 +238,11 @@ // var hashSortCoerce = hasher();

var objects = {
a: {
a: [{c: 2, a: 1, b: {a: 3, c: 2, b: 0}}],
b: [1, 'a', {}, null],
},
b: {
b: ['a', 1, {}, undefined],
a: [{c: '2', b: {b: false, c: 2, a: '3'}, a: true}]
},
c: ['4', true, 0, 2, 3]
a: {
a: [{ c: 2, a: 1, b: { a: 3, c: 2, b: 0 } }],
b: [1, 'a', {}, null],
},
b: {
b: ['a', 1, {}, undefined],
a: [{ c: '2', b: { b: false, c: 2, a: '3' }, a: true }],
},
c: ['4', true, 0, 2, 3],
};

@@ -250,33 +265,46 @@

* `npm run bench` to run custom benchmark
* `npm run benchmark` to run benchmark suite
- `npm run bench` to run custom benchmark
- `npm run benchmark` to run benchmark suite
- `npm run benchmark:hash` to run hash benchmark suite
### Results
| Hashing algorithm | Result hash bytes length | Performance (ops/sec) |
| ------------------ | ------------------------ | --------------------- |
| `sha256` (default) | 64 | 1,599 +- 5.77% |
| `sha1` | 40 | 1,983 +- 1.50% |
| `sha224` | 56 | 1,701 +- 2.81% |
| `sha384` | 96 | 1,800 +- 0.81% |
| `sha512` | 128 | 1,847 +- 1.75% |
| `md4` | 32 | 1,971 +- 0.98% |
| `md5` | 32 | 1,691 +- 3.18% |
| `whirlpool` | 128 | 1,487 +- 2.33% |
| | | |
#### Custom benchmark ([code](bench/index.js))
| Library | Time (ms) | Memory (Mb) |
|---------------------------------------|------------|--------------------|
| node-object-hash-0.2.1 | 5813.575 | 34 |
| node-object-hash-1.0.X | 2805.581 | 27 |
| node-object-hash-1.1.X (node v7) | 2555.583 | 27 |
| node-object-hash-1.2.X (node v7) | 2390.752 | 28 |
| node-object-hash-2.X.X (node v12) | 1990.622 | 24 |
| object-hash-1.1.5 (node v7) | 28115.553 | 39 |
| object-hash-1.1.4 | 534528.254 | 41 |
| object-hash-1.1.3 | ERROR | Out of heap memory |
| hash-object-0.1.7 | 9219.826 | 42 |
| Library | Time (ms) | Memory (Mb) |
| --------------------------------- | ---------- | ------------------ |
| node-object-hash-0.2.1 | 5813.575 | 34 |
| node-object-hash-1.0.X | 2805.581 | 27 |
| node-object-hash-1.1.X (node v7) | 2555.583 | 27 |
| node-object-hash-1.2.X (node v7) | 2390.752 | 28 |
| node-object-hash-2.X.X (node v12) | 1990.622 | 24 |
| object-hash-1.1.5 (node v7) | 28115.553 | 39 |
| object-hash-1.1.4 | 534528.254 | 41 |
| object-hash-1.1.3 | ERROR | Out of heap memory |
| hash-object-0.1.7 | 9219.826 | 42 |
#### Benchmark suite module ([code](bench/bench.js))
| Library (node v12) | Perf (ops/s) |
|------------------------|--------------|
| Library (node v12) | Perf (ops/s) |
| ---------------------- | ------------ |
| node-object-hash-2.0.0 | 2087 ±0.59% |
| object-hash-1.3.1 | 239 ±0.39% |
| hash-object-0.1.7 | 711 ±0.18% |
| object-hash-1.3.1 | 239 ±0.39% |
| hash-object-0.1.7 | 711 ±0.18% |
### Links
* [object-hash](https://www.npmjs.com/package/object-hash) - Slow, useful for browsers because it not uses node's crypto library
* [hash-object](https://www.npmjs.com/package/hash-object) - no ES6 types support
- [object-hash](https://www.npmjs.com/package/object-hash) - Slow, useful for browsers because it not uses node's crypto library
- [hash-object](https://www.npmjs.com/package/hash-object) - no ES6 types support

@@ -283,0 +311,0 @@ ## License

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

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc