mirror of
https://github.com/scratchfoundation/scratch-sb1-converter.git
synced 2024-11-24 08:38:09 -05:00
Merge pull request #21 from mzgoddard/export-assert-error
feat: export AssertionError and ValidationError
This commit is contained in:
commit
6a8cac3829
3 changed files with 16 additions and 5 deletions
|
@ -1 +1,2 @@
|
|||
export {SB1File} from './sb1-file';
|
||||
export {AssertionError, ValidationError} from './util/assert';
|
||||
|
|
|
@ -27,7 +27,7 @@ class SB1Signature extends Packet.extend({
|
|||
* @throws {AssertionError} Throws if it is not valid.
|
||||
*/
|
||||
validate () {
|
||||
assert(
|
||||
assert.validate(
|
||||
this.equals({version: 'ScratchV01'}) ||
|
||||
this.equals({version: 'ScratchV02'}),
|
||||
'Invalid Scratch file signature.'
|
||||
|
@ -45,7 +45,7 @@ class SB1Header extends Packet.extend({
|
|||
numObjects: Uint32BE
|
||||
}) {
|
||||
validate () {
|
||||
assert(
|
||||
assert.validate(
|
||||
this.equals({
|
||||
ObjS: 'ObjS',
|
||||
ObjSValue: 1,
|
||||
|
|
|
@ -3,11 +3,21 @@
|
|||
*/
|
||||
class AssertionError extends Error {}
|
||||
|
||||
/**
|
||||
* A `scratch-sb1-converter` validation error.
|
||||
*/
|
||||
class ValidationError extends AssertionError {}
|
||||
|
||||
const assert = function (test, message) {
|
||||
if (!test) throw new AssertionError(message);
|
||||
};
|
||||
|
||||
export {
|
||||
AssertionError,
|
||||
assert
|
||||
assert.validate = function (test, message) {
|
||||
if (!test) throw new ValidationError(message);
|
||||
};
|
||||
|
||||
export {
|
||||
assert,
|
||||
AssertionError,
|
||||
ValidationError
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue