subsetchecksum
v1.0.0
Published
Create a deterministic checksum from a selected subset of object paths.
Maintainers
Readme
subsetchecksum
Build a deterministic SHA-256 checksum from a subset of object values.
Behavior
- If
objectisnull, returnsnull. keyscan be:- an array of dot-paths (
['profile.name', 'email']) - a mapping object (
{ 'profile.name': 'name', emailaddress: 'email' })
- an array of dot-paths (
- If
keysis empty (or not provided), key paths are auto-generated from object leaf paths. - Nested fields are supported with dot-path notation like
profile.name.first. - If a selected value is an object, it is stored as a deterministic JSON string (recursively key-sorted before
JSON.stringify). - If
JSON.stringifythrows (for example circular references), that subset value is set tonull. - The generated subset object is sorted by key before hashing.
- In mapping-object mode, missing source paths are skipped (they do not write
nullinto the output key).
Install
npm install subsetchecksumTest
npm testUsage
const subsetChecksum = require('./index');
const source = {
id: 5,
profile: {
name: 'Dana',
},
};
const checksum = subsetChecksum(source, ['profile.name', 'id']);
console.log(checksum);When installed from npm:
const subsetChecksum = require('subsetchecksum');Mapping Mode Example
const subsetChecksum = require('./index');
const source = {
fullname: 'Jack Smith',
emailaddress: '[email protected]',
};
const checksum = subsetChecksum(source, {
formalname: 'name',
fullname: 'name',
emailaddress: 'email',
});
console.log(checksum);