Added few utils methods

This commit is contained in:
Roman Gotsiy 2015-10-08 20:16:45 +03:00
parent 2594cf9503
commit aaa78d7c50
3 changed files with 52 additions and 0 deletions

18
lib/utils/JsonPointer.js Normal file
View File

@ -0,0 +1,18 @@
'use strict';
import JsonPointerLib from 'json-pointer';
/**
* Wrapper for JsonPointer. Provides common operations
*/
export class JsonPointer extends JsonPointerLib {
/**
* returns last JsonPointer token
* @example
* // returns subpath
* new JsonPointerHelper.dirName('/path/0/subpath')
*/
static dirName(pointer) {
return JsonPointer.parse(pointer).pop();
}
}

31
lib/utils/pipes.js Normal file
View File

@ -0,0 +1,31 @@
'use strict';
import {Pipe} from 'angular2/angular2';
import {JsonPointer} from './JsonPointer';
@Pipe({
name: 'keys'
})
export class KeysPipe {
transform(obj) {
return Object.keys(obj);
}
}
@Pipe({
name: 'values'
})
export class ValuesPipe {
transform(obj) {
return Object.keys(obj).map(key => obj[key]);
}
}
@Pipe({
name: 'jsonPointerEscape'
})
export class JsonPointerEscapePipe {
transform(str) {
return JsonPointer.escape(str);
}
}

View File

@ -0,0 +1,3 @@
'use strict';
export var methods = new Set(['get', 'put', 'post', 'delete', 'options', 'head', 'patch']);