
Product
Socket Now Supports pylock.toml Files
Socket now supports pylock.toml, enabling secure, reproducible Python builds with advanced scanning and full alignment with PEP 751's new standard.
Observe the object property getter, setter or method calls and add custom behavior.
Observe the object property getter, setter or method calls and add custom behavior.
ghostrap can intercept object on any timing (e.g. property value change, assignment, function invocation, etc).
<script src="ghostrap.js"></script>
or
<script src="ghostrap.min.js"></script>
Function object ghostrap will defined in the global scope.
npm install ghostrap
var ghostrap = require('ghostrap');
bower install ghostrap
ghostrap
is a handy constructor.
new
operator is not needed.
In this example, outputs a log when the object message has change.
var myModel = {
id: 1,
message: 'Hello'
};
var ghost = ghostrap(myModel);
ghost.on('change:message', function() {
console.log('message changed!');
});
myModel.message = 'Good evening';
// message changed!
myModel.message = 'Good night';
// message changed!
Add new handler.
The first argument type separates by a colon.
'when:propName'
e.g. 'get:myPropName'
The second argument func is a handler function. On callback arguments are following.
function(target, key, value, args) { ... }
Example:
var myData = {
data: '',
maxLength: 20
};
var ghost = ghostrap(myData);
ghost.on('set:data', function(target, key, value) {
// Truncate data value to the maximum length when set new data.
if (value.length > myData.maxLength) {
value = value.substr(0, myData.maxLength - 3) + '...';
}
return value;
});
myData.data = 'Lorem ipsum dolor sit amet';
console.log(myData.data); // 'Lorem ipsum dolor...'
Add a new handler. Just like on, but handler is called only once.
Remove a handler. If argument type is specified, same types handlers are removed. If argument func is specified, same handlers are removed. If arguments is omitted, all handlers are removed.
Example:
var myModel = {
id: 1,
message: 'Hello'
};
function onMessageChange(target, key, value) {
console.log('message changed!', value);
}
var ghost = ghostrap(myModel);
ghost.on('change:message', onMessageChange);
myModel.message = 'Good evening';
// message changed!
myModel.message = 'Good night';
// message changed!
ghost.off('change:message', onMessageChange);
myModel.message = 'Good morning';
// no console logs.
Clear all handlers and release the target object reference.
MIT
FAQs
Observe the object property getter, setter or method calls and add custom behavior.
The npm package ghostrap receives a total of 0 weekly downloads. As such, ghostrap popularity was classified as not popular.
We found that ghostrap demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket now supports pylock.toml, enabling secure, reproducible Python builds with advanced scanning and full alignment with PEP 751's new standard.
Security News
Research
Socket uncovered two npm packages that register hidden HTTP endpoints to delete all files on command.
Research
Security News
Malicious Ruby gems typosquat Fastlane plugins to steal Telegram bot tokens, messages, and files, exploiting demand after Vietnam’s Telegram ban.