Skip to content

Commit 2744b98

Browse files
committed
Stable Version 1.0.0-alpha.1.
1 parent ce53d01 commit 2744b98

File tree

8 files changed

+71
-338
lines changed

8 files changed

+71
-338
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
##### 1.0.0-alpha.1 - 01 November 2014
2+
3+
Stable Version 1.0.0-alpha.1
4+
15
##### 0.1.0 - 15 September 2014
26

37
Initial Release

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Contributing Guide
22

3-
First, feel free to contact me with questions. [Mailing List](https://groups.google.com/forum/?fromgroups#!forum/js-data-project). [Issues](https://github.com/js-data/js-data-schema/issues).
3+
First, feel free to contact me with questions. [Mailing List](https://groups.io/org/groupsio/jsdata). [Issues](https://github.com/js-data/js-data-schema/issues).
44

55
1. Contribute to the issue that is the reason you'll be developing in the first place
66
1. Fork js-data-schema

Gruntfile.js

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ module.exports = function (grunt) {
1111
test: 'test'
1212
};
1313

14+
var pkg = grunt.file.readJSON('package.json');
15+
1416
grunt.initConfig({
1517
config: config,
1618
pkg: grunt.file.readJSON('package.json'),
@@ -66,17 +68,6 @@ module.exports = function (grunt) {
6668
}
6769
},
6870

69-
groc: {
70-
javascript: [
71-
'dist/js-data-schema.js'
72-
],
73-
options: {
74-
'out': 'doc/',
75-
// 'index': 'doc.md',
76-
'repository-url': 'https://github.com/js-data/js-data-schema'
77-
}
78-
},
79-
8071
browserify: {
8172
dist: {
8273
options: {
@@ -110,13 +101,37 @@ module.exports = function (grunt) {
110101
}
111102
});
112103

104+
grunt.registerTask('banner', function () {
105+
var file = grunt.file.read('dist/js-data-schema.js');
106+
107+
var banner = '/**\n' +
108+
'* @author Jason Dobry <[email protected]>\n' +
109+
'* @file js-data-schema.js\n' +
110+
'* @version ' + pkg.version + ' - Homepage <http://www.js-data.io/docs/js-data-schema>\n' +
111+
'* @copyright (c) 2014 Jason Dobry \n' +
112+
'* @license MIT <https://github.com/js-data/js-data-schema/blob/master/LICENSE>\n' +
113+
'*\n' +
114+
'* @overview Define and validate rules, datatypes and schemata in Node and in the browser.\n' +
115+
'*/\n';
116+
117+
file = banner + file;
118+
119+
grunt.file.write('dist/js-data-schema.js', file);
120+
});
121+
113122
grunt.registerTask('test', [
114123
'build',
115124
'jshint:test',
116125
'mochaTest',
117126
'karma:dist'
118127
]);
119-
grunt.registerTask('build', ['clean', 'jshint:src', 'browserify', 'uglify']);
128+
grunt.registerTask('build', [
129+
'clean',
130+
'jshint:src',
131+
'browserify',
132+
'banner',
133+
'uglify'
134+
]);
120135
grunt.registerTask('go', ['build', 'watch']);
121136

122137
grunt.registerTask('default', ['build']);

README.md

Lines changed: 1 addition & 295 deletions
Original file line numberDiff line numberDiff line change
@@ -65,301 +65,7 @@ errors; // {
6565

6666
## API
6767

68-
### Schemator
69-
70-
#### Schemator()
71-
```js
72-
var schemator = new Schemator();
73-
```
74-
75-
#### Schemator#availableDataTypes()
76-
```js
77-
schemator.availableDataTypes(); // ['boolean', 'string', 'etc.']
78-
```
79-
80-
#### Schemator#availableRules()
81-
```js
82-
schemator.availableRules(); // ['type', 'minLength', 'etc.']
83-
```
84-
85-
#### Schemator#availableSchemata()
86-
```js
87-
schemator.defineSchema('PersonSchema', { ... });
88-
schemator.availableSchemata(); // ['PersonSchema']
89-
```
90-
91-
#### Schemator#getDataType(name)
92-
```js
93-
schemator.getDataType('myDataType');
94-
```
95-
96-
#### Schemator#getRule(name)
97-
```js
98-
schemator.getRule('myRule');
99-
```
100-
101-
#### Schemator#getSchema(name)
102-
```js
103-
schemator.getSchema('PersonSchema');
104-
```
105-
106-
#### Schemator#removeDataType(name)
107-
```js
108-
schemator.removeDataType('myDataType');
109-
```
110-
111-
#### Schemator#removeRule(name)
112-
```js
113-
schemator.removeRule('myRule');
114-
```
115-
116-
#### Schemator#removeSchema(name)
117-
```js
118-
schemator.removeSchema('PersonSchema');
119-
```
120-
121-
#### Schemator#defineDataType(name, typeDefinition)
122-
```js
123-
schemator.defineDataType('NaN', function (x) {
124-
if (isNaN(x)) {
125-
return null;
126-
} else {
127-
return {
128-
rule: 'type',
129-
actual: typeof x,
130-
expected: 'NaN'
131-
};
132-
}
133-
});
134-
```
135-
136-
#### Schemator#defineRule(name, ruleFunc[, async])
137-
```js
138-
schemator.defineRule('divisibleBy', function (x, divisor) {
139-
if (typeof x === 'number' && typeof divisor === 'number' && x % divisor !== 0) {
140-
return {
141-
rule: 'divisibleBy',
142-
actual: '' + x + ' % ' + divisor + ' === ' + (x % divisor),
143-
expected: '' + x + ' % ' + divisor + ' === 0'
144-
};
145-
}
146-
return null;
147-
});
148-
149-
schemator.defineSchema('mySchema', {
150-
seats: {
151-
divisibleBy: 4
152-
}
153-
});
154-
155-
var errors = schemator.getSchema('mySchema').validateSync({
156-
seats: 16
157-
});
158-
159-
errors; // null
160-
161-
errors = schemator.getSchema('mySchema').validateSync({
162-
seats: 17
163-
});
164-
165-
errors; // {
166-
// seats: {
167-
// errors: [ {
168-
// rule: 'divisibleBy',
169-
// actual: '17 % 4 === 1',
170-
// expected: '17 % 4 === 0'
171-
// } ]
172-
// }
173-
// }
174-
```
175-
176-
Asynchronous rule:
177-
```js
178-
schemator.defineRule('divisibleBy', function (x, divisor, cb) {
179-
180-
// asynchronity here is fake, but you could do something async, like make an http request
181-
setTimeout(function () {
182-
if (typeof x === 'number' && typeof divisor === 'number' && x % divisor !== 0) {
183-
cb({
184-
rule: 'divisibleBy',
185-
actual: '' + x + ' % ' + divisor + ' === ' + (x % divisor),
186-
expected: '' + x + ' % ' + divisor + ' === 0'
187-
});
188-
}
189-
cb(null);
190-
}, 1);
191-
}, true); // pass true as the third argument
192-
193-
schemator.defineSchema('mySchema', {
194-
seats: {
195-
divisibleBy: 4
196-
}
197-
});
198-
199-
var errors = schemator.getSchema('mySchema').validate({
200-
seats: 16
201-
}, function (err) {
202-
errors; // null
203-
204-
errors = schemator.getSchema('mySchema').validate({
205-
seats: 17
206-
}, function (err) {
207-
errors; // {
208-
// seats: {
209-
// errors: [ {
210-
// rule: 'divisibleBy',
211-
// actual: '17 % 4 === 1',
212-
// expected: '17 % 4 === 0'
213-
// } ]
214-
// }
215-
// }
216-
});
217-
});
218-
```
219-
220-
#### Schemator#defineSchema(name, definition)
221-
```js
222-
schemator.defineSchema('PersonSchema', {
223-
name: {
224-
first: {
225-
type: 'string',
226-
maxLength: 255
227-
},
228-
last: {
229-
type: 'string',
230-
maxLength: 255
231-
}
232-
},
233-
age: {
234-
type: 'number',
235-
max: 150,
236-
min: 0
237-
}
238-
});
239-
```
240-
241-
#### Schemator#validate(schemaName, attrs[, options], cb)
242-
See `Schema#validate(attrs[, options], cb)`
243-
244-
#### Schemator#validateSync(schemaName, attrs[, options])
245-
See `Schema#validateSync(attrs[, options])`
246-
247-
#### Schemator#setDefaults(schemaName, attrs)
248-
See `Schema#setDefaults(attrs)`
249-
250-
#### Schemator#getDefaults()
251-
See `Schema#getDefaults()`
252-
253-
#### Schemator#addDefaultsToTarget(schemaName, target[, overwrite])
254-
See `Schema#addDefaultsToTarget(target)`
255-
256-
#### Schemator#stripNonSchemaAttrs(schemaName, target)
257-
See `Schema#stripNonSchemaAttrs(target)`
258-
259-
### Schema
260-
261-
#### Schema#validate(attrs[, options], cb)
262-
```js
263-
PersonSchema.validate({
264-
name: 'John Anderson'
265-
}, function (err) {
266-
err; // null
267-
});
268-
269-
PersonSchema.validate({
270-
name: 5
271-
}, function (err) {
272-
err; // {
273-
// name: {
274-
// errors: [{
275-
// rule: 'type',
276-
// actual: 'number',
277-
// expected: 'string'
278-
// }]
279-
// }
280-
// }
281-
});
282-
```
283-
284-
#### Schema#validateSync(attrs[, options])
285-
```js
286-
var errors = PersonSchema.validate({
287-
name: 'John Anderson'
288-
});
289-
290-
errors; // null
291-
292-
errors = mySchema.validate({
293-
name: 5
294-
});
295-
errors; // {
296-
// name: {
297-
// errors: [{
298-
// rule: 'type',
299-
// actual: 'number',
300-
// expected: 'string'
301-
// }]
302-
// }
303-
// }
304-
```
305-
306-
#### Schema#setDefaults(attrs)
307-
```js
308-
PersonSchema.setDefaults({
309-
first: '',
310-
last: '',
311-
plan: 'free'
312-
});
313-
```
314-
315-
#### Schema#getDefaults()
316-
```js
317-
PersonSchema.getDefaults(); // {
318-
first: '',
319-
last: '',
320-
age: 0
321-
}
322-
```
323-
324-
#### Schema#addDefaultsToTarget(target[, overwrite])
325-
```js
326-
var person = {
327-
first: 'John',
328-
plan: 'premium'
329-
};
330-
331-
PersonSchema.addDefaultsToTarget(person);
332-
333-
person; // {
334-
first: 'John',
335-
last: '',
336-
plan: 'premium'
337-
}
338-
339-
PersonSchema.addDefaultsToTarget(person, true);
340-
341-
person; // {
342-
first: '',
343-
last: '',
344-
plan: 'free'
345-
}
346-
```
347-
348-
#### Schema#stripNonSchemaAttrs(target)
349-
```js
350-
var person = {
351-
first: 'John',
352-
plan: 'premium',
353-
nonSchema: 'value'
354-
};
355-
356-
PersonSchema.stripNonSchemaAttrs(person);
357-
358-
person; // {
359-
first: 'John',
360-
plan: 'premium'
361-
}
362-
```
68+
[js-data-schema api](http://www.js-data.io/docs/js-data-schema)
36369

36470
## License
36571
[MIT License](https://github.com/js-data/js-data-schema/blob/master/LICENSE)

bower.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
"author": "Jason Dobry",
33
"name": "js-data-schema",
44
"description": "Define and validate rules, datatypes and schemata in Node and in the browser.",
5-
"version": "0.1.0",
6-
"homepage": "https://github.com/js-data/js-data-schema",
5+
"version": "1.0.0-alpha.1",
6+
"homepage": "http://www.js-data.io/docs/js-data-schema",
77
"repository": {
88
"type": "git",
99
"url": "https://github.com/js-data/js-data-schema.git"

0 commit comments

Comments
 (0)