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

contextor

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

contextor - npm Package Compare versions

Comparing version 0.3.2 to 0.4.0

6

index.d.ts

@@ -24,2 +24,8 @@ declare namespace contextor {

get: (key: string, defaultValue: any, allowUndefinedContext?: boolean) => any;
/**
* Get an object describing memory usage of the contextor and process
* in order to help debugging potential memory leaks.
* @returns {object} Memory usage description.
*/
getMemoryUsage: () => object;
}

@@ -26,0 +32,0 @@ }

@@ -172,1 +172,40 @@ 'use strict';

};
/**
* Get an object describing memory usage of the contextor and process
* in order to help debugging potential memory leaks.
* @returns {object} Memory usage description.
*/
exports.getMemoryUsage = function getMemoryUsage() {
const resourceTreeSize = Object.getOwnPropertyNames(resourceTree).length;
const contextsSize = Object.getOwnPropertyNames(contexts).length;
const childResourcesSize = Object.getOwnPropertyNames(childResources).length;
const parentResourcesSize = Object.getOwnPropertyNames(parentResources).length;
const destroyedResourcesSize = Object.getOwnPropertyNames(destroyedResources).length;
const memoryUsage = process.memoryUsage();
const processMemory = Object.getOwnPropertyNames(memoryUsage).reduce((map, item) => {
const mbSize = (Math.round((memoryUsage[item] / 1024 / 1024) * 100) / 100).toFixed(2);
// eslint-disable-next-line no-param-reassign
map[item] = `${mbSize} MB`;
return map;
}, {});
return {
processMemory,
sizes: {
resourceTree: resourceTreeSize,
contexts: contextsSize,
childResources: childResourcesSize,
parentResources: parentResourcesSize,
destroyedResources: destroyedResourcesSize
},
contents: {
resourceTree,
contexts,
childResources,
parentResources,
destroyedResources
}
};
};

2

package.json
{
"name": "contextor",
"description": "Package allowing to pass a context along an asynchronous process",
"version": "0.3.2",
"version": "0.4.0",
"author": "Thomas Prelot <tprelot@gmail.com> (https://github.com/Gnucki)",

@@ -6,0 +6,0 @@ "contributors": [],

@@ -65,2 +65,3 @@ # contextor

- [Get a value in the current context](#get-a-value-in-the-current-context)
- [Debugging](#debugging)
- [Testing](#testing)

@@ -99,3 +100,3 @@ - [Contributing](#contributing)

### Get a value in the current context
You can get a value of the current context.
You can get a value of the current context:
```js

@@ -111,2 +112,17 @@ contextor.get('foo');

### Debugging
Contextor create context for async hooks. A bad usage can lead to memory leaks.<br>
Function `getMemoryUsage` has been build to help you investigate that kind of issue:
```js
const { inspect } = require('util');
const memoryUsage = contextor.getMemoryUsage();
console.log(inspect(memoryUsage, {
compact: false,
colors: true,
depth: 6,
}));
```
## Testing

@@ -113,0 +129,0 @@ Many `npm` scripts are available to help testing:

@@ -117,2 +117,23 @@ 'use strict';

});
it('should be debuggable', () => {
const memoryUsage = contextor.getMemoryUsage();
expect(Object.getOwnPropertyNames(memoryUsage)).to.deep.equal(['processMemory', 'sizes', 'contents']);
expect(Object.getOwnPropertyNames(memoryUsage.processMemory)).to.deep.equal(['rss', 'heapTotal', 'heapUsed', 'external']);
expect(Object.getOwnPropertyNames(memoryUsage.sizes)).to.deep.equal([
'resourceTree',
'contexts',
'childResources',
'parentResources',
'destroyedResources'
]);
expect(Object.getOwnPropertyNames(memoryUsage.contents)).to.deep.equal([
'resourceTree',
'contexts',
'childResources',
'parentResources',
'destroyedResources'
]);
});
});
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