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

definitely

Package Overview
Dependencies
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

definitely - npm Package Compare versions

Comparing version 1.0.5 to 1.0.6

4

definitely.js

@@ -1,2 +0,2 @@

'use strict';Object.defineProperty(exports,'__esModule',{value:true});exports.default=function(obj){return new Proxy(obj,{get:function get(target,key){if(!(key in target)){var err=new Error('attempted to access nonexistent property `'+key+'`');err.stack=err.stack.replace(/(\n\s*at[^\n]*){2}/,'');throw err}return target[key]}})};
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbImRlZmluaXRlbHkuanMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6InNGQUFlLFNBQUEsR0FBRyxTQUFJLElBQUksS0FBSyxDQUFDLEdBQUcsQ0FBRSxDQUNuQyxHQUFHLGNBQUMsTUFBTSxDQUFFLEdBQUcsQ0FBRSxDQUNmLEdBQUksRUFBRSxHQUFHLElBQUksTUFBTSxDQUFBLEFBQUMsQ0FBRSxDQUNwQixJQUFNLEdBQUcsQ0FBRyxJQUFJLEtBQUssOENBQStDLEdBQUcsS0FBSyxDQUFBLEFBQzVFLEdBQUcsQ0FBQyxLQUFLLENBQUcsR0FBRyxDQUFDLEtBQUssQ0FBQyxPQUFPLENBQUMsb0JBQW9CLENBQUUsRUFBRSxDQUFDLENBQUEsQUFDdkQsTUFBTSxHQUFHLENBQUEsQUFDVixBQUNELE9BQU8sTUFBTSxDQUFDLEdBQUcsQ0FBQyxDQUFBLEFBQ25CLENBQ0YsQ0FBQyxDQUFBIiwiZmlsZSI6ImRlZmluaXRlbHkuanMiLCJzb3VyY2VzQ29udGVudCI6WyJleHBvcnQgZGVmYXVsdCBvYmogPT4gbmV3IFByb3h5KG9iaiwge1xuICBnZXQodGFyZ2V0LCBrZXkpIHtcbiAgICBpZiAoIShrZXkgaW4gdGFyZ2V0KSkge1xuICAgICAgY29uc3QgZXJyID0gbmV3IEVycm9yKGBhdHRlbXB0ZWQgdG8gYWNjZXNzIG5vbmV4aXN0ZW50IHByb3BlcnR5IFxcYCR7a2V5fVxcYGApXG4gICAgICBlcnIuc3RhY2sgPSBlcnIuc3RhY2sucmVwbGFjZSgvKFxcblxccyphdFteXFxuXSopezJ9LywgJycpXG4gICAgICB0aHJvdyBlcnJcbiAgICB9XG4gICAgcmV0dXJuIHRhcmdldFtrZXldXG4gIH1cbn0pXG4iXX0=
'use strict';Object.defineProperty(exports,'__esModule',{value:true});exports.default=function(obj){var _ref=arguments.length<=1||arguments[1]===undefined?{}:arguments[1];var _ref$whitelist=_ref.whitelist;var whitelist=_ref$whitelist===undefined?[]:_ref$whitelist;var whiteset={};for(var i=0;i<whitelist.length;i++){whiteset[whitelist[i]]=null}if(typeof Proxy==='undefined')return obj;return new Proxy(obj,{get:function get(target,key){if(!(key in target||key in whiteset)){var err=new Error('attempted to access nonexistent property `'+key+'`');err.stack=err.stack.replace(/(\n\s*at[^\n]*){2}/,'');throw err}return target[key]}})};
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbImRlZmluaXRlbHkuanMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6InNGQUFlLFNBQ2IsR0FBRyxDQUlBLHdEQURDLEVBQUUsc0NBREosU0FBUyxLQUFULFNBQVMsNEJBQUcsRUFBRSxnQkFJaEIsSUFBTSxRQUFRLENBQUcsRUFBRSxDQUFBLEFBQ25CLElBQUssSUFBSSxDQUFDLENBQUcsQ0FBQyxDQUFFLENBQUMsQ0FBRyxTQUFTLENBQUMsTUFBTSxDQUFFLENBQUMsRUFBRSxFQUN2QyxRQUFRLENBQUMsU0FBUyxDQUFDLENBQUMsQ0FBQyxDQUFDLENBQUcsSUFBSSxDQUFBLEFBRS9CLEdBQUksT0FBTyxLQUFLLEdBQUssV0FBVyxDQUM5QixPQU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cyBub25leGlzdGVudCBwcm9wZXJ0eSBcXGAke2tleX1cXGBgKVxuICAgICAgICBlcnIuc3RhY2sgPSBlcnIuc3RhY2sucmVwbGFjZSgvKFxcblxccyphdFteXFxuXSopezJ9LywgJycpXG4gICAgICAgIHRocm93IGVyclxuICAgICAgfVxuICAgICAgcmV0dXJuIHRhcmdldFtrZXldXG4gICAgfVxuICB9KVxufVxuIl19
{
"name": "definitely",
"version": "1.0.5",
"version": "1.0.6",
"description": "Disallow undefined property access in JavaScript",

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

@@ -1,10 +0,25 @@

export default obj => new Proxy(obj, {
get(target, key) {
if (!(key in target)) {
const err = new Error(`attempted to access nonexistent property \`${key}\``)
err.stack = err.stack.replace(/(\n\s*at[^\n]*){2}/, '')
throw err
export default (
obj,
{
whitelist = []
} = {}
) => {
const whiteset = {}
for (let i = 0; i < whitelist.length; i++)
whiteset[whitelist[i]] = null
if (typeof Proxy === 'undefined')
return obj
return new Proxy(obj, {
get(target, key) {
if (!(key in target || key in whiteset)) {
const err = new Error(`attempted to access nonexistent property \`${key}\``)
err.stack = err.stack.replace(/(\n\s*at[^\n]*){2}/, '')
throw err
}
return target[key]
}
return target[key]
}
})
})
}

@@ -5,4 +5,2 @@ import { expect } from 'chai'

global.Proxy = require('harmony-proxy')
describe('definitely', () => {

@@ -16,2 +14,10 @@ const obj = {

before(() => {
global.Proxy = require('harmony-proxy')
})
after(() => {
delete global.Proxy
})
it('allows valid property access', () => {

@@ -33,2 +39,13 @@ for (const key in obj)

})
it('allows invalid properties that are whitelisted', () => {
const key = 'blip'
expect(definitely(obj, { whitelist: [key] })[key]).to.equal(undefined)
})
})
describe('definitely without Proxy', () => {
it('is a noop', () => {
expect(definitely({}).meh).to.equal(undefined)
})
})
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