Skip to content

Commit 3e426e3

Browse files
committed
v3 updates
1 parent 9a702ae commit 3e426e3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+718
-15712
lines changed

.eslintrc

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"extends": ["standard", "prettier", "prettier/standard"],
3+
"plugins": ["standard", "prettier"]
4+
}

.github/workflows/test.yml

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
name: Test
2+
3+
on:
4+
push:
5+
pull_request:
6+
branches:
7+
- master
8+
9+
jobs:
10+
release:
11+
runs-on: ubuntu-latest
12+
container: mongo:latest
13+
steps:
14+
- uses: actions/checkout@v2
15+
- uses: actions/setup-node@v1
16+
with:
17+
node-version: 16
18+
- run: npm install
19+
- run: npm run format:ci
20+
- run: npm test

.husky/pre-commit

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/bin/sh
2+
. "$(dirname "$0")/_/husky.sh"
3+
4+
npm run format
5+
npm test

.npmrc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
package-lock=false

.prettierignore

-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,2 @@
1-
package.json
2-
package-lock.json
31
node_modules/
42
docs/

.prettierrc

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"singleQuote": true
3+
}

.travis.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
language: node_js
22
node_js:
3-
- "6.11.0"
3+
- '6.11.0'
44
before_script:
55
- npm install
66
script: npm test

LICENSE

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
(The MIT License)
22

3-
Copyright (c) 2015 Lee Powell <lee@leepowell.co.uk>
3+
Copyright (c) 2015 Lee Powell <lee@leepowell.dev>
44

55
Permission is hereby granted, free of charge, to any person obtaining
66
a copy of this software and associated documentation files (the

README.md

+21-21
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ More details on 0.2.2 can be found [here](https://github.com/leepowellcouk/mongo
2929
## Usage
3030

3131
```javascript
32-
var mongoose = require('mongoose')
33-
var validate = require('mongoose-validator')
32+
var mongoose = require('mongoose');
33+
var validate = require('mongoose-validator');
3434

3535
var nameValidator = [
3636
validate({
@@ -43,11 +43,11 @@ var nameValidator = [
4343
passIfEmpty: true,
4444
message: 'Name should contain alpha-numeric characters only',
4545
}),
46-
]
46+
];
4747

4848
var Schema = new mongoose.Schema({
4949
name: { type: String, required: true, validate: nameValidator },
50-
})
50+
});
5151
```
5252

5353
Error objects are returned as normal via Mongoose.
@@ -96,7 +96,7 @@ var alphaValidator = validate({
9696
passIfEmpty: true,
9797
message: 'Name should contain alpha-numeric characters only',
9898
httpStatus: 400,
99-
})
99+
});
100100
```
101101

102102
In this example the error object returned by mongoose will have its 'properties' extended with httpStatus should validation fail. More details can be found about this here: [http://thecodebarbarian.com/2014/12/19/mongoose-397](http://thecodebarbarian.com/2014/12/19/mongoose-397)
@@ -107,15 +107,15 @@ By default Mongoose runs all validators synchronously, if you need to perform as
107107

108108
```javascript
109109
validate({
110-
validator: function(val) {
110+
validator: function (val) {
111111
return new Promise((resolve, reject) => {
112112
setTimeout(() => {
113-
resolve(val > 0)
114-
}, 500)
115-
})
113+
resolve(val > 0);
114+
}, 500);
115+
});
116116
},
117117
message: 'Count must be a positive number.',
118-
})
118+
});
119119
```
120120

121121
## Custom validators
@@ -126,34 +126,34 @@ Custom validators can also be added - these are then added to the validator.js o
126126
```javascript
127127
// extend([method name], [validator], [default error message])
128128

129-
var extend = require('mongoose-validator').extend
129+
var extend = require('mongoose-validator').extend;
130130

131131
extend(
132132
'isString',
133-
function(val) {
134-
return Object.prototype.toString.call(val) === '[object String]'
133+
function (val) {
134+
return Object.prototype.toString.call(val) === '[object String]';
135135
},
136136
'Not a string'
137-
)
137+
);
138138
```
139139

140140
Custom validators are called normally:
141141

142142
```javascript
143143
validate({
144144
validator: 'isString',
145-
})
145+
});
146146
```
147147

148148
Custom validator can be passed directly as a function:
149149

150150
```javascript
151151
validate({
152-
validator: function(val) {
153-
return val > 0
152+
validator: function (val) {
153+
return val > 0;
154154
},
155155
message: 'Count must be a positive number.',
156-
})
156+
});
157157
```
158158

159159
NOTE: As per validator.js documentation, the currently tested value is accessed through the first argument that is automatically passed to the validator function.
@@ -166,7 +166,7 @@ Mongoose Validator can use the validator.js `matches` method, however, it's wort
166166
validate({
167167
validator: 'matches',
168168
arguments: /^[a-zA-Z\-]+$/i,
169-
})
169+
});
170170
```
171171

172172
or as a string with a further argument containing any required modifiers:
@@ -175,7 +175,7 @@ or as a string with a further argument containing any required modifiers:
175175
validate({
176176
validator: 'matches',
177177
arguments: ['^[a-zA-Z-]+$', 'i'],
178-
})
178+
});
179179
```
180180

181181
## Contributors
@@ -184,7 +184,7 @@ Special thanks to [Francesco Pasqua](https://github.com/cesconix/) for heavily r
184184

185185
## License (MIT)
186186

187-
Copyright (c) 2015 Lee Powell <mailto:[email protected]>
187+
Copyright (c) 2015 Lee Powell <[email protected]>
188188

189189
Permission is hereby granted, free of charge, to any person obtaining
190190
a copy of this software and associated documentation files (the

docker-compose.yml

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
version: '3.8'
2+
3+
services:
4+
mongo:
5+
image: mongo:latest
6+
restart: always
7+
environment:
8+
- MONGO_INITDB_ROOT_USERNAME=root
9+
- MONGO_INITDB_ROOT_PASSWORD=example
10+
logging:
11+
driver: none
12+
ports:
13+
- '27017:27017'

docs/fonts/OpenSans-Bold-webfont.eot

-19.1 KB
Binary file not shown.

0 commit comments

Comments
 (0)