New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

mongoose-hidden

Package Overview
Dependencies
Maintainers
1
Versions
42
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mongoose-hidden - npm Package Compare versions

Comparing version

to
1.5.1

4

CHANGELOG.md
# Changelog
1.5.1
- fix: 1.5.0 would add entries from the schema that were not in the original transform (thanks to @proswdev)
1.5.0

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

27

lib/mongoose-hidden.js

@@ -36,6 +36,8 @@ 'use strict';

function testSchema(schema, key, doc, transformed) {
if (typeof schema === 'undefined') { return false }
return schema.options[key] === true ||
typeof schema.options[key] === 'function' &&
schema.options[key](doc, transformed)
if (typeof schema === 'undefined') {
return false
}
return schema.options[key] === true
|| (typeof schema.options[key] === 'function' && schema.options[key](doc, transformed))
}

@@ -74,3 +76,3 @@

* @param {Schema} schema a mongoose schema
* @param {string} key
* @param {string} key object key name
* @param {object} options a set of options

@@ -81,4 +83,4 @@ * @param {string} target the target to test, e.g 'JSON'

function shouldCopyVirtual(schema, key, options, target) {
return schema.pathType(key) === 'virtual' &&
[hide, `hide${target}`].indexOf(options.virtuals[key]) === -1
return schema.pathType(key) === 'virtual'
&& [hide, `hide${target}`].indexOf(options.virtuals[key]) === -1
}

@@ -204,3 +206,5 @@

const partsToValue = function (parts, value) {
if (parts.length === 0) { return value }
if (parts.length === 0) {
return value
}
let obj = {}

@@ -267,4 +271,7 @@ obj[parts[0]] = partsToValue(parts.slice(1), value)

} else {
log('%s: copy "%s"', target, pathname)
setPath(finalTransform, pathname, mpath.get(pathname, transformed))
let value = mpath.get(pathname, transformed)
if (typeof value !== 'undefined') {
log('%s: copy "%s"', target, pathname)
setPath(finalTransform, pathname, value)
}
}

@@ -271,0 +278,0 @@ })

{
"name": "mongoose-hidden",
"version": "1.5.0",
"version": "1.5.1",
"author": "Michael Bøcker-Larsen <mblarsen@gmail.com>",

@@ -5,0 +5,0 @@ "description": "Hides certain model properties when invoking toJSON or toObject.",

@@ -8,5 +8,10 @@ # mongoose-hidden

[![NPM version](http://img.shields.io/npm/v/mongoose-hidden.svg)](https://www.npmjs.com/package/mongoose-hidden/) [![](https://img.shields.io/npm/dm/mongoose-hidden.svg)](https://www.npmjs.com/package/mongoose-hidden/)
[![Donate](https://img.shields.io/badge/%24-donate-red.svg)](https://freewallet.org/id/mblarsen/btc)
A Mongoose schema plugin that hooks into `toJSON()` and `toObject()` to allow hiding of properties you do not want sent client-side, like passwords and other secrets and sensitive information.
<a target='_blank' rel='nofollow' href='https://app.codesponsor.io/link/okYdxs3cWxjapKfPcTg9nLwG/mblarsen/mongoose-hidden'>
<img alt='Sponsor' width='888' height='68' src='https://app.codesponsor.io/embed/okYdxs3cWxjapKfPcTg9nLwG/mblarsen/mongoose-hidden.svg' />
</a>
# Install

@@ -13,0 +18,0 @@