Huge News!Announcing our $40M Series B led by Abstract Ventures.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.3.1 to 1.4.0

2

package.json
{
"name": "lawn",
"version": "1.3.1",
"version": "1.4.0",
"description": "The environment is dangerous. Your lawn is nice. Stay in your lawn.",

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

@@ -224,3 +224,3 @@ # Lawn

lawn.validate(lawnSpec, { WEB_API: 'https://example.com/api' })
//=> { WEB_API: 'https://example.com/api' }
//=> { WEB_API: URL { 'https://example.com/api' } }

@@ -231,2 +231,34 @@ lawn.validate(lawnSpec, { WEB_API: 'mysql://user:pass@host/database' })

#### .requireTrailingSlash
For situations where it is useful to use [`new URL(someComponent,
baseUrl)`][mdnurl] to build up a URL, preventing confusion by requiring a
trailing slash is useful.
For example, this is often unexpected:
```
const baseUrl = new URL('s3://bucket-name/folder-name`)
const newKey = new URL('file', baseUrl)
//=> s3://bucket-name/file (not the expected s3://bucket-name/folder-name/file
```
To reduce issues like this, `.requireTrailingSlash` will validate that the
config value does have a trailing slash to prevent confusion.
```
const lawnSpec = {
S3_STORE: lawn.url.requireTrailingSlash
}
lawn.validate(lawnSpec, { S3_STORE: 's3://bucket/folder/' })
//=> { S3_STORE: URL { 's3://bucket/folder/' } }
lawn.validate(lawnSpec, { S3_STORE: 's3://bucket/folder' })
//=> throws "S3_STORE is invalid: 's3://bucket/folder' must have a trailing slash"
```
[mdnurl]: https://developer.mozilla.org/en-US/docs/Web/API/URL/URL
#### .defaultQuery(name, val)

@@ -242,6 +274,6 @@

lawn.validate(lawnSpec, { MYSQL: 'mysql://user:pass@host/database' })
//=> { MYSQL: 'mysql://user:pass@host/database?connectionLimit=8' }
//=> { MYSQL: URL { 'mysql://user:pass@host/database?connectionLimit=8' } }
lawn.validate(lawnSpec, { MYSQL: 'mysql://user:pass@host/database?connectionLimit=2' })
//=> { MYSQL: 'mysql://user:pass@host/database?connectionLimit=2' }
//=> { MYSQL: URL { 'mysql://user:pass@host/database?connectionLimit=2' } }
```

@@ -260,6 +292,6 @@

lawn.validate(lawnSpec, { MYSQL: 'mysql://user:pass@host/database' })
//=> { MYSQL: 'mysql://user:pass@host/database?multipleStatements=true' }
//=> { MYSQL: URL { 'mysql://user:pass@host/database?multipleStatements=true' } }
lawn.validate(lawnSpec, { MYSQL: 'mysql://user:pass@host/database?multipleStatements=false' })
//=> { MYSQL: 'mysql://user:pass@host/database?multipleStatements=true' }
//=> { MYSQL: URL { 'mysql://user:pass@host/database?multipleStatements=true' } }
```

@@ -35,2 +35,8 @@ 'use strict'

if (this._trailingSlash === 'required') {
if (!/\/$/.test(val.pathname)) {
throw new Error(`must have a trailing slash`)
}
}
super.validate(val)

@@ -60,2 +66,8 @@ }

get requireTrailingSlash () {
this._trailingSlash = 'required'
return this
}
protocol (val) {

@@ -62,0 +74,0 @@ this._protocol = val

@@ -96,2 +96,48 @@ /* global describe it beforeEach */

describe('.requireTrailingSlash', function () {
it('allows a URL with a trailing slash', function () {
const spec = {
URL: lawn.url.requireTrailingSlash
}
const result = lawn.validate(spec, {
URL: 's3://bucket/folder/'
})
assert.equal(result.URL.href, 's3://bucket/folder/')
})
it('rejects a URL without a trailing slash', function () {
const spec = {
URL: lawn.url.requireTrailingSlash
}
assert.throws(() => lawn.validate(spec, {
URL: 's3://bucket/folder'
}), /URL is invalid: 's3:\/\/bucket\/folder' must have a trailing slash/)
})
it('allows a URL with a trailing slash and a query string', function () {
const spec = {
URL: lawn.url.requireTrailingSlash
}
const result = lawn.validate(spec, {
URL: 's3://bucket/folder/?region=us-east-1'
})
assert.equal(result.URL.href, 's3://bucket/folder/?region=us-east-1')
})
it('rejects a URL without a trailing slash and a query string', function () {
const spec = {
URL: lawn.url.requireTrailingSlash
}
assert.throws(() => lawn.validate(spec, {
URL: 's3://bucket/folder?region=us-east-1'
}), /URL is invalid: 's3:\/\/bucket\/folder\?region=us-east-1' must have a trailing slash/)
})
})
describe('.defaultQuery', function () {

@@ -98,0 +144,0 @@ it('sets default values when they are missing', function () {

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