Compare commits
14 Commits
Author | SHA1 | Date | |
---|---|---|---|
e3eca5528d | |||
d43f568795 | |||
85f2cc4745 | |||
143eef8781 | |||
bb7bee3b42 | |||
50197d4634 | |||
2e7a61541f | |||
5a6ae2f083 | |||
bf1b89a95a | |||
3e2b300cdb | |||
d865e3b874 | |||
13f1f854ce | |||
34586b5fec | |||
edb13cbdcf |
4
.gitignore
vendored
4
.gitignore
vendored
@ -15,8 +15,6 @@ node_modules/
|
||||
|
||||
# builds
|
||||
dist/
|
||||
dist_web/
|
||||
dist_serve/
|
||||
dist_ts_web/
|
||||
dist_*/
|
||||
|
||||
# custom
|
@ -12,6 +12,9 @@ stages:
|
||||
- release
|
||||
- metadata
|
||||
|
||||
before_script:
|
||||
- npm install -g @shipzone/npmci
|
||||
|
||||
# ====================
|
||||
# security stage
|
||||
# ====================
|
||||
@ -19,22 +22,36 @@ mirror:
|
||||
stage: security
|
||||
script:
|
||||
- npmci git mirror
|
||||
only:
|
||||
- tags
|
||||
tags:
|
||||
- lossless
|
||||
- docker
|
||||
- notpriv
|
||||
|
||||
snyk:
|
||||
image: registry.gitlab.com/hosttoday/ht-docker-node:snyk
|
||||
auditProductionDependencies:
|
||||
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||
stage: security
|
||||
script:
|
||||
- npmci npm prepare
|
||||
- npmci command npm install --production --ignore-scripts
|
||||
- npmci command npm config set registry https://registry.npmjs.org
|
||||
- npmci command npm audit --audit-level=high --only=prod --production
|
||||
tags:
|
||||
- docker
|
||||
allow_failure: true
|
||||
|
||||
auditDevDependencies:
|
||||
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||
stage: security
|
||||
script:
|
||||
- npmci npm prepare
|
||||
- npmci command npm install --ignore-scripts
|
||||
- npmci command snyk test
|
||||
- npmci command npm config set registry https://registry.npmjs.org
|
||||
- npmci command npm audit --audit-level=high --only=dev
|
||||
tags:
|
||||
- lossless
|
||||
- docker
|
||||
- notpriv
|
||||
allow_failure: true
|
||||
|
||||
# ====================
|
||||
# test stage
|
||||
@ -49,9 +66,7 @@ testStable:
|
||||
- npmci npm test
|
||||
coverage: /\d+.?\d+?\%\s*coverage/
|
||||
tags:
|
||||
- lossless
|
||||
- docker
|
||||
- priv
|
||||
|
||||
testBuild:
|
||||
stage: test
|
||||
@ -62,9 +77,7 @@ testBuild:
|
||||
- npmci command npm run build
|
||||
coverage: /\d+.?\d+?\%\s*coverage/
|
||||
tags:
|
||||
- lossless
|
||||
- docker
|
||||
- notpriv
|
||||
|
||||
release:
|
||||
stage: release
|
||||
@ -84,11 +97,12 @@ release:
|
||||
codequality:
|
||||
stage: metadata
|
||||
allow_failure: true
|
||||
only:
|
||||
- tags
|
||||
script:
|
||||
- npmci command npm install -g tslint typescript
|
||||
- npmci command npm install -g typescript
|
||||
- npmci npm prepare
|
||||
- npmci npm install
|
||||
- npmci command "tslint -c tslint.json ./ts/**/*.ts"
|
||||
tags:
|
||||
- lossless
|
||||
- docker
|
||||
@ -108,11 +122,10 @@ trigger:
|
||||
pages:
|
||||
stage: metadata
|
||||
script:
|
||||
- npmci node install lts
|
||||
- npmci command npm install -g @gitzone/tsdoc
|
||||
- npmci node install stable
|
||||
- npmci npm prepare
|
||||
- npmci npm install
|
||||
- npmci command tsdoc
|
||||
- npmci command npm run buildDocs
|
||||
tags:
|
||||
- lossless
|
||||
- docker
|
||||
|
4
.snyk
4
.snyk
@ -1,4 +0,0 @@
|
||||
# Snyk (https://snyk.io) policy file, patches or ignores known vulnerabilities.
|
||||
version: v1.13.3
|
||||
ignore: {}
|
||||
patch: {}
|
11
.vscode/launch.json
vendored
Normal file
11
.vscode/launch.json
vendored
Normal file
@ -0,0 +1,11 @@
|
||||
{
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"command": "npm test",
|
||||
"name": "Run npm test",
|
||||
"request": "launch",
|
||||
"type": "node-terminal"
|
||||
}
|
||||
]
|
||||
}
|
26
.vscode/settings.json
vendored
Normal file
26
.vscode/settings.json
vendored
Normal file
@ -0,0 +1,26 @@
|
||||
{
|
||||
"json.schemas": [
|
||||
{
|
||||
"fileMatch": ["/npmextra.json"],
|
||||
"schema": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"npmci": {
|
||||
"type": "object",
|
||||
"description": "settings for npmci"
|
||||
},
|
||||
"gitzone": {
|
||||
"type": "object",
|
||||
"description": "settings for gitzone",
|
||||
"properties": {
|
||||
"projectType": {
|
||||
"type": "string",
|
||||
"enum": ["website", "element", "service", "npm", "wcc"]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
@ -1,16 +1,16 @@
|
||||
{
|
||||
"gitzone": {
|
||||
"projectType": "npm",
|
||||
"module": {
|
||||
"githost": "gitlab.com",
|
||||
"gitscope": "pushrocks",
|
||||
"gitrepo": "smarthash",
|
||||
"shortDescription": "simplifies access to node hash functions",
|
||||
"description": "simplifies access to node hash functions",
|
||||
"npmPackagename": "@pushrocks/smarthash",
|
||||
"license": "MIT"
|
||||
}
|
||||
},
|
||||
"npmci": {
|
||||
"npmAccessLevel": "public",
|
||||
"npmRegistryUrl": "verdaccio.lossless.one"
|
||||
"npmAccessLevel": "public"
|
||||
}
|
||||
}
|
11096
package-lock.json
generated
11096
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
48
package.json
48
package.json
@ -1,17 +1,14 @@
|
||||
{
|
||||
"name": "@pushrocks/smarthash",
|
||||
"version": "2.1.5",
|
||||
"version": "3.0.1",
|
||||
"private": false,
|
||||
"description": "simplified access to node hash functions",
|
||||
"main": "dist/index.js",
|
||||
"typings": "dist/index.d.ts",
|
||||
"main": "dist_ts/index.js",
|
||||
"typings": "dist_ts/index.d.ts",
|
||||
"scripts": {
|
||||
"test": "(tstest test/)",
|
||||
"build": "(tsbuild)"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/pushrocks/nodehash.git"
|
||||
"test": "(tstest test/ --web)",
|
||||
"build": "(tsbuild --web)",
|
||||
"buildDocs": "tsdoc"
|
||||
},
|
||||
"keywords": [
|
||||
"pushrocks",
|
||||
@ -24,34 +21,33 @@
|
||||
],
|
||||
"author": "Lossless GmbH",
|
||||
"license": "MIT",
|
||||
"bugs": {
|
||||
"url": "https://github.com/pushrocks/nodehash/issues"
|
||||
},
|
||||
"homepage": "https://github.com/pushrocks/nodehash#readme",
|
||||
"devDependencies": {
|
||||
"@gitzone/tsbuild": "^2.1.17",
|
||||
"@gitzone/tsrun": "^1.2.8",
|
||||
"@gitzone/tstest": "^1.0.28",
|
||||
"@pushrocks/tapbundle": "^3.2.0",
|
||||
"@types/node": "^12.12.17",
|
||||
"tslint": "^5.20.1",
|
||||
"tslint-config-prettier": "^1.18.0"
|
||||
"@gitzone/tsbuild": "^2.1.63",
|
||||
"@gitzone/tsrun": "^1.2.37",
|
||||
"@gitzone/tstest": "^1.0.71",
|
||||
"@pushrocks/tapbundle": "^5.0.3",
|
||||
"@types/node": "^18.0.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"@pushrocks/smartjson": "^3.0.9",
|
||||
"@pushrocks/smartpromise": "^3.0.6",
|
||||
"@types/through2": "^2.0.34",
|
||||
"through2": "^3.0.1"
|
||||
"@pushrocks/smartjson": "^5.0.1",
|
||||
"@pushrocks/smartpromise": "^3.1.7",
|
||||
"@types/through2": "^2.0.36",
|
||||
"through2": "^4.0.2"
|
||||
},
|
||||
"files": [
|
||||
"ts/**/*",
|
||||
"ts_web/**/*",
|
||||
"dist/**/*",
|
||||
"dist_web/**/*",
|
||||
"dist_*/**/*",
|
||||
"dist_ts/**/*",
|
||||
"dist_ts_web/**/*",
|
||||
"assets/**/*",
|
||||
"cli.js",
|
||||
"npmextra.json",
|
||||
"readme.md"
|
||||
]
|
||||
],
|
||||
"browserslist": [
|
||||
"last 1 chrome versions"
|
||||
],
|
||||
"type": "module"
|
||||
}
|
||||
|
21
readme.md
21
readme.md
@ -8,13 +8,20 @@ simplifies access to node hash functions
|
||||
* [docs (typedoc)](https://pushrocks.gitlab.io/smarthash/)
|
||||
|
||||
## Status for master
|
||||
[](https://gitlab.com/pushrocks/smarthash/commits/master)
|
||||
[](https://gitlab.com/pushrocks/smarthash/commits/master)
|
||||
[](https://www.npmjs.com/package/@pushrocks/smarthash)
|
||||
[](https://snyk.io/test/npm/@pushrocks/smarthash)
|
||||
[](https://nodejs.org/dist/latest-v10.x/docs/api/)
|
||||
[](https://nodejs.org/dist/latest-v10.x/docs/api/)
|
||||
[](https://prettier.io/)
|
||||
|
||||
Status Category | Status Badge
|
||||
-- | --
|
||||
GitLab Pipelines | [](https://lossless.cloud)
|
||||
GitLab Pipline Test Coverage | [](https://lossless.cloud)
|
||||
npm | [](https://lossless.cloud)
|
||||
Snyk | [](https://lossless.cloud)
|
||||
TypeScript Support | [](https://lossless.cloud)
|
||||
node Support | [](https://nodejs.org/dist/latest-v10.x/docs/api/)
|
||||
Code Style | [](https://lossless.cloud)
|
||||
PackagePhobia (total standalone install weight) | [](https://lossless.cloud)
|
||||
PackagePhobia (package size on registry) | [](https://lossless.cloud)
|
||||
BundlePhobia (total size when bundled) | [](https://lossless.cloud)
|
||||
Platform support | [](https://lossless.cloud) [](https://lossless.cloud)
|
||||
|
||||
## Usage
|
||||
|
||||
|
28
test/test.ts
28
test/test.ts
@ -1,55 +1,55 @@
|
||||
import { tap, expect } from '@pushrocks/tapbundle';
|
||||
import fs = require('fs');
|
||||
import * as fs from 'fs';
|
||||
|
||||
import * as smarthash from '../ts/index';
|
||||
import * as smarthash from '../ts/index.js';
|
||||
|
||||
tap.test('sha256FromStringSync should convert a String to sha256 hash synchronously', async () => {
|
||||
const testHash = smarthash.sha256FromStringSync('test');
|
||||
const testHash2 = smarthash.sha256FromStringSync('testString');
|
||||
const testHash3 = smarthash.sha256FromStringSync('test');
|
||||
expect(testHash).to.equal(testHash3);
|
||||
expect(testHash).to.not.equal('test');
|
||||
expect(testHash).toEqual(testHash3);
|
||||
expect(testHash).not.toEqual('test');
|
||||
});
|
||||
|
||||
tap.test('sha256fromStringSync should convert a String to sha256 hash synchronously', async () => {
|
||||
const resultString = await smarthash.sha256FromString('test');
|
||||
const compareString = smarthash.sha256FromStringSync('test');
|
||||
expect(resultString).to.equal(compareString);
|
||||
expect(resultString).toEqual(compareString);
|
||||
});
|
||||
|
||||
tap.test('sha256fromStream should convert a Stream to sha256', async tools => {
|
||||
tap.test('sha256fromStream should convert a Stream to sha256', async (tools) => {
|
||||
const readStream = fs.createReadStream('./test/testImageForHash.jpg');
|
||||
const resultString: string = await smarthash.sha256FromStream(readStream);
|
||||
expect(resultString).to.equal('45b80413ed93acb495691186ce61850449439f9183352b9bff96d5533fa1046c');
|
||||
expect(resultString).toEqual('45b80413ed93acb495691186ce61850449439f9183352b9bff96d5533fa1046c');
|
||||
});
|
||||
|
||||
tap.test('sha256fromFile should convert a Stream to sha256', async () => {
|
||||
const resultString = await smarthash.sha256FromFile('./test/testImageForHash.jpg');
|
||||
expect(resultString).to.equal('45b80413ed93acb495691186ce61850449439f9183352b9bff96d5533fa1046c');
|
||||
expect(resultString).toEqual('45b80413ed93acb495691186ce61850449439f9183352b9bff96d5533fa1046c');
|
||||
});
|
||||
|
||||
tap.test('should produce reproducible hash from Object', async () => {
|
||||
const hash1 = await smarthash.sha265FromObject({
|
||||
hithere: 1,
|
||||
wow: 'two'
|
||||
wow: 'two',
|
||||
});
|
||||
|
||||
const hash2 = await smarthash.sha265FromObject({
|
||||
wow: 'two',
|
||||
hithere: 1
|
||||
hithere: 1,
|
||||
});
|
||||
|
||||
const hash3 = await smarthash.sha265FromObject({
|
||||
wow: 'twoe',
|
||||
hithere: 1
|
||||
hithere: 1,
|
||||
});
|
||||
expect(hash1).to.equal(hash2);
|
||||
expect(hash1).to.not.equal(hash3);
|
||||
expect(hash1).toEqual(hash2);
|
||||
expect(hash1).not.toEqual(hash3);
|
||||
});
|
||||
|
||||
tap.test('should create md5hash from string', async () => {
|
||||
const md5Hash = await smarthash.md5FromString('hellothere');
|
||||
expect(md5Hash).to.equal('c6f7c372641dd25e0fddf0215375561f');
|
||||
expect(md5Hash).toEqual('c6f7c372641dd25e0fddf0215375561f');
|
||||
});
|
||||
|
||||
tap.start();
|
||||
|
8
ts/00_commitinfo_data.ts
Normal file
8
ts/00_commitinfo_data.ts
Normal file
@ -0,0 +1,8 @@
|
||||
/**
|
||||
* autocreated commitinfo by @pushrocks/commitinfo
|
||||
*/
|
||||
export const commitinfo = {
|
||||
name: '@pushrocks/smarthash',
|
||||
version: '3.0.1',
|
||||
description: 'simplified access to node hash functions'
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
import * as plugins from './nodehash.plugins';
|
||||
import * as plugins from './nodehash.plugins.js';
|
||||
|
||||
export * from './nodehash.sha256';
|
||||
export * from './nodehash.md5';
|
||||
export * from './nodehash.sha256.js';
|
||||
export * from './nodehash.md5.js';
|
||||
|
@ -1,12 +1,12 @@
|
||||
import * as plugins from './nodehash.plugins';
|
||||
import * as plugins from './nodehash.plugins.js';
|
||||
|
||||
export const hashStreamPipeStop = resolveFuntion => {
|
||||
const forEach = (chunk: Buffer, enc, cb) => {
|
||||
resolveFuntion(chunk.toString('utf8'));
|
||||
export const hashStreamPipeStop = (resolveFunctionArg: (inputArg: string) => any) => {
|
||||
const forEach = (chunk: Buffer, enc: any, cb: any) => {
|
||||
resolveFunctionArg(chunk.toString('utf8'));
|
||||
cb(null, chunk);
|
||||
};
|
||||
|
||||
const atEnd = cb => {
|
||||
const atEnd = (cb: any) => {
|
||||
cb();
|
||||
};
|
||||
|
||||
|
@ -1,8 +1,5 @@
|
||||
import * as plugins from './nodehash.plugins';
|
||||
import * as plugins from './nodehash.plugins.js';
|
||||
|
||||
export const md5FromString = async (stringToHash: string) => {
|
||||
return plugins.crypto
|
||||
.createHash('md5')
|
||||
.update(stringToHash)
|
||||
.digest('hex');
|
||||
return plugins.crypto.createHash('md5').update(stringToHash).digest('hex');
|
||||
};
|
||||
|
@ -1,5 +1,5 @@
|
||||
import * as plugins from './nodehash.plugins';
|
||||
import * as helpers from './nodehash.helpers';
|
||||
import * as plugins from './nodehash.plugins.js';
|
||||
import * as helpers from './nodehash.helpers.js';
|
||||
|
||||
/**
|
||||
* creates sha256 Hash from Stream
|
||||
@ -26,7 +26,7 @@ export const sha256FromFile = async (filePath: string): Promise<string> => {
|
||||
/**
|
||||
* Computes sha256 Hash from String synchronously
|
||||
*/
|
||||
export let sha256FromStringSync = (stringArg): string => {
|
||||
export const sha256FromStringSync = (stringArg: string): string => {
|
||||
const hash = plugins.crypto.createHash('sha256');
|
||||
hash.update(stringArg);
|
||||
return hash.digest('hex');
|
||||
@ -42,11 +42,21 @@ export const sha256FromString = async (stringArg: string): Promise<string> => {
|
||||
return hashResult;
|
||||
};
|
||||
|
||||
/**
|
||||
* Computes sha256 Hash from String
|
||||
*/
|
||||
export const sha256FromBuffer = async (bufferArg: Buffer): Promise<string> => {
|
||||
const hash = plugins.crypto.createHash('sha256');
|
||||
hash.update(bufferArg);
|
||||
const hashResult = hash.digest('hex');
|
||||
return hashResult;
|
||||
};
|
||||
|
||||
/**
|
||||
* computes sha265 Hash from Object
|
||||
*/
|
||||
export const sha265FromObject = async (objectArg: any): Promise<string> => {
|
||||
const stringifiedObject = plugins.smartjson.Smartjson.stringify(objectArg, {});
|
||||
const stringifiedObject = plugins.smartjson.stringify(objectArg);
|
||||
const hashResult = await sha256FromString(stringifiedObject);
|
||||
return hashResult;
|
||||
};
|
||||
|
17
tslint.json
17
tslint.json
@ -1,17 +0,0 @@
|
||||
{
|
||||
"extends": ["tslint:latest", "tslint-config-prettier"],
|
||||
"rules": {
|
||||
"semicolon": [true, "always"],
|
||||
"no-console": false,
|
||||
"ordered-imports": false,
|
||||
"object-literal-sort-keys": false,
|
||||
"member-ordering": {
|
||||
"options":{
|
||||
"order": [
|
||||
"static-method"
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"defaultSeverity": "warning"
|
||||
}
|
Reference in New Issue
Block a user