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

util-type-funcs

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

util-type-funcs - npm Package Compare versions

Comparing version 0.2.2 to 0.2.4

88

index.js

@@ -24,16 +24,2 @@ 'use strict';

module.exports.extend = extend;
function extend(other, add) {
if (!add || !isObjectLike(add)) return other;
let keys = Object.keys(add);
let i = keys.length;
while (i--) {
const key = keys[i];
other[key] = add[key];
}
return other;
}
/** @deprecated */

@@ -171,2 +157,73 @@ module.exports.hasOwnProperty = hasOwnProperty;

module.exports.forAllPrototypes = forAllPrototypes;
/**
* @this {constructor} constructor
* @param callback function(prototype) called for each prototype in the chain
*/
function forAllPrototypes(callback) {
if (this) {
let prototype = this.prototype;
while (prototype) {
callback(prototype);
prototype = Object.getPrototypeOf(prototype);
}
}
}
module.exports.callPrototypeChainDown = callPrototypeChainDown;
/**
* Call method in prototype chain in down chain order
*
* @this {Model} instance model
* @param methodName
*/
function callPrototypeChainDown(methodName) {
const methods = [];
forAllPrototypes.call(this.constructor, prototype => {
if (prototype.hasOwnProperty(methodName)) {
methods.push(prototype[methodName]);
}
});
const args = Array.prototype.slice.call(arguments, 1);
let i = methods.length;
while (i--) {
const method = methods[i];
method.apply(this, args);
}
}
module.exports.callPrototypeChainUp = callPrototypeChainUp;
/**
* Call method in prototype chain in up chain order
*
* @this {Model} instance model
* @param methodName
*/
function callPrototypeChainUp(methodName) {
const args = Array.prototype.slice.call(arguments, 1);
forAllPrototypes.call(this.constructor, prototype => {
if (prototype.hasOwnProperty(methodName)) {
prototype[methodName].apply(this, args);
}
});
}
module.exports.extend = extend;
function extend(other, add) {
if (!add || !isObjectLike(add)) return other;
let keys = Object.keys(add);
let i = keys.length;
while (i--) {
const key = keys[i];
other[key] = add[key];
}
return other;
}
/*

@@ -196,2 +253,5 @@ const utilTypes = require('util-type-funcs');

const firstValid = utilTypes.firstValid;
const forAllPrototypes = utilTypes.forAllPrototypes;
const callPrototypeChainDown = utilTypes.callPrototypeChainDown;
const callPrototypeChainUp = utilTypes.callPrototypeChainUp;
*/

2

package.json
{
"name": "util-type-funcs",
"version": "0.2.2",
"version": "0.2.4",
"description": "type test and conversion related functions",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -5,2 +5,3 @@ # Version History

- [0.2.4](#024)
- [0.2.2](#022)

@@ -12,2 +13,14 @@ - [0.2.1](#021)

## 0.2.4
* Add: prototype chain functions:
* `forAllPrototypes.call(constructor, callback)` - calls callback(prototype) for all
prototypes in the prototype chain, including constructor.prototype
* `callPrototypeChainDown.call(instance, methodName,...args)` - calls methodName with args in
all prototypes in the chain which have the method in own properties with `this` set to
`instance`, calls are made in reverse prototype chain order
* `callPrototypeChainUp.call(instance, methodName,...args)` - calls methodName with args in
all prototypes in the chain which have the method in own properties with `this` set to
`instance`, calls are made in prototype chain order
## 0.2.2

@@ -14,0 +27,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