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

lawn

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

lawn - npm Package Compare versions

Comparing version 1.0.1 to 1.1.0

12

index.js

@@ -76,2 +76,6 @@ 'use strict'

get optional () {
return this.props({ optional: true })
},
validate (config, properties) {

@@ -92,2 +96,5 @@ if (!properties) {

if (!originalVal) {
if (cfg.optional === true) {
continue
}
if (cfg.default === undefined) {

@@ -123,3 +130,6 @@ throw new Error(`${key} is missing`)

if (cfg.default !== undefined) {
if (cfg.optional === true) {
const example = cfg.example || ''
strs.push(`# ${key}=${example}`)
} else if (cfg.default !== undefined) {
strs.push(`# ${key}=${cfg.default}`)

@@ -126,0 +136,0 @@ } else {

61

index.test.js

@@ -13,3 +13,3 @@ /* global describe it */

it('converters a number', function () {
const config = {
const spec = {
SECRET: lawn.string,

@@ -19,3 +19,3 @@ PORT: lawn.number

const result = lawn.validate(config, {
const result = lawn.validate(spec, {
SECRET: 's3cr3t',

@@ -32,7 +32,7 @@ PORT: '8000'

it('throws on NaN', function () {
const config = {
const spec = {
PORT: lawn.number
}
assert.throws(() => lawn.validate(config, {
assert.throws(() => lawn.validate(spec, {
PORT: 'WHAT'

@@ -43,7 +43,7 @@ }), /PORT is invalid: 'WHAT' is not a number/)

it('throws on missing key', function () {
const config = {
const spec = {
PORT: lawn.number
}
assert.throws(() => lawn.validate(config, {
assert.throws(() => lawn.validate(spec, {
SECRET: 'WHAT'

@@ -54,7 +54,7 @@ }), /PORT is missing/)

it('uses defaults when missing', function () {
const config = {
const spec = {
PORT: lawn.number.default(8000)
}
const result = lawn.validate(config, {
const result = lawn.validate(spec, {
SECRET: 'WHAT'

@@ -67,3 +67,3 @@ })

it('converts a boolean', function () {
const config = {
const spec = {
BOOL0: lawn.bool,

@@ -79,3 +79,3 @@ BOOL1: lawn.bool,

const result = lawn.validate(config, {
const result = lawn.validate(spec, {
BOOL0: 'yes',

@@ -109,3 +109,3 @@ BOOL1: 'YES',

const config = {
const spec = {
SECRET: lawn.string,

@@ -115,3 +115,3 @@ PORT: lawn.number

const result = lawn.validate(config)
const result = lawn.validate(spec)

@@ -123,2 +123,11 @@ assert.deepEqual(result, {

})
it('allows optional values', function () {
const spec = {
OPTIONAL: lawn.string.optional
}
const result = lawn.validate(spec, {})
assert.notProperty(result, 'OPTIONAL')
})
})

@@ -128,3 +137,3 @@

it('outputs some simple stuff', function () {
const config = {
const spec = {
MYSQL_HOST: lawn.string,

@@ -134,3 +143,3 @@ MYSQL_PORT: lawn.number

const result = lawn.output(config)
const result = lawn.output(spec)

@@ -144,3 +153,3 @@ assert.equal(result, stripIndent(`

it('includes descriptions, if available', function () {
const config = {
const spec = {
MYSQL_HOST: lawn.string.desc('The MySQL host'),

@@ -150,3 +159,3 @@ MYSQL_PORT: lawn.number.desc('The port to run MySQL on')

const result = lawn.output(config)
const result = lawn.output(spec)

@@ -162,7 +171,7 @@ assert.equal(result, stripIndent(`

it('includes examples', function () {
const config = {
const spec = {
MYSQL_HOST: lawn.string.example('127.0.0.1')
}
const result = lawn.output(config)
const result = lawn.output(spec)

@@ -175,7 +184,7 @@ assert.equal(result, stripIndent(`

it('includes commented out defaults', function () {
const config = {
const spec = {
MYSQL_PORT: lawn.number.default(3306)
}
const result = lawn.output(config)
const result = lawn.output(spec)

@@ -186,3 +195,15 @@ assert.equal(result, stripIndent(`

})
it('includes commented out optionals', function () {
const spec = {
MYSQL_PORT: lawn.number.optional.example(3306)
}
const result = lawn.output(spec)
assert.equal(result, stripIndent(`
# MYSQL_PORT=3306
`).trim())
})
})
})
{
"name": "lawn",
"version": "1.0.1",
"version": "1.1.0",
"description": "The environment is dangerous. Your lawn is nice. Stay in your lawn.",

@@ -32,2 +32,2 @@ "main": "index.js",

}
}
}

@@ -176,1 +176,7 @@ # Lawn

environment string.
### .optional
Mark the property as optional. If marked as optional and the property does not
exist, `lawn.validate` will not throw an error, and instead will not include
the property in its return value.
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