Skip to content

Commit 2a7c3cf

Browse files
committed
Exports Schema as default of package
Exports `Schema` using ES6 default export Exports `SchemaError` using ES6 default export Exports `SchemaField` using ES6 default export Updates README
1 parent b6c387b commit 2a7c3cf

File tree

12 files changed

+42
-61
lines changed

12 files changed

+42
-61
lines changed

README.md

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# jk-schema
1+
# Schema
22

33
This package allows you to validate complex objects using schemas.
44

@@ -18,7 +18,7 @@ to check if the data is valid or not.
1818
You can use any of the given properties to define a field.
1919

2020
```js
21-
import {Schema} from "jk-schema/dist/schema";
21+
import Schema from "@jalik/schema";
2222

2323
const ExampleSchema = new Schema({
2424

@@ -204,7 +204,7 @@ Almost all properties (excepted `type`) accept a function instead of the usual v
204204
The given function is called with a single argument representing the current context (data) being validated by the schema.
205205

206206
```js
207-
import {Schema} from "jk-schema/dist/schema";
207+
import Schema from "@jalik/schema";
208208

209209
const isPublishing = function(context) {
210210
// context refers to the data being validated
@@ -254,8 +254,8 @@ PostSchema.validate({
254254
To create a schema, use the `Schema` class.
255255

256256
```js
257-
import RegEx from "jk-schema/dist/regex";
258-
import {Schema} from "jk-schema/dist/schema";
257+
import RegEx from "@jalik/schema/dist/regex";
258+
import Schema from "@jalik/schema";
259259

260260
const PersonSchema = new Schema({
261261
name: {
@@ -291,7 +291,7 @@ const PersonSchema = new Schema({
291291
The extend operation creates a new schema based on the current one.
292292

293293
```js
294-
import {Schema} from "jk-schema/dist/schema";
294+
import Schema from "@jalik/schema";
295295

296296
const PersonSchema = new Schema({
297297
age: {type: Number},
@@ -313,7 +313,7 @@ const ParentSchema = PersonSchema.extend({
313313
## Cloning a schema
314314

315315
```js
316-
import {Schema} from "jk-schema/dist/schema";
316+
import Schema from "@jalik/schema";
317317

318318
const PersonSchema = new Schema({
319319
name: {
@@ -331,7 +331,7 @@ The update creates fields that do not exist, but only modifies existing properti
331331
so you can keep properties that have already been defined.
332332

333333
```js
334-
import {Schema} from "jk-schema/dist/schema";
334+
import Schema from "@jalik/schema";
335335

336336
const PersonSchema = new Schema({
337337
name: {
@@ -359,8 +359,8 @@ To validate data using a schema, use the method `schema.validate(obj)`.
359359
If the validation fails, it will throw a `SchemaError` containing information about the error.
360360

361361
```js
362-
import RegEx from "jk-schema/dist/regex";
363-
import {Schema} from "jk-schema/dist/schema";
362+
import RegEx from "@jalik/schema/dist/regex";
363+
import Schema from "@jalik/schema";
364364

365365
const AddressSchema = new Schema({
366366
city: {
@@ -455,6 +455,11 @@ catch (err) {
455455

456456
## Changelog
457457

458+
### v1.0.0
459+
- Exports `Schema` using ES6 default export
460+
- Exports `SchemaError` using ES6 default export
461+
- Exports `SchemaField` using ES6 default export
462+
458463
### v0.5.1
459464
- Makes `type` field option optional
460465

package-lock.json

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
2-
"name": "jk-schema",
3-
"version": "0.5.1",
2+
"name": "@jalik/schema",
3+
"version": "1.0.0",
44
"description": "Validates objects using schemas",
55
"license": "MIT",
66
"keywords": [
@@ -37,7 +37,7 @@
3737
},
3838
"devDependencies": {
3939
"babel-core": "^6.26.0",
40-
"babel-loader": "^7.1.2",
40+
"babel-loader": "^7.1.4",
4141
"babel-polyfill": "^6.26.0",
4242
"babel-preset-env": "^1.6.1",
4343
"gulp": "^3.9.1",

src/index.js

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,6 @@
2222
* SOFTWARE.
2323
*/
2424

25-
import regExp from "./regex";
26-
import utils from "./utils";
27-
import {Schema} from "./schema";
28-
import {SchemaError} from "./schema-error";
29-
import {SchemaField} from "./schema-field";
25+
import Schema from "./schema";
3026

31-
export default {
32-
Utils: utils,
33-
RegExp: regExp,
34-
Schema: Schema,
35-
SchemaError: SchemaError,
36-
SchemaField: SchemaField
37-
}
27+
export default Schema;

src/regex.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
*/
2424

2525
export default {
26+
2627
/**
2728
* Basic alphabetic
2829
*/

src/schema-error.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,5 @@ export class SchemaError extends Error {
3131
this.reason = reason;
3232
}
3333
}
34+
35+
export default SchemaError;

src/schema-field.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@
2323
*/
2424

2525
import utils from "./utils";
26+
import Schema from "./schema";
27+
import SchemaError from "./schema-error";
2628
import {extendRecursively} from "@jalik/extend";
27-
import {Schema} from "./schema";
28-
import {SchemaError} from "./schema-error";
2929

3030
/**
3131
* Schema field properties
@@ -859,3 +859,5 @@ export class SchemaField {
859859
return value;
860860
}
861861
}
862+
863+
export default SchemaField;

src/schema.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@
2222
* SOFTWARE.
2323
*/
2424

25+
import SchemaError from "./schema-error";
26+
import SchemaField from "./schema-field";
2527
import {extendRecursively} from "@jalik/extend";
26-
import {SchemaError} from "./schema-error";
27-
import {SchemaField} from "./schema-field";
2828

2929
export class Schema {
3030

@@ -322,3 +322,5 @@ export class Schema {
322322
}
323323
}
324324
}
325+
326+
export default Schema;

test/compiled.test.js

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -22,36 +22,15 @@
2222
* SOFTWARE.
2323
*/
2424

25-
import {Schema} from "../dist/schema";
26-
import {SchemaError} from "../dist/schema-error";
27-
import {SchemaField} from "../dist/schema-field";
28-
25+
import Schema from "../dist/schema";
2926
import Index from "../dist/index";
3027

3128
describe(`Schema`, () => {
3229
it(`should be importable from package`, () => {
3330
expect(typeof Schema).toEqual("function");
3431
});
3532
it(`should be importable from index`, () => {
36-
expect(typeof Index.Schema).toEqual("function");
37-
});
38-
});
39-
40-
describe(`SchemaError`, () => {
41-
it(`should be importable from package`, () => {
42-
expect(typeof SchemaError).toEqual("function");
43-
});
44-
it(`should be importable from index`, () => {
45-
expect(typeof Index.SchemaError).toEqual("function");
46-
});
47-
});
48-
49-
describe(`SchemaField`, () => {
50-
it(`should be importable from package`, () => {
51-
expect(typeof SchemaField).toEqual("function");
52-
});
53-
it(`should be importable from index`, () => {
54-
expect(typeof Index.SchemaField).toEqual("function");
33+
expect(typeof Index).toEqual("function");
5534
});
5635
});
5736

test/schema-error.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
* SOFTWARE.
2323
*/
2424

25-
import {SchemaError} from "../src/schema-error";
25+
import SchemaError from "../src/schema-error";
2626

2727
describe(`SchemaError`, () => {
2828

0 commit comments

Comments
 (0)