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

value-object

Package Overview
Dependencies
Maintainers
2
Versions
23
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

value-object - npm Package Compare versions

Comparing version 0.2.0 to 0.2.1

.git/logs/refs/heads/simpler-but-slower-with

2

package.json
{
"name": "value-object",
"version": "0.2.0",
"version": "0.2.1",
"description": "value-object.js - simple value objects",

@@ -5,0 +5,0 @@ "main": "value-object.js",

@@ -1156,2 +1156,12 @@ /* eslint-env mocha */

it('calls the original constructor', () => {
class X extends ValueObject.define({ a: 'string' }) {
constructor({ a }) {
super({ a: a + '!' })
}
}
const x = new X({ a: 'G' }).with({ a: 'H' })
assert.equal(x.a, 'H!')
})
it('returns instances with schemas', () => {

@@ -1158,0 +1168,0 @@ class Yo extends ValueObject.define({ x: 'string' }) {}

@@ -59,31 +59,3 @@ function ValueObject() {

var Constructor = this.constructor
if (!Constructor.With) {
Constructor.With = function With() {}
Constructor.With.prototype = Object.create(Constructor.prototype)
Constructor.With.prototype.constructor = Constructor
}
var instance = new Constructor.With()
for (var propertyName in Constructor.schema.propertyTypes) {
instance[propertyName] = this[propertyName]
}
for (var newPropertyName in newPropertyValues) {
if (Object.prototype.hasOwnProperty.call(newPropertyValues, newPropertyName)) {
var property = Constructor.schema.propertyTypes[newPropertyName]
if (!property) {
new Constructor(extend(this, newPropertyValues))
}
var coercionResult = property.coerce(newPropertyValues[newPropertyName])
if (coercionResult.failure) {
new Constructor(extend(this, newPropertyValues))
} else {
instance[newPropertyName] = coercionResult.value
}
}
}
if (typeof instance._init === 'function') {
instance._init()
}
freeze(instance)
return instance
return new Constructor(extend(this.toPlainObject(), newPropertyValues))
}

@@ -613,15 +585,18 @@ ValueObject.prototype.toJSON = function() {

function extend(extendee, extender) {
var extended = {},
prop
for (prop in extendee) {
if (Object.prototype.hasOwnProperty.call(extendee, prop)) {
extended[prop] = extendee[prop]
var extended = {}
withOwnProperties(extendee, function(prop) {
extended[prop] = extendee[prop]
})
withOwnProperties(extender, function(prop) {
extended[prop] = extender[prop]
})
return extended
}
function withOwnProperties(subject, fn) {
for (var prop in subject) {
if (Object.prototype.hasOwnProperty.call(subject, prop)) {
fn(prop)
}
}
for (prop in extender) {
if (Object.prototype.hasOwnProperty.call(extender, prop)) {
extended[prop] = extender[prop]
}
}
return extended
}

@@ -628,0 +603,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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