2015-10-08 20:16:45 +03:00
|
|
|
'use strict';
|
|
|
|
|
2015-12-14 19:14:14 +03:00
|
|
|
import {Pipe, InvalidPipeArgumentException} from 'angular2/core';
|
|
|
|
import {isString} from 'angular2/src/facade/lang';
|
2015-10-08 20:16:45 +03:00
|
|
|
import {JsonPointer} from './JsonPointer';
|
2015-10-23 12:03:47 +03:00
|
|
|
import marked from 'marked';
|
|
|
|
|
|
|
|
marked.setOptions({
|
|
|
|
renderer: new marked.Renderer(),
|
|
|
|
gfm: true,
|
|
|
|
tables: true,
|
|
|
|
breaks: false,
|
|
|
|
pedantic: false,
|
|
|
|
smartLists: true,
|
|
|
|
smartypants: false
|
|
|
|
});
|
|
|
|
|
2015-10-08 20:16:45 +03:00
|
|
|
|
2015-12-14 19:14:14 +03:00
|
|
|
@Pipe({ name: 'keys' })
|
2015-10-08 20:16:45 +03:00
|
|
|
export class KeysPipe {
|
|
|
|
transform(obj) {
|
2015-12-14 19:14:14 +03:00
|
|
|
if (typeof obj !== 'object') {
|
|
|
|
throw new InvalidPipeArgumentException(ValuesPipe, obj);
|
|
|
|
}
|
2015-10-08 20:16:45 +03:00
|
|
|
return Object.keys(obj);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-14 19:14:14 +03:00
|
|
|
@Pipe({ name: 'values' })
|
2015-10-08 20:16:45 +03:00
|
|
|
export class ValuesPipe {
|
2015-12-14 19:14:14 +03:00
|
|
|
transform(value) {
|
|
|
|
if (typeof value !== 'object') {
|
|
|
|
throw new InvalidPipeArgumentException(ValuesPipe, value);
|
|
|
|
}
|
|
|
|
return Object.keys(value).map(key => value[key]);
|
2015-10-08 20:16:45 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-14 19:14:14 +03:00
|
|
|
@Pipe({ name: 'jsonPointerEscape' })
|
2015-10-08 20:16:45 +03:00
|
|
|
export class JsonPointerEscapePipe {
|
2015-12-14 19:14:14 +03:00
|
|
|
transform(value) {
|
|
|
|
if (!isString(value)) {
|
|
|
|
throw new InvalidPipeArgumentException(JsonPointerEscapePipe, value);
|
|
|
|
}
|
|
|
|
return JsonPointer.escape(value);
|
2015-10-08 20:16:45 +03:00
|
|
|
}
|
|
|
|
}
|
2015-10-23 12:03:47 +03:00
|
|
|
|
2015-12-14 19:14:14 +03:00
|
|
|
@Pipe({ name: 'marked' })
|
2015-10-23 12:03:47 +03:00
|
|
|
export class MarkedPipe {
|
2015-12-14 19:14:14 +03:00
|
|
|
transform(value) {
|
|
|
|
if (!isString(value)) {
|
|
|
|
throw new InvalidPipeArgumentException(JsonPointerEscapePipe, value);
|
|
|
|
}
|
|
|
|
return marked(value);
|
2015-10-23 12:03:47 +03:00
|
|
|
}
|
|
|
|
}
|