Commit 5782c0b1 authored by Matt Teeter's avatar Matt Teeter

Merge branch 'feature/value-by-key' into 'develop'

feat(pipe): add value-by-key pipe

See merge request !13
parents 50228c7b 12df061d
Pipeline #85979 passed with stages
in 6 minutes and 45 seconds
import { CommonModule } from '@angular/common';
import { NgModule } from '@angular/core';
import { ValueByKeyPipe } from './value-by-key.pipe';
@NgModule({
declarations: [ValueByKeyPipe],
imports: [CommonModule],
exports: [ValueByKeyPipe]
})
export class ValueByKeyModule {}
import { ValueByKeyPipe } from './value-by-key.pipe';
describe('ValueByKeyPipe', () => {
let pipe: ValueByKeyPipe;
beforeEach(() => {
pipe = new ValueByKeyPipe();
});
it('create an instance', () => {
expect(pipe).toBeTruthy();
});
it('should return a value when the key exists in the object', () => {
expect(pipe.transform({ a: 'test' }, 'a')).toEqual('test');
});
it('should return null if the key is not found in the object', () => {
expect(pipe.transform({ a: 'test' }, 'b')).toBeNull();
});
it('should return null if the object is nil', () => {
expect(pipe.transform(undefined, 'a')).toBeNull();
expect(pipe.transform(null, 'a')).toBeNull();
});
it('should return null if the key is nil', () => {
expect(pipe.transform({ a: 'test' }, undefined)).toBeNull();
expect(pipe.transform({ a: 'test' }, null)).toBeNull();
});
});
import { Pipe, PipeTransform } from '@angular/core';
import { pathOr } from 'ramda';
@Pipe({
name: 'valueByKey'
})
export class ValueByKeyPipe implements PipeTransform {
public transform(value: object, key: string): any {
return pathOr(null, [key], value);
}
}
......@@ -4,7 +4,8 @@
"peerDependencies": {
"@angular/common": "^8.0.0",
"@angular/core": "^8.0.0",
"@angular/cdk": "^8.2.3"
"@angular/cdk": "^8.2.3",
"ramda": "^0.27.0"
},
"private": false,
"repository": {
......
......@@ -1609,6 +1609,13 @@
resolved "https://nexus.ci.psu.edu/repository/npm-all/@types/normalize-package-data/-/normalize-package-data-2.4.0.tgz#e486d0d97396d79beedd0a6e33f4534ff6b4973e"
integrity sha512-f5j5b/Gf71L+dbqxIpQ4Z2WlmI/mPJ0fOkGGmFgtb6sAu97EPczzbS3/tJKxmcYDj55OX6ssqwDAWOHIYDRDGA==
"@types/ramda@^0.26.43":
version "0.26.43"
resolved "https://nexus.ci.psu.edu/repository/npm-all/@types/ramda/-/ramda-0.26.43.tgz#62e235ea17133b8629bc891a26851cf0ea2b4204"
integrity sha512-VK2EaHR/fpeMNPDboGSPAmH+a6HN1pflWqRt67Jii2n8vGpYt6vxIBc1ZdoYrA/jQXRaGGpJKRiSPcHALRD3/A==
dependencies:
ts-toolbelt "^6.3.3"
"@types/resolve@0.0.8":
version "0.0.8"
resolved "https://nexus.ci.psu.edu/repository/npm-all/@types/resolve/-/resolve-0.0.8.tgz#f26074d238e02659e323ce1a13d041eee280e194"
......@@ -9384,6 +9391,11 @@ ramda@0.24.1:
resolved "https://nexus.ci.psu.edu/repository/npm-all/ramda/-/ramda-0.24.1.tgz#c3b7755197f35b8dc3502228262c4c91ddb6b857"
integrity sha1-w7d1UZfzW43DUCIoJixMkd22uFc=
ramda@^0.27.0:
version "0.27.0"
resolved "https://nexus.ci.psu.edu/repository/npm-all/ramda/-/ramda-0.27.0.tgz#915dc29865c0800bf3f69b8fd6c279898b59de43"
integrity sha512-pVzZdDpWwWqEVVLshWUHjNwuVP7SfcmPraYuqocJp1yo2U1R7P+5QAfDhdItkuoGqIBnBYrtPp7rEPqDn9HlZA==
randomatic@^3.0.0:
version "3.1.1"
resolved "https://nexus.ci.psu.edu/repository/npm-all/randomatic/-/randomatic-3.1.1.tgz#b776efc59375984e36c537b2f51a1f0aff0da1ed"
......@@ -11345,6 +11357,11 @@ ts-node@~7.0.0:
source-map-support "^0.5.6"
yn "^2.0.0"
ts-toolbelt@^6.3.3:
version "6.3.5"
resolved "https://nexus.ci.psu.edu/repository/npm-all/ts-toolbelt/-/ts-toolbelt-6.3.5.tgz#5cb4e0454ab954faa9b6e4d5bce366fdb262e364"
integrity sha512-Xvh/gvBBCRU1qGeholaN8kgiwBH4neyun6VIDDsJf/jNwz4PXyR8ZY/5qdpB1DuMBrWMG2oTT1oWcOzGPOnluQ==
tsconfig-paths-webpack-plugin@3.2.0:
version "3.2.0"
resolved "https://nexus.ci.psu.edu/repository/npm-all/tsconfig-paths-webpack-plugin/-/tsconfig-paths-webpack-plugin-3.2.0.tgz#6e70bd42915ad0efb64d3385163f0c1270f3e04d"
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment