4.0.0-alpha • Published 5 years ago
@telus/platform-colophon v4.0.0-alpha
Colophon Schema
Schema & Validator for the Colophon Project.
Schema Specification
Versions
# | status |
---|---|
4.0 | stable |
3.0 | deprecated as of Nov 2020 |
2.0 | deprecated as of Nov 2020 |
1.1 | deprecated as of Dec 2019 |
1.0 | deprecated as of Dec 2019 |
see an example of this repo's own
.colophon.yml
...
Install
Available as a private npm
package for validation purposes, exposes validation helper, and the schema itself (compatible with any JSON Schema validation tool)
npm install @telus/platform-colophon
Usage
const parser = require('@telus/platform-colophon)
const { schema, regex } = require('@telus/platform-colophon/versions/latest')
Referencing older versions
const schemas = require('@telus/platform-colophon/versions')
const { schema, regex } = schemas['1.0']
API
parser(colophon: String | Object): Promise<Object>
Resolves with
content
as a valid JavaScript Colophon Object Rejects withColophonError
on invalid schema test
Example: Valid Colophon
const parser = require('@telus/platform-colophon')
const valid = { ... } // supply an Object or YAML String
const colophon = await parser(valid)
// colophon is a JavaScript Object (parsed from YAML string, or returned as is)
Example: Invalid Colophon
const parser = require('@telus/platform-colophon')
// invalid
const invalid = `
version: 2.0 // or version 3.0
id: my-app
`
parser(invalid)
.then(colophon)
.catch(err => console.error(err.message, err.errors))
// invalid colophon content
// "err.errors" object contains schema errors
// e.g. "err.errors": [ { message: "should have required property 'contacts'" } ]
// see https://github.com/epoberezkin/ajv#validation-errors for details
}
Credits
- Team: The Platform Team
- Original Idea: @crimeminister
- Name: @andrewkumar
4.0.0-alpha
5 years ago
4.0.0
5 years ago