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