Skip to content

Commit 7432978

Browse files
committed
feat(pkg): remove old "validator.js" and use its ESM+AJV version
1 parent 0290455 commit 7432978

19 files changed

Lines changed: 46 additions & 73 deletions

package.json

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,8 @@
33
"version": "1.1.2",
44
"description": "JSON Resume Schema",
55
"private": false,
6-
"main": "validator.js",
76
"exports": {
87
".": {
9-
"require": "./validator.js",
10-
"import": "./validator.js"
11-
},
12-
"./all": {
138
"require": "./dist/index.cjs",
149
"import": "./index.mjs"
1510
},
@@ -41,11 +36,9 @@
4136
"sample.resume.json",
4237
"sample.job.json",
4338
"schema.json",
44-
"job-schema.json",
45-
"validator.js"
39+
"job-schema.json"
4640
],
4741
"dependencies": {
48-
"jsonschema": "^1.4.1"
4942
},
5043
"devDependencies": {
5144
"ajv": "^8.20.0",

test/0-package.spec.cjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use strict'
22

33
const tape = require('tape')
4-
const { validate, schema, jobSchema } = require('@jsonresume/schema/all')
4+
const { validate, schema, jobSchema } = require('@jsonresume/schema')
55

66
tape('CJS package export - validate', (t) => {
77
t.equal(typeof validate, 'function', 'package should export "validate" function')

test/0-package.spec.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import tape from 'tape'
2-
import { validate, schema, jobSchema } from '@jsonresume/schema/all'
2+
import { validate, schema, jobSchema } from '@jsonresume/schema'
33

44
import treeValidate from '@jsonresume/schema/validate'
55
import treeSchemasResume from '@jsonresume/schema/schemas/resume.json' with { type: 'json' }

test/awards-esm.spec.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import test from 'tape'
2-
import { validate } from '@jsonresume/schema/all'
2+
import validate from '@jsonresume/schema/validate'
33

44
import fixtures from './__test__/awards.json' with { type: 'json' }
55

test/awards.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
var test = require("tape");
2-
var { validate } = require("../validator");
2+
var { validate } = require("@jsonresume/schema");
33
const fixtures = require("./__test__/awards.json");
44

55
test("awards - valid", (t) => {

test/basics.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
var test = require('tape');
2-
var { validate } = require('../validator');
2+
var { validate } = require("@jsonresume/schema");
33
const fixtures = require('./__test__/basics.json');
44

55
test('basics - valid', (t) => {

test/certificates.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
var test = require('tape');
2-
var { validate } = require('../validator');
2+
var { validate } = require("@jsonresume/schema");
33
const fixtures = require('./__test__/certificates.json');
44

55
test('certificates - valid', (t) => {

test/dates.spec.js

Lines changed: 29 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,58 @@
1-
var test = require("tape");
2-
var Validator = require("jsonschema").Validator;
1+
'use strict'
2+
const test = require('tape')
3+
const Ajv = require('ajv')
34

4-
const fixtures = require("./__test__/dates.json");
5-
// var mockDateSchema = require('./__test__/mockDateSchema.json');
5+
const schemaResume = require('@jsonresume/schema/schemas/resume.json')
66

7-
const mockDateSchema = {
8-
type: "string",
9-
description: "Mock Date Format",
10-
pattern:
11-
"^([1-2][0-9]{3}-[0-1][0-9]-[0-3][0-9]|[1-2][0-9]{3}-[0-1][0-9]|[1-2][0-9]{3})$",
12-
};
7+
const fixtures = require('./__test__/dates.json');
8+
9+
const miniDateSchema = {
10+
type: 'string',
11+
description: 'Mock Date Format',
1312

14-
function dateValidate(resumeJson, callback) {
15-
var v = new Validator();
13+
// copy 'date' pattern from resume schema
14+
pattern: schemaResume['$defs']['iso8601']['pattern'],
15+
};
1616

17-
const validation = v.validate(resumeJson, mockDateSchema);
17+
function dateValidate (resumeJson, callback) {
18+
const ajv = new Ajv();
19+
const validate = ajv.compile(miniDateSchema)
1820

19-
if (!validation.valid) {
20-
return callback(validation.errors, false);
21+
if (!validate(resumeJson)) {
22+
return callback(validate.errors, false);
2123
}
2224

2325
return callback(null, true);
2426
}
2527

26-
test("dates - YYYY-MM-DD", (t) => {
28+
test('dates - YYYY-MM-DD', (t) => {
2729
dateValidate(fixtures.yearMonthDay, (err, valid) => {
28-
t.equal(err, null, "err should be null");
29-
t.true(valid, "valid is true");
30+
t.equal(err, null, 'err should be null');
31+
t.true(valid, 'valid is true');
3032
});
3133
t.end();
3234
});
3335

34-
test("dates - YYYY-MM", (t) => {
36+
test('dates - YYYY-MM', (t) => {
3537
dateValidate(fixtures.yearMonth, (err, valid) => {
36-
t.equal(err, null, "err should be null");
37-
t.true(valid, "valid is true");
38+
t.equal(err, null, 'err should be null');
39+
t.true(valid, 'valid is true');
3840
});
3941
t.end();
4042
});
4143

42-
test("dates - YYYY", (t) => {
44+
test('dates - YYYY', (t) => {
4345
dateValidate(fixtures.yearMonthDay, (err, valid) => {
44-
t.equal(err, null, "err should be null");
45-
t.true(valid, "valid is true");
46+
t.equal(err, null, 'err should be null');
47+
t.true(valid, 'valid is true');
4648
});
4749
t.end();
4850
});
4951

50-
test("dates - invalid", (t) => {
52+
test('dates - invalid', (t) => {
5153
dateValidate(fixtures.invalid, (err, valid) => {
52-
t.notEqual(err, null, "err should contain an error");
53-
t.false(valid, "valid is false");
54+
t.notEqual(err, null, 'err should contain an error');
55+
t.false(valid, 'valid is false');
5456
});
5557
t.end();
5658
});

test/education.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
var test = require('tape');
2-
var { validate } = require('../validator');
2+
var { validate } = require("@jsonresume/schema");
33
const fixtures = require('./__test__/education.json');
44

55
test('eductaion - valid', (t) => {

test/interests.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
var test = require('tape');
2-
var { validate } = require('../validator');
2+
var { validate } = require("@jsonresume/schema");
33
const fixtures = require('./__test__/interests.json');
44

55
test('interests - valid', (t) => {

0 commit comments

Comments
 (0)