New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

sha-anything

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sha-anything - npm Package Compare versions

Comparing version 0.0.4 to 1.0.0

10

dist/index.d.ts

@@ -1,12 +0,12 @@

declare function sortObject<T extends Record<string, unknown>>(obj: T, options?: {
export declare function sortObject<T extends {
[key in string]: unknown;
}>(obj: T, options?: {
deep?: boolean;
}): T;
declare function sortArray<T extends any[]>(array: T, options?: {
export declare function sortArray<T extends any[]>(array: T, options?: {
deep?: boolean;
}): T;
declare function sha256(payload: any, options?: {
export declare function sha256(payload: any, options?: {
sort?: boolean;
deepSort?: boolean;
}): Promise<string>;
export { sha256, sortArray, sortObject };

@@ -1,41 +0,34 @@

import { sha256 as sha256$1 } from 'crypto-hash';
import { isObject, isArray, isSymbol } from 'is-what';
import { sha256 as _sha256 } from 'crypto-hash';
import { sort } from 'fast-sort';
function sortObject(obj, options) {
const { deep = false } = options || {};
let entries = Object.entries(obj);
if (deep) {
entries = entries.map(
(entry) => isObject(entry[1]) ? [entry[0], sortObject(entry[1], options)] : isArray(entry[1]) ? [entry[0], sortArray(entry[1], options)] : entry
);
}
return Object.fromEntries(sort(entries).asc(([key]) => key));
import { isArray, isObject, isSymbol } from 'is-what';
export function sortObject(obj, options) {
const { deep = false } = options || {};
let entries = Object.entries(obj);
if (deep) {
entries = entries.map((entry) => isObject(entry[1])
? [entry[0], sortObject(entry[1], options)]
: isArray(entry[1])
? [entry[0], sortArray(entry[1], options)]
: entry);
}
return Object.fromEntries(sort(entries).asc(([key]) => key));
}
function sortArray(array, options) {
const { deep = false } = options || {};
if (deep) {
array = array.map(
(val) => isObject(val) ? sortObject(val, options) : isArray(val) ? sortArray(val, options) : val
);
}
return sort(array).asc();
export function sortArray(array, options) {
const { deep = false } = options || {};
if (deep) {
array = array.map((val) => isObject(val) ? sortObject(val, options) : isArray(val) ? sortArray(val, options) : val);
}
return sort(array).asc();
}
async function sha256(payload, options) {
const { sort: sort2 = false, deepSort = false } = options || {};
if (isSymbol(payload))
throw new Error("Cannot sha256 a symbol");
if (isObject(payload)) {
return sha256$1(
JSON.stringify(sort2 || deepSort ? sortObject(payload, { deep: deepSort }) : payload)
);
}
if (isArray(payload)) {
return sha256$1(
JSON.stringify(sort2 || deepSort ? sortArray(payload, { deep: deepSort }) : payload)
);
}
return sha256$1(`${payload}`);
export async function sha256(payload, options) {
const { sort = false, deepSort = false } = options || {};
if (isSymbol(payload))
throw new Error('Cannot sha256 a symbol');
if (isObject(payload)) {
return _sha256(JSON.stringify(sort || deepSort ? sortObject(payload, { deep: deepSort }) : payload));
}
if (isArray(payload)) {
return _sha256(JSON.stringify(sort || deepSort ? sortArray(payload, { deep: deepSort }) : payload));
}
return _sha256(`${payload}`);
}
export { sha256, sortArray, sortObject };
{
"name": "sha-anything",
"version": "0.0.4",
"version": "1.0.0",
"description": "A tiny TS utility to sha256 anything, including objects (with sorted keys option). Uses native crypto in browser & NodeJS.",
"type": "module",
"sideEffects": false,
"types": "./dist/index.d.ts",
"module": "./dist/index.js",
"main": "./dist/index.js",
"exports": {
".": {
"require": {
"types": "./dist/cjs/index.d.cts",
"default": "./dist/cjs/index.cjs"
},
"import": {
"types": "./dist/index.d.ts",
"default": "./dist/index.js"
}
}
".": "./dist/index.js"
},
"files": [
"dist"
],
"engines": {
"node": ">=12.13"
"node": ">=18"
},
"scripts": {
"test": "vitest run",
"lint": "tsc --noEmit && eslint ./src --ext .ts",
"build": "rollup -c ./rollup.config.js",
"release": "npm run lint && del dist && npm run build && np"
"lint": "tsc --noEmit && eslint ./src",
"build": "del-cli dist && tsc",
"release": "npm run lint && npm run build && np"
},
"dependencies": {
"crypto-hash": "^2.0.1",
"crypto-hash": "^3.0.0",
"fast-sort": "^3.4.0",
"is-what": "^4.1.8"
"is-what": "^5.0.0"
},
"devDependencies": {
"@typescript-eslint/eslint-plugin": "^5.59.2",
"@typescript-eslint/parser": "^5.59.2",
"del-cli": "^5.0.0",
"eslint": "^8.40.0",
"eslint-config-prettier": "^8.8.0",
"eslint-plugin-tree-shaking": "^1.10.0",
"np": "^7.7.0",
"prettier": "^2.8.8",
"rollup": "^3.23.0",
"rollup-plugin-dts": "^5.3.0",
"rollup-plugin-esbuild": "^5.0.0",
"typescript": "^4.9.5",
"vitest": "^0.31.0"
"del-cli": "^5.1.0",
"np": "^10.0.5",
"vitest": "^1.6.0",
"@cycraft/eslint": "^0.3.0",
"@cycraft/tsconfig": "^0.1.2"
},
"files": [
"dist"
],
"keywords": [

@@ -63,44 +43,11 @@ "sha",

],
"author": "Luca Ban - Mesqueeb",
"author": "Luca Ban - Mesqueeb (https://cycraft.co)",
"funding": "https://github.com/sponsors/mesqueeb",
"license": "MIT",
"bugs": {
"url": "https://github.com/mesqueeb/sha-anything/issues"
},
"homepage": "https://github.com/mesqueeb/sha-anything#readme",
"repository": {
"type": "git",
"url": "git+https://github.com/mesqueeb/sha-anything.git"
"url": "https://github.com/mesqueeb/sha-anything.git"
},
"np": {
"yarn": false,
"branch": "production"
},
"eslintConfig": {
"ignorePatterns": [
"node_modules",
"dist",
"scripts",
"test"
],
"root": true,
"parser": "@typescript-eslint/parser",
"plugins": [
"@typescript-eslint",
"tree-shaking"
],
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended",
"prettier"
],
"rules": {
"@typescript-eslint/no-empty-function": "off",
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/ban-ts-ignore": "off",
"tree-shaking/no-side-effects-in-initialization": "error",
"@typescript-eslint/ban-ts-comment": "off"
}
}
"homepage": "https://github.com/mesqueeb/sha-anything#readme",
"bugs": "https://github.com/mesqueeb/sha-anything/issues"
}
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