Skip to content

Commit

Permalink
TOOLS-2046 node-assert-plus needs license and contributor guide
Browse files Browse the repository at this point in the history
  • Loading branch information
jclulow committed Jun 13, 2018
1 parent ed53c78 commit 674ccf9
Show file tree
Hide file tree
Showing 9 changed files with 149 additions and 99 deletions.
1 change: 1 addition & 0 deletions .npmignore
Expand Up @@ -4,3 +4,4 @@ tools
tests
.gitmodules
.npmignore
CONTRIBUTING.md
19 changes: 19 additions & 0 deletions CONTRIBUTING.md
@@ -0,0 +1,19 @@
# Contributing

This repository uses [cr.joyent.us](https://cr.joyent.us) (Gerrit) for new
changes. Anyone can submit changes. To get started, see the [cr.joyent.us user
guide](https://github.com/joyent/joyent-gerrit/blob/master/docs/user/README.md).
This repo does not use GitHub pull requests.

See the [Joyent Engineering
Guidelines](https://github.com/joyent/eng/blob/master/docs/index.md) for general
best practices expected in this repository.

Contributions should be "make prepush" clean. The "prepush" target runs the
"check" target, which requires these separate tools:

* https://github.com/joyent/jsstyle
* https://github.com/joyent/javascriptlint

If you're changing something non-trivial or user-facing, you may want to submit
an issue first.
21 changes: 21 additions & 0 deletions LICENSE
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2018, Joyent, Inc. and assert-plus authors

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
2 changes: 1 addition & 1 deletion Makefile
Expand Up @@ -5,7 +5,7 @@
#

#
# Copyright 2015, Joyent, Inc.
# Copyright (c) 2018, Joyent, Inc. and assert-plus authors
#

NPM = npm
Expand Down
188 changes: 95 additions & 93 deletions README.md
@@ -1,28 +1,33 @@
# assert-plus

This library is a super small wrapper over node's assert module that has two
things: (1) the ability to disable assertions with the environment variable
NODE\_NDEBUG, and (2) some API wrappers for argument testing. Like
`assert.string(myArg, 'myArg')`. As a simple example, most of my code looks
like this:
This library is a thin wrapper over the Node built-in `assert` module,
providing two main enhancements:

1. the ability to disable assertions with the environment variable
`NODE_NDEBUG`

2. some API wrappers for argument testing; e.g., `assert.string(myArg,
'myArg')`. As a simple example:

```javascript
var assert = require('assert-plus');

function fooAccount(options, callback) {
assert.object(options, 'options');
assert.number(options.id, 'options.id');
assert.bool(options.isManager, 'options.isManager');
assert.string(options.name, 'options.name');
assert.arrayOfString(options.email, 'options.email');
assert.func(callback, 'callback');

// Do stuff
callback(null, {});
}
var assert = require('assert-plus');

function fooAccount(options, callback) {
assert.object(options, 'options');
assert.number(options.id, 'options.id');
assert.bool(options.isManager, 'options.isManager');
assert.string(options.name, 'options.name');
assert.arrayOfString(options.email, 'options.email');
assert.func(callback, 'callback');

// Do stuff
callback(null, {});
}
```

# API
See [CONTRIBUTING.md](CONTRIBUTING.md) for details on how to submit changes.

## API

All methods that *aren't* part of node's core assert API are simply assumed to
take an argument, and then a string 'name' that's not a message; `AssertionError`
Expand All @@ -41,23 +46,23 @@ will be thrown if the assertion fails with a message like:
from:

```javascript
function test(foo) {
assert.string(foo, 'foo');
}
function test(foo) {
assert.string(foo, 'foo');
}
```

There you go. You can check that arrays are of a homogeneous type with `Arrayof$Type`:

```javascript
function test(foo) {
assert.arrayOfString(foo, 'foo');
}
function test(foo) {
assert.arrayOfString(foo, 'foo');
}
```

You can assert IFF an argument is not `undefined` (i.e., an optional arg):

```javascript
assert.optionalString(foo, 'foo');
assert.optionalString(foo, 'foo');
```

Lastly, you can opt-out of assertion checking altogether by setting the
Expand All @@ -69,75 +74,76 @@ the `assert` module avoids this behavior.

The complete list of APIs is:

* assert.array
* assert.bool
* assert.buffer
* assert.func
* assert.number
* assert.finite
* assert.object
* assert.string
* assert.stream
* assert.date
* assert.regexp
* assert.uuid
* assert.arrayOfArray
* assert.arrayOfBool
* assert.arrayOfBuffer
* assert.arrayOfFunc
* assert.arrayOfNumber
* assert.arrayOfFinite
* assert.arrayOfObject
* assert.arrayOfString
* assert.arrayOfStream
* assert.arrayOfDate
* assert.arrayOfRegexp
* assert.arrayOfUuid
* assert.optionalArray
* assert.optionalBool
* assert.optionalBuffer
* assert.optionalFunc
* assert.optionalNumber
* assert.optionalFinite
* assert.optionalObject
* assert.optionalString
* assert.optionalStream
* assert.optionalDate
* assert.optionalRegexp
* assert.optionalUuid
* assert.optionalArrayOfArray
* assert.optionalArrayOfBool
* assert.optionalArrayOfBuffer
* assert.optionalArrayOfFunc
* assert.optionalArrayOfNumber
* assert.optionalArrayOfFinite
* assert.optionalArrayOfObject
* assert.optionalArrayOfString
* assert.optionalArrayOfStream
* assert.optionalArrayOfDate
* assert.optionalArrayOfRegexp
* assert.optionalArrayOfUuid
* assert.AssertionError
* assert.fail
* assert.ok
* assert.equal
* assert.notEqual
* assert.deepEqual
* assert.notDeepEqual
* assert.strictEqual
* assert.notStrictEqual
* assert.throws
* assert.doesNotThrow
* assert.ifError

# Installation
* `assert.array`
* `assert.bool`
* `assert.buffer`
* `assert.func`
* `assert.number`
* `assert.finite`
* `assert.object`
* `assert.string`
* `assert.stream`
* `assert.date`
* `assert.regexp`
* `assert.uuid`
* `assert.arrayOfArray`
* `assert.arrayOfBool`
* `assert.arrayOfBuffer`
* `assert.arrayOfFunc`
* `assert.arrayOfNumber`
* `assert.arrayOfFinite`
* `assert.arrayOfObject`
* `assert.arrayOfString`
* `assert.arrayOfStream`
* `assert.arrayOfDate`
* `assert.arrayOfRegexp`
* `assert.arrayOfUuid`
* `assert.optionalArray`
* `assert.optionalBool`
* `assert.optionalBuffer`
* `assert.optionalFunc`
* `assert.optionalNumber`
* `assert.optionalFinite`
* `assert.optionalObject`
* `assert.optionalString`
* `assert.optionalStream`
* `assert.optionalDate`
* `assert.optionalRegexp`
* `assert.optionalUuid`
* `assert.optionalArrayOfArray`
* `assert.optionalArrayOfBool`
* `assert.optionalArrayOfBuffer`
* `assert.optionalArrayOfFunc`
* `assert.optionalArrayOfNumber`
* `assert.optionalArrayOfFinite`
* `assert.optionalArrayOfObject`
* `assert.optionalArrayOfString`
* `assert.optionalArrayOfStream`
* `assert.optionalArrayOfDate`
* `assert.optionalArrayOfRegexp`
* `assert.optionalArrayOfUuid`
* `assert.AssertionError`
* `assert.fail`
* `assert.ok`
* `assert.equal`
* `assert.notEqual`
* `assert.deepEqual`
* `assert.notDeepEqual`
* `assert.strictEqual`
* `assert.notStrictEqual`
* `assert.throws`
* `assert.doesNotThrow`
* `assert.ifError`

## Installation

npm install assert-plus

## License

The MIT License (MIT)
Copyright (c) 2012 Mark Cavage

Copyright (c) 2018, Joyent, Inc. and assert-plus authors

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
Expand All @@ -156,7 +162,3 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

## Bugs

See <https://github.com/mcavage/node-assert-plus/issues>.
5 changes: 3 additions & 2 deletions assert.js
@@ -1,5 +1,6 @@
// Copyright (c) 2012, Mark Cavage. All rights reserved.
// Copyright 2015 Joyent, Inc.
/*
* Copyright (c) 2018, Joyent, Inc. and assert-plus authors
*/

var assert = require('assert');
var Stream = require('stream').Stream;
Expand Down
4 changes: 3 additions & 1 deletion tests/all.test.js
@@ -1,4 +1,6 @@
// Copyright 2015 Joyent, Inc.
/*
* Copyright (c) 2018, Joyent, Inc. and assert-plus authors
*/

var f = require('util').format;
var stream = require('stream');
Expand Down
4 changes: 3 additions & 1 deletion tests/exports.test.js
@@ -1,4 +1,6 @@
// Copyright 2015 Joyent, Inc.
/*
* Copyright (c) 2018, Joyent, Inc. and assert-plus authors
*/

var assert = require('assert');
var test = require('tape');
Expand Down
4 changes: 3 additions & 1 deletion tests/ndebug.test.js
@@ -1,4 +1,6 @@
// Copyright 2015 Joyent, Inc.
/*
* Copyright (c) 2018, Joyent, Inc. and assert-plus authors
*/

var assert = require('assert');
var test = require('tape');
Expand Down

0 comments on commit 674ccf9

Please sign in to comment.