mirror of
https://github.com/Redocly/redoc.git
synced 2025-07-10 00:02:39 +03:00
Add error messages to Pipes
This commit is contained in:
parent
66aa19404a
commit
0a3bbdf0d1
|
@ -1,6 +1,7 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
import {Pipe} from 'angular2/core';
|
import {Pipe, InvalidPipeArgumentException} from 'angular2/core';
|
||||||
|
import {isString} from 'angular2/src/facade/lang';
|
||||||
import {JsonPointer} from './JsonPointer';
|
import {JsonPointer} from './JsonPointer';
|
||||||
import marked from 'marked';
|
import marked from 'marked';
|
||||||
|
|
||||||
|
@ -15,39 +16,42 @@ marked.setOptions({
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
@Pipe({
|
@Pipe({ name: 'keys' })
|
||||||
name: 'keys'
|
|
||||||
})
|
|
||||||
export class KeysPipe {
|
export class KeysPipe {
|
||||||
transform(obj) {
|
transform(obj) {
|
||||||
|
if (typeof obj !== 'object') {
|
||||||
|
throw new InvalidPipeArgumentException(ValuesPipe, obj);
|
||||||
|
}
|
||||||
return Object.keys(obj);
|
return Object.keys(obj);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Pipe({
|
@Pipe({ name: 'values' })
|
||||||
name: 'values'
|
|
||||||
})
|
|
||||||
export class ValuesPipe {
|
export class ValuesPipe {
|
||||||
transform(obj) {
|
transform(value) {
|
||||||
return Object.keys(obj).map(key => obj[key]);
|
if (typeof value !== 'object') {
|
||||||
|
throw new InvalidPipeArgumentException(ValuesPipe, value);
|
||||||
|
}
|
||||||
|
return Object.keys(value).map(key => value[key]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Pipe({
|
@Pipe({ name: 'jsonPointerEscape' })
|
||||||
name: 'jsonPointerEscape'
|
|
||||||
})
|
|
||||||
export class JsonPointerEscapePipe {
|
export class JsonPointerEscapePipe {
|
||||||
transform(str) {
|
transform(value) {
|
||||||
return JsonPointer.escape(str);
|
if (!isString(value)) {
|
||||||
|
throw new InvalidPipeArgumentException(JsonPointerEscapePipe, value);
|
||||||
|
}
|
||||||
|
return JsonPointer.escape(value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Pipe({
|
@Pipe({ name: 'marked' })
|
||||||
name: 'marked'
|
|
||||||
})
|
|
||||||
export class MarkedPipe {
|
export class MarkedPipe {
|
||||||
transform(str) {
|
transform(value) {
|
||||||
if (!str) return str;
|
if (!isString(value)) {
|
||||||
return marked(str);
|
throw new InvalidPipeArgumentException(JsonPointerEscapePipe, value);
|
||||||
|
}
|
||||||
|
return marked(value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user