Skip to content
This repository has been archived by the owner on Feb 23, 2023. It is now read-only.

Add linting #98

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,7 @@ src/**/*.d.ts
.vscode
coverage
package-lock.json
yarn.lock
yarn.lock
.npmrc
.nvmrc
.yvmrc
7 changes: 6 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,13 @@ services:
- xvfb

cache:
yarn: true
npm: true
directories:
- node_modules

script:
- npm run lint
- npm run build
- npm run test

after_success: npm run cover
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 10.1.0

- Add linting [#98](https://github.com/fknop/angular-pipes/pull/98)

# 10.0.0

- Added a module for each pipe [#97](https://github.com/fknop/angular-pipes/pull/97)
Expand Down
42 changes: 24 additions & 18 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
{
"$schema": "./node_modules/ng-packagr/package.schema.json",
"name": "angular-pipes",
"version": "10.0.0",
"version": "10.1.0",
"description": "Angular pipes library",
"scripts": {
"cover": "cat ./coverage/*/lcovonly | ./node_modules/.bin/coveralls",
"karma": "node_modules/.bin/karma start karma.conf.js",
"pretty": "prettier --check '**/*.{ts,scss,js,json,yml,md,html}'",
"pretty:write": "yarn pretty --write",
"packagr": "ng-packagr -p package.json",
"build": "ng-packagr -p package.json",
"publish-dist": "npm publish dist",
"test": "npm run karma"
"test": "yarn karma",
"lint": "run-p lint:*",
"lint:ts": "tslint --project tsconfig.json --config tslint.json --format stylish",
"lint:pretty": "prettier --check '**/*.{ts,scss,js,json,yml,md,html}'"
},
"author": "Florian Knop",
"repository": {
Expand All @@ -27,16 +29,18 @@
"library"
],
"license": "MIT",
"dependencies": {},
"devDependencies": {
"@angular/animations": "^8.1.3",
"@angular/common": "^8.1.3",
"@angular/compiler": "^8.1.3",
"@angular/compiler-cli": "^8.1.3",
"@angular/core": "^8.1.3",
"@angular/platform-browser": "^8.1.3",
"@angular/platform-browser-dynamic": "^8.1.3",
"@angular/platform-server": "^8.1.3",
"@types/jasmine": "^3.3.16",
"@angular/animations": "^8.2.10",
"@angular/common": "^8.2.10",
"@angular/compiler": "^8.2.10",
"@angular/compiler-cli": "^8.2.10",
"@angular/core": "^8.2.10",
"@angular/platform-browser": "^8.2.10",
"@angular/platform-browser-dynamic": "^8.2.10",
"@angular/platform-server": "^8.2.10",
"@types/jasmine": "^3.4.0",
"codelyzer": "^5.1.2",
"core-js": "^3.1.4",
"coveralls": "^3.0.5",
"jasmine-core": "^3.4.0",
Expand All @@ -45,22 +49,24 @@
"karma-jasmine": "^2.0.1",
"karma-spec-reporter": "0.0.32",
"karma-typescript": "^4.1.1",
"ng-packagr": "^5.4.3",
"ng-packagr": "^5.6.1",
"npm-run-all": "^4.1.5",
"prettier": "^1.18.2",
"reflect-metadata": "^0.1.13",
"rxjs": "^6.5.2",
"tsickle": "^0.36.0",
"tsickle": "^0.37.0",
"tslib": "^1.10.0",
"tslint": "^5.20.0",
"tslint-microsoft-contrib": "^6.2.0",
"tslint-sonarts": "^1.9.0",
"typescript": "3.5.3",
"zone.js": "~0.9.1"
},
"dependencies": {},
"prettier": {
"printWidth": 120,
"singleQuote": true,
"trailingComma": "es5"
},
"$schema": "./node_modules/ng-packagr/package.schema.json",
"ngPackage": {
"lib": {
"entryFile": "src/public_api.ts"
Expand Down
4 changes: 2 additions & 2 deletions src/aggregate/group-by.pipe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import { getProperty, isArray, isUndefined } from '../utils/utils';
name: 'groupBy',
})
export class GroupByPipe implements PipeTransform {
transform(input: any, prop: string): Array<any> {
transform(input: any, prop: string): any[] {
if (!isArray(input)) {
return input;
}

const arr: { [key: string]: Array<any> } = {};
const arr: { [key: string]: any[] } = {};

for (const value of input) {
const field: any = getProperty(value, prop);
Expand Down
2 changes: 1 addition & 1 deletion src/array/chunk.pipe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { isArray } from '../utils/utils';
name: 'chunk',
})
export class ChunkPipe implements PipeTransform {
transform(input: any, size: number = 1): any {
transform(input: any, size = 1): any {
if (!isArray(input)) {
return input;
}
Expand Down
18 changes: 10 additions & 8 deletions src/array/first-or-default.pipe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export class FirstOrDefaultPipe implements PipeTransform {
result = input[i];
}

if (typeof result === 'undefined' && typeof defaultValue !== 'undefined') {
if (result == undefined && defaultValue != undefined) {
result = defaultValue;
}

Expand All @@ -31,15 +31,17 @@ export class FirstOrDefaultPipe implements PipeTransform {
}

if (isFunction(predicate)) {
return FirstOrDefaultPipe.find(input, <CollectionPredicate>predicate, defaultValue);
} else if (isArray(predicate)) {
const [key, value] = <string[]>predicate;
return FirstOrDefaultPipe.find(input, predicate as CollectionPredicate, defaultValue);
}
if (isArray(predicate)) {
const [key, value] = predicate as string[];
return FirstOrDefaultPipe.find(input, (item: any) => getProperty(item, key) === value, defaultValue);
} else if (predicate) {
return FirstOrDefaultPipe.find(input, item => item === <any>predicate, defaultValue);
} else {
return input;
}
if (predicate) {
return FirstOrDefaultPipe.find(input, item => item === predicate, defaultValue);
}

return input;
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/array/join.pipe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { isArray } from '../utils/utils';
name: 'join',
})
export class JoinPipe implements PipeTransform {
transform(input: any, character: string = ''): any {
transform(input: any, character = ''): any {
if (!isArray(input)) {
return input;
}
Expand Down
45 changes: 23 additions & 22 deletions src/array/order-by.pipe.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// tslint:disable:cognitive-complexity
import { Pipe, PipeTransform, NgModule } from '@angular/core';
import { isArray } from '../utils/utils';

Expand Down Expand Up @@ -41,35 +42,35 @@ export class OrderByPipe implements PipeTransform {
const comparator = OrderByPipe._orderBy(a, b);
return desc ? -comparator : comparator;
});
} else {
// If contains + or -, substring the property
const property = first === '+' || desc ? propertyToCheck.substr(1) : propertyToCheck;

return [...input].sort((a: any, b: any) => {
const comparator = OrderByPipe._orderBy(a[property], b[property]);
return desc ? -comparator : comparator;
});
}
} else {
// Config is an array of property

// If contains + or -, substring the property
const property = first === '+' || desc ? propertyToCheck.substr(1) : propertyToCheck;

return [...input].sort((a: any, b: any) => {
for (let i: number = 0; i < config.length; ++i) {
const first = config[i].substr(0, 1);
const desc = first === '-';
const property = first === '+' || desc ? config[i].substr(1) : config[i];
const comparator = OrderByPipe._orderBy(a[property], b[property]);
return desc ? -comparator : comparator;
});
}

// Config is an array of property

return [...input].sort((a: any, b: any) => {
for (const conf of config) {
const first = conf.substr(0, 1);
const desc = first === '-';
const property = first === '+' || desc ? conf.substr(1) : conf;

const comparator = OrderByPipe._orderBy(a[property], b[property]);
const comparison = desc ? -comparator : comparator;
const comparator = OrderByPipe._orderBy(a[property], b[property]);
const comparison = desc ? -comparator : comparator;

if (comparison !== 0) {
return comparison;
}
if (comparison !== 0) {
return comparison;
}
}

return 0;
});
}
return 0;
});
}
}

Expand Down
7 changes: 4 additions & 3 deletions src/array/range.pipe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ import { Pipe, PipeTransform, NgModule } from '@angular/core';
name: 'range',
})
export class RangePipe implements PipeTransform {
transform(_input: any, size: number = 0, start: number = 1, step: number = 1): any {
transform(_input: any, size = 0, start = 1, step = 1): any {
const range: number[] = [];
let _start = start;
for (let length = 0; length < size; ++length) {
range.push(start);
start += step;
range.push(_start);
_start += step;
}

return range;
Expand Down
10 changes: 6 additions & 4 deletions src/array/where.pipe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,16 @@ export class WherePipe implements PipeTransform {

if (isFunction(fn)) {
return input.filter(fn);
} else if (isArray(fn)) {
}
if (isArray(fn)) {
const [key, value] = fn;
return input.filter((item: any) => getProperty(item, key) === value);
} else if (fn) {
}
if (fn) {
return input.filter((item: any) => item === fn);
} else {
return input;
}

return input;
}
}

Expand Down
22 changes: 11 additions & 11 deletions src/math/bytes.pipe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,16 @@ export class BytesPipe implements PipeTransform {
TB: { max: Number.MAX_SAFE_INTEGER, prev: 'GB' },
};

transform(input: any, decimal: number = 0, from: ByteUnit = 'B', to?: ByteUnit): any {
static formatResult(result: number, unit: string): string {
return `${result} ${unit}`;
}

static calculateResult(format: { max: number; prev?: ByteUnit }, bytes: number) {
const prev = format.prev ? BytesPipe.formats[format.prev] : undefined;
return prev ? bytes / prev.max : bytes;
}

transform(input: any, decimal = 0, from: ByteUnit = 'B', to?: ByteUnit): any {
if (!(isNumberFinite(input) && isNumberFinite(decimal) && isInteger(decimal) && isPositive(decimal))) {
return input;
}
Expand All @@ -25,7 +34,7 @@ export class BytesPipe implements PipeTransform {
let unit = from;
while (unit !== 'B') {
bytes *= 1024;
unit = BytesPipe.formats[unit].prev!;
unit = BytesPipe.formats[unit].prev;
}

if (to) {
Expand All @@ -47,15 +56,6 @@ export class BytesPipe implements PipeTransform {
}
}
}

static formatResult(result: number, unit: string): string {
return `${result} ${unit}`;
}

static calculateResult(format: { max: number; prev?: ByteUnit }, bytes: number) {
const prev = format.prev ? BytesPipe.formats[format.prev] : undefined;
return prev ? bytes / prev.max : bytes;
}
}

@NgModule({
Expand Down
9 changes: 5 additions & 4 deletions src/math/ceil.pipe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ import { createRound, isString } from '../utils/utils';
name: 'ceil',
})
export class CeilPipe implements PipeTransform {
transform(value: any, precision: any = 0): any {
if (isString(precision)) {
precision = parseInt(precision);
transform(value: any, precision: any = 0, radix = 10): any {
let _precision = precision;
if (isString(_precision)) {
_precision = parseInt(_precision, radix);
}

return createRound('ceil')(value, precision);
return createRound('ceil')(value, _precision);
}
}

Expand Down
9 changes: 5 additions & 4 deletions src/math/floor.pipe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ import { createRound, isString } from '../utils/utils';
name: 'floor',
})
export class FloorPipe implements PipeTransform {
transform(value: any, precision: any = 0): any {
if (isString(precision)) {
precision = parseInt(precision);
transform(value: any, precision: any = 0, radix = 10): any {
let _precision = precision;
if (isString(_precision)) {
_precision = parseInt(_precision, radix);
}

return createRound('floor')(value, precision);
return createRound('floor')(value, _precision);
}
}

Expand Down
26 changes: 13 additions & 13 deletions src/math/ordinal.pipe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,20 @@ export class OrdinalPipe implements PipeTransform {
}

if (this.endsWithTenth(input)) {
return input + 'th';
} else {
const cardinal = input.toString().charAt(input.toString().length - 1);
return `${input}th`;
}

const cardinal = input.toString().charAt(input.toString().length - 1);

switch (cardinal) {
case '1':
return input + 'st';
case '2':
return input + 'nd';
case '3':
return input + 'rd';
default:
return input + 'th';
}
switch (cardinal) {
case '1':
return `${input}st`;
case '2':
return `${input}nd`;
case '3':
return `${input}rd`;
default:
return `${input}th`;
}
}

Expand Down
Loading