diff --git a/.prettierignore b/.prettierignore new file mode 100644 index 0000000..66dec0b --- /dev/null +++ b/.prettierignore @@ -0,0 +1,4 @@ +package.json +package-lock.json +.nyc_output/ +lib/ diff --git a/package-lock.json b/package-lock.json index 5cd7240..cb91f9d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9492,6 +9492,12 @@ "tsutils": "^2.27.2" } }, + "tslint-config-prettier": { + "version": "1.15.0", + "resolved": "https://registry.npmjs.org/tslint-config-prettier/-/tslint-config-prettier-1.15.0.tgz", + "integrity": "sha512-06CgrHJxJmNYVgsmeMoa1KXzQRoOdvfkqnJth6XUkNeOz707qxN0WfxfhYwhL5kXHHbYJRby2bqAPKwThlZPhw==", + "dev": true + }, "tsutils": { "version": "2.29.0", "resolved": "https://registry.npmjs.org/tsutils/-/tsutils-2.29.0.tgz", diff --git a/package.json b/package.json index 5ba9fa6..838c618 100644 --- a/package.json +++ b/package.json @@ -19,7 +19,7 @@ "build": "tsc -p .", "test": "TS_NODE_COMPILER_OPTIONS='{\"module\":\"commonjs\"}' nyc --require ts-node/register mocha \"src/*.test.ts\"", "prettier": "prettier '**/{*.{js?(on),ts,yml},.*.js?(on),.*.yml}' --write --list-different", - "tslint": "tslint -c tslint.json -p tsconfig.json './src/*.ts'", + "tslint": "tslint -t stylish -c tslint.json -p tsconfig.json './src/*.ts'", "semantic-release": "semantic-release" }, "nyc": { @@ -52,6 +52,7 @@ "sinon": "^6.1.5", "ts-node": "^7.0.1", "tslint": "^5.11.0", + "tslint-config-prettier": "^1.15.0", "typescript": "^3.0.1" } } diff --git a/src/index.test.ts b/src/index.test.ts index 9237b38..eed2255 100644 --- a/src/index.test.ts +++ b/src/index.test.ts @@ -1,10 +1,10 @@ Object.assign(global, require('abort-controller')) -import { create, defer, toPromise, switchMap, concatMap, mergeMap, forEach } from '.' +import { AssertionError } from 'assert' import { assert } from 'chai' +import { Observable, of, Subject, Subscriber } from 'rxjs' import * as sinon from 'sinon' -import { Subscriber, Subject, Observable, of } from 'rxjs' -import { AssertionError } from 'assert' +import { concatMap, create, defer, forEach, mergeMap, switchMap, toPromise } from '.' describe('Observable factories', () => { describe('create()', () => { diff --git a/src/index.ts b/src/index.ts index 6eeebd8..1ffe8d6 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,21 +1,6 @@ -import { from, Observable, ObservableInput, Subscriber, Subscription, TeardownLogic, OperatorFunction } from 'rxjs' +import { from, Observable, ObservableInput, OperatorFunction, Subscriber, Subscription, TeardownLogic } from 'rxjs' import { concatMap as rxConcatMap, mergeMap as rxMergeMap, switchMap as rxSwitchMap } from 'rxjs/operators' -export const switchMap = ( - project: (value: T, index: number, abortSignal: AbortSignal) => ObservableInput -): OperatorFunction => source => - source.pipe(rxSwitchMap((value, index) => defer(abortSignal => project(value, index, abortSignal)))) - -export const concatMap = ( - project: (value: T, index: number, abortSignal: AbortSignal) => ObservableInput -): OperatorFunction => source => - source.pipe(rxConcatMap((value, index) => defer(abortSignal => project(value, index, abortSignal)))) - -export const mergeMap = ( - project: (value: T, index: number, abortSignal: AbortSignal) => ObservableInput -): OperatorFunction => source => - source.pipe(rxMergeMap((value, index) => defer(abortSignal => project(value, index, abortSignal)))) - export const create = ( subscribe?: (subscriber: Subscriber, signal: AbortSignal) => TeardownLogic ): Observable => @@ -81,3 +66,18 @@ export const forEach = (source: Observable, next: (value: T) => void, sign }) } }) + +export const switchMap = ( + project: (value: T, index: number, abortSignal: AbortSignal) => ObservableInput +): OperatorFunction => source => + source.pipe(rxSwitchMap((value, index) => defer(abortSignal => project(value, index, abortSignal)))) + +export const concatMap = ( + project: (value: T, index: number, abortSignal: AbortSignal) => ObservableInput +): OperatorFunction => source => + source.pipe(rxConcatMap((value, index) => defer(abortSignal => project(value, index, abortSignal)))) + +export const mergeMap = ( + project: (value: T, index: number, abortSignal: AbortSignal) => ObservableInput +): OperatorFunction => source => + source.pipe(rxMergeMap((value, index) => defer(abortSignal => project(value, index, abortSignal)))) diff --git a/tslint.json b/tslint.json index 62d448e..2b8994c 100644 --- a/tslint.json +++ b/tslint.json @@ -1,5 +1,5 @@ { - "extends": ["tslint:recommended", "rxjs-tslint-rules", "tslint-react", "tslint-config-prettier"], + "extends": ["tslint:recommended", "tslint-config-prettier"], "rules": { "adjacent-overload-signatures": true, "array-type": [true, "array"], @@ -87,16 +87,6 @@ "prefer-template": [false, "allow-single-concat"], "quotemark": [true, "single", "jsx-double", "avoid-escape"], "return-undefined": true, - "rxjs-no-add": { - "severity": "error" - }, - "rxjs-no-operator": { - "severity": "error" - }, - "rxjs-no-patched": { - "severity": "error" - }, - "rxjs-no-wholesale": true, "space-before-function-paren": [ true, {