Skip to content

Commit

Permalink
Fix(#23): noImplictAny issue
Browse files Browse the repository at this point in the history
  • Loading branch information
danrevah committed Feb 6, 2017
1 parent 33d045a commit 5f1114c
Show file tree
Hide file tree
Showing 14 changed files with 29 additions and 25 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ngx-pipes",
"version": "1.3.2",
"version": "1.3.3",
"author": "Dan Revah",
"description": "Useful angular2 pipes",
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion src/app/pipes/array/diff.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ export class DiffPipe implements PipeTransform {
return input;
}

return args.reduce((d, c) => d.filter(e => !~c.indexOf(e)), input);
return args.reduce((d, c) => d.filter((e: any) => !~c.indexOf(e)), input);
}
}
2 changes: 1 addition & 1 deletion src/app/pipes/array/group-by.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ describe('GroupByPipe', () => {

it('allow function to be used as discriminator', () => {
const arrayWithDiscriminator = [{key: 'foo'}, {key: 'bar'}, {key: 'foo'}, {key: 'bar'}];
const result = pipe.transform(arrayWithDiscriminator, _ => _['key']);
const result = pipe.transform(arrayWithDiscriminator, (_: any) => _['key']);
expect(result).toEqual({
foo: [{key: 'foo'}, {key: 'foo'}],
bar: [{key: 'bar'}, {key: 'bar'}]
Expand Down
6 changes: 3 additions & 3 deletions src/app/pipes/array/group-by.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {extractDeepPropertyByMapKey, isFunction} from '../helpers/helpers';
@Pipe({name: 'groupBy'})
export class GroupByPipe implements PipeTransform {

transform(input: any, discriminator: any = [], delimiter = '|'): any {
transform(input: any, discriminator: any = [], delimiter: string = '|'): any {
if (!Array.isArray(input)) {
return input;
}
Expand All @@ -13,7 +13,7 @@ export class GroupByPipe implements PipeTransform {
}

private groupBy(list: any[], discriminator: any, delimiter: string) {
return list.reduce((acc, payload) => {
return list.reduce((acc: any, payload: string) => {
const key = this.extractKeyByDiscriminator(discriminator, payload, delimiter);

acc[key] = Array.isArray(acc[key])
Expand All @@ -24,7 +24,7 @@ export class GroupByPipe implements PipeTransform {
}, {});
}

private extractKeyByDiscriminator(discriminator, payload, delimiter) {
private extractKeyByDiscriminator(discriminator: any, payload: string, delimiter: string) {
if (isFunction(discriminator)) {
return (<Function>discriminator)(payload);
}
Expand Down
2 changes: 1 addition & 1 deletion src/app/pipes/array/intersection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ export class IntersectionPipe implements PipeTransform {
return input;
}

return args.reduce((n, c) => n.filter(e => !!~c.indexOf(e)), input);
return args.reduce((n, c) => n.filter((e: any) => !!~c.indexOf(e)), input);
}
}
4 changes: 2 additions & 2 deletions src/app/pipes/array/order-by.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export class OrderByPipe implements PipeTransform {
});
}

static orderCompare(prop, asc, a, b) {
static orderCompare(prop: string, asc: boolean, a: any, b: any) {
const first = extractDeepPropertyByMapKey(a, prop),
second = extractDeepPropertyByMapKey(b, prop);

Expand All @@ -65,7 +65,7 @@ export class OrderByPipe implements PipeTransform {
: second - first;
}

static extractFromConfig(config) {
static extractFromConfig(config: any) {
const sign = config.substr(0, 1);
const prop = config.replace(/^[-+]/, '');
const asc = sign !== '-';
Expand Down
2 changes: 1 addition & 1 deletion src/app/pipes/array/sample.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export class SamplePipe implements PipeTransform {
return input;
}

let sample = [];
let sample: any[] = [];
for (let i = 0, tmp = [...input], l = len < tmp.length ? len : tmp.length; i < l; ++i) {
sample = sample.concat(tmp.splice(
Math.floor(Math.random() * tmp.length),
Expand Down
2 changes: 1 addition & 1 deletion src/app/pipes/array/union.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export class UnionPipe implements PipeTransform {
}

return args.reduce((newArr, currArr) => {
return newArr.concat(currArr.reduce((noDupArr, curr) => {
return newArr.concat(currArr.reduce((noDupArr: any[], curr: any) => {
return (!~noDupArr.indexOf(curr) && !~newArr.indexOf(curr))
? noDupArr.concat([curr])
: noDupArr;
Expand Down
4 changes: 2 additions & 2 deletions src/app/pipes/helpers/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ export function isNumberFinite(value: any) {
return isNumber(value) && isFinite(value);
}

export function extractDeepPropertyByMapKey(obj: Object, map: string) {
export function extractDeepPropertyByMapKey(obj: any, map: string): any {
const keys = map.split('.');
const key = keys.shift();

return keys.reduce((prop, key) => {
return keys.reduce((prop: any, key: string) => {
return !isUndefined(prop) && !isUndefined(prop[key])
? prop[key]
: undefined;
Expand Down
10 changes: 5 additions & 5 deletions src/app/pipes/object/invert-by.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,16 @@ describe('InvertBy Pipe', () => {
expect(pipe.transform({foo: 'bar'})).toEqual({bar: ['foo']});
expect(pipe.transform({foo: 1, bar: 42})).toEqual({1: ['foo'], 42: ['bar']});

expect(pipe.transform({}, _ => `name_${_}`)).toEqual({});
expect(pipe.transform({foo: 'bar'}, _ => `name_${_}`)).toEqual({name_bar: ['foo']});
expect(pipe.transform({foo: 1, bar: 42}, _ => `name_${_}`)).toEqual({name_1: ['foo'], name_42: ['bar']});
expect(pipe.transform({}, (_: any) => `name_${_}`)).toEqual({});
expect(pipe.transform({foo: 'bar'}, (_: any) => `name_${_}`)).toEqual({name_bar: ['foo']});
expect(pipe.transform({foo: 1, bar: 42}, (_: any) => `name_${_}`)).toEqual({name_1: ['foo'], name_42: ['bar']});
});

it('should return inverted values / keys subsequent values override previous value', () => {
expect(pipe.transform({a: 1, b: 2, c: 1})).toEqual({1: ['a', 'c'], 2: ['b']});
expect(pipe.transform({a: 1, b: 2, c: 1, d: 2, e: 3})).toEqual({1: ['a','c'], 2: ['b','d'], 3: ['e']});

expect(pipe.transform({a: 1, b: 2, c: 1}, _ => `name_${_}`)).toEqual({name_1: ['a', 'c'], name_2: ['b']});
expect(pipe.transform({a: 1, b: 2, c: 1, d: 2, e: 3}, _ => `name_${_}`)).toEqual({name_1: ['a','c'], name_2: ['b','d'], name_3: ['e']});
expect(pipe.transform({a: 1, b: 2, c: 1}, (_: any) => `name_${_}`)).toEqual({name_1: ['a', 'c'], name_2: ['b']});
expect(pipe.transform({a: 1, b: 2, c: 1, d: 2, e: 3}, (_: any) => `name_${_}`)).toEqual({name_1: ['a','c'], name_2: ['b','d'], name_3: ['e']});
});
});
2 changes: 1 addition & 1 deletion src/app/pipes/object/invert-by.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export class InvertByPipe implements PipeTransform {
return obj;
}

return Object.keys(obj).reduce((o, k) => {
return Object.keys(obj).reduce((o: any, k: string) => {
const key = cb ? cb(obj[k]) : obj[k];
return Array.isArray(o[key])
? (o[key].push(k), o)
Expand Down
8 changes: 5 additions & 3 deletions src/app/pipes/string/camelize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ export class CamelizePipe implements PipeTransform {
return text;
}

return text.toLowerCase().split(/[-_\s]/g).filter(v => !!v).map((word, key) => {
return !key ? word : (word.slice(0, 1).toUpperCase() + word.slice(1))
}).join('');
return text.toLowerCase()
.split(/[-_\s]/g)
.filter((v: string) => !!v).map((word: string, key: any) => {
return !key ? word : (word.slice(0, 1).toUpperCase() + word.slice(1))
}).join('');
}
}
4 changes: 2 additions & 2 deletions src/app/pipes/string/latinise.ts

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion src/app/pipes/string/underscore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ export class UnderscorePipe implements PipeTransform {
return isString(text)
? text.trim()
.replace(/\s+/g, '')
.replace(/[A-Z]/g, (c, k) => k ? `_${c.toLowerCase()}` : c.toLowerCase())
.replace(/[A-Z]/g, (c: string, k: any) => {
return k ? `_${c.toLowerCase()}` : c.toLowerCase()
})
: text;
}
}

0 comments on commit 5f1114c

Please sign in to comment.