Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@egodigital/egoose

Package Overview
Dependencies
Maintainers
2
Versions
134
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@egodigital/egoose - npm Package Compare versions

Comparing version 1.8.1 to 1.9.0

lib/test/cloneObj.d.ts

4

CHANGELOG.md
# Change Log (@egodigital/egoose)
## 1.9.0
* added `cloneObj()`, `importApiErrors()` and `importApiErrorsSync()` functions
## 1.8.0

@@ -4,0 +8,0 @@

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

*/
/// <reference types="node" />
import { Response } from 'express';

@@ -33,2 +34,16 @@ /**

/**
* A possible value for 'importApiErrors()' and 'importApiErrorsSync()' functions.
*
* If STRING: The path to the JSON file to import.
* If BUFFER: The binary content as UTF-8 JSON data.
* If OBJECT or ARRAY: One or more items to import.
*/
export declare type ImportApiErrorsArgument = string | Buffer | ApiErrorWithKey | ApiErrorWithKey[];
/**
* An entry for an API error with a key.
*/
export interface ApiErrorWithKey extends ApiError {
key: string;
}
/**
* An api result.

@@ -57,2 +72,14 @@ */

/**
* Imports the data for 'API_ERRORS' constant.
*
* @param {ImportApiErrorsArgument} errors The items to import.
*/
export declare function importApiErrors(errors: ImportApiErrorsArgument): Promise<void>;
/**
* Imports the data for 'API_ERRORS' constant (sync).
*
* @param {ImportApiErrorsArgument} errors The items to import.
*/
export declare function importApiErrorsSync(errors: ImportApiErrorsArgument): void;
/**
* Sends an API response.

@@ -59,0 +86,0 @@ *

@@ -18,4 +18,15 @@ "use strict";

*/
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
const index_1 = require("../index");
const _ = require("lodash");
const fs_extra_1 = require("fs-extra");
const Path = require("path");
/**

@@ -25,3 +36,58 @@ * Global list of API errors.

exports.API_ERRORS = {};
function applyApiErrors(errors) {
errors = index_1.asArray(errors);
for (const ERR of errors) {
const KEY = index_1.normalizeString(ERR.key);
const CLONED_ERR = index_1.cloneObj(ERR);
delete CLONED_ERR['key'];
exports.API_ERRORS[KEY] = index_1.cloneObj(CLONED_ERR);
}
}
/**
* Imports the data for 'API_ERRORS' constant.
*
* @param {ImportApiErrorsArgument} errors The items to import.
*/
function importApiErrors(errors) {
return __awaiter(this, void 0, void 0, function* () {
let importedErrorList;
if (_.isString(errors)) {
if (!Path.isAbsolute(errors)) {
errors = Path.join(process.cwd(), errors);
}
importedErrorList = JSON.parse((yield fs_extra_1.readFile(errors)).toString('utf8'));
}
else if (Buffer.isBuffer(errors)) {
importedErrorList = JSON.parse(errors.toString('utf8'));
}
else {
importedErrorList = errors;
}
applyApiErrors(importedErrorList);
});
}
exports.importApiErrors = importApiErrors;
/**
* Imports the data for 'API_ERRORS' constant (sync).
*
* @param {ImportApiErrorsArgument} errors The items to import.
*/
function importApiErrorsSync(errors) {
let importedErrorList;
if (_.isString(errors)) {
if (!Path.isAbsolute(errors)) {
errors = Path.join(process.cwd(), errors);
}
importedErrorList = JSON.parse(fs_extra_1.readFileSync(errors).toString('utf8'));
}
else if (Buffer.isBuffer(errors)) {
importedErrorList = JSON.parse(errors.toString('utf8'));
}
else {
importedErrorList = errors;
}
applyApiErrors(importedErrorList);
}
exports.importApiErrorsSync = importApiErrorsSync;
/**
* Sends an API response.

@@ -28,0 +94,0 @@ *

@@ -36,2 +36,10 @@ /**

/**
* Clones an object / value.
*
* @param {T} obj The value to clone.
*
* @return {T} The cloned value.
*/
export declare function cloneObj<T>(obj: T): T;
/**
* Compare to values for sorting.

@@ -38,0 +46,0 @@ *

@@ -45,2 +45,16 @@ "use strict";

/**
* Clones an object / value.
*
* @param {T} obj The value to clone.
*
* @return {T} The cloned value.
*/
function cloneObj(obj) {
if (!obj) {
return obj;
}
return JSON.parse(JSON.stringify(obj));
}
exports.cloneObj = cloneObj;
/**
* Compare to values for sorting.

@@ -47,0 +61,0 @@ *

{
"name": "@egodigital/egoose",
"version": "1.8.1",
"version": "1.9.0",
"description": "Helper classes and functions for Node.js 8 or later.",

@@ -11,2 +11,4 @@ "main": "lib/index.js",

"scripts": {
"build": "(rm -r ./lib || true) && (\"./node_modules/.bin/tsc\" && \"./node_modules/.bin/tsc\" -d)",
"doc": "(rm -r ./doc || true) && (\"./node_modules/.bin/typedoc\" --out ./doc ./src)",
"test": "./node_modules/.bin/mocha ./lib/test/**/*.js"

@@ -46,2 +48,3 @@ },

"@types/express": "^4.16.0",
"@types/fs-extra": "^5.0.4",
"@types/is-stream": "^1.1.0",

@@ -57,2 +60,3 @@ "@types/lodash": "^4.14.112",

"express": "^4.16.3",
"fs-extra": "^7.0.0",
"header-case-normalizer": "^1.0.3",

@@ -59,0 +63,0 @@ "is-stream": "^1.1.0",

5

README.md

@@ -32,4 +32,3 @@ # egoose

```bash
rm -rf ./lib
tsc && tsc -d
npm run build
```

@@ -44,3 +43,3 @@

```bash
./node_modules/.bin/typedoc --out ./doc ./src/**
npm run doc
```

@@ -47,0 +46,0 @@

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