metautil
Advanced tools
Comparing version 3.5.10 to 3.5.11
@@ -5,2 +5,7 @@ # Changelog | ||
## [3.5.11][] - 2021-09-09 | ||
- Add `namespaceByPath(namespace: object, path: string): object | null` | ||
- Add `md5(fileName: string): Promise<string>` | ||
## [3.5.10][] - 2021-08-25 | ||
@@ -97,3 +102,4 @@ | ||
[unreleased]: https://github.com/metarhia/metautil/compare/v3.5.10....HEAD | ||
[unreleased]: https://github.com/metarhia/metautil/compare/v3.5.11....HEAD | ||
[3.5.11]: https://github.com/metarhia/metautil/compare/v3.5.10...v3.5.11 | ||
[3.5.10]: https://github.com/metarhia/metautil/compare/v3.5.9...v3.5.10 | ||
@@ -100,0 +106,0 @@ [3.5.9]: https://github.com/metarhia/metautil/compare/v3.5.8...v3.5.9 |
'use strict'; | ||
const crypto = require('crypto'); | ||
const fs = require('fs'); | ||
@@ -119,2 +120,13 @@ const UINT32_MAX = 0xffffffff; | ||
const md5 = (filePath) => | ||
new Promise((resolve, reject) => { | ||
const hash = crypto.createHash('md5'); | ||
const file = fs.createReadStream(filePath); | ||
file.on('error', reject); | ||
hash.once('readable', () => { | ||
resolve(hash.read().toString('hex')); | ||
}); | ||
file.pipe(hash); | ||
}); | ||
module.exports = { | ||
@@ -128,2 +140,3 @@ cryptoRandom, | ||
validatePassword, | ||
md5, | ||
}; |
@@ -125,3 +125,3 @@ 'use strict'; | ||
const size = bytes / 1000 ** exp; | ||
const short = Math.round(size, 2); | ||
const short = Math.round(size); | ||
const unit = exp === 0 ? '' : ' ' + SIZE_UNITS[exp - 1]; | ||
@@ -150,2 +150,10 @@ return short.toString() + unit; | ||
const namespaceByPath = (namespace, path) => { | ||
const [key, rest] = split(path, '.'); | ||
const step = namespace[key]; | ||
if (!step) return null; | ||
if (rest === '') return step; | ||
return namespaceByPath(step, rest); | ||
}; | ||
const ORDINAL = ['st', 'nd', 'rd', 'th']; | ||
@@ -330,2 +338,3 @@ | ||
sizeToBytes, | ||
namespaceByPath, | ||
parseEvery, | ||
@@ -332,0 +341,0 @@ nextEvent, |
@@ -6,2 +6,3 @@ import { EventEmitter } from 'events'; | ||
export function crcToken(secret: string, key: string): string; | ||
export function md5(fileName: string): Promise<string>; | ||
@@ -39,2 +40,3 @@ export function generateToken( | ||
export function sizeToBytes(size: string): number; | ||
export function namespaceByPath(namespace: object, path: string): object | null; | ||
@@ -41,0 +43,0 @@ type Every = { |
{ | ||
"name": "metautil", | ||
"version": "3.5.10", | ||
"version": "3.5.11", | ||
"author": "Timur Shemsedinov <timur.shemsedinov@gmail.com>", | ||
@@ -41,3 +41,3 @@ "license": "MIT", | ||
"devDependencies": { | ||
"@types/node": "^16.6.2", | ||
"@types/node": "^16.9.0", | ||
"eslint": "^7.32.0", | ||
@@ -47,7 +47,7 @@ "eslint-config-metarhia": "^7.0.1", | ||
"eslint-plugin-import": "^2.24.0", | ||
"eslint-plugin-prettier": "^3.4.0", | ||
"eslint-plugin-prettier": "^4.0.0", | ||
"metatests": "^0.7.2", | ||
"prettier": "^2.3.2", | ||
"typescript": "^4.3.5" | ||
"prettier": "^2.4.0", | ||
"typescript": "^4.4.2" | ||
} | ||
} |
@@ -34,2 +34,3 @@ # Metarhia utilities | ||
- `sizeToBytes(size: string): number` | ||
- `namespaceByPath(namespace: object, path: string): object | null` | ||
- `makePrivate(instance: object): object` | ||
@@ -51,2 +52,3 @@ - `protect(allowMixins: Array<string>, ...namespaces: Array<object>): void` | ||
- `validatePassword(password: string, serHash: string): Promise<boolean>` | ||
- `md5(fileName: string): Promise<string>` | ||
@@ -53,0 +55,0 @@ ## Async abstractions |
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
24982
556
62
1