Skip to content
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
2 changes: 1 addition & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"parser": "@typescript-eslint/parser",
"extends": [
"plugin:@typescript-eslint/recommended",
"prettier/@typescript-eslint",
"prettier",
"plugin:prettier/recommended"
],
"parserOptions": {
Expand Down
31 changes: 15 additions & 16 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,20 @@
"coveralls": "cat ./coverage/lcov.info | coveralls"
},
"devDependencies": {
"@types/faker": "^4.1.7",
"@types/jest": "^24.0.23",
"@typescript-eslint/eslint-plugin": "^2.7.0",
"@typescript-eslint/parser": "^2.7.0",
"coveralls": "^3.0.8",
"eslint": "^6.6.0",
"eslint-config-prettier": "^6.5.0",
"eslint-plugin-prettier": "^3.1.1",
"faker": "^4.1.0",
"husky": "^3.0.9",
"jest": "^24.9.0",
"prettier": "^1.19.1",
"rimraf": "^3.0.0",
"ts-jest": "^24.1.0",
"typescript": "^3.7.2"
"@faker-js/faker": "^7.5.0",
"@types/jest": "^29.1.0",
"@typescript-eslint/eslint-plugin": "^5.38.1",
"@typescript-eslint/parser": "^5.38.1",
"coveralls": "^3.1.1",
"eslint": "^8.24.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-prettier": "^4.2.1",
"husky": "^8.0.1",
"jest": "^29.1.1",
"prettier": "^2.7.1",
"rimraf": "^3.0.2",
"ts-jest": "^29.0.2",
"typescript": "^4.8.4"
},
"keywords": [
"typescript",
Expand All @@ -54,4 +53,4 @@
"type-safety",
"null-check"
]
}
}
5 changes: 3 additions & 2 deletions src/empty.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Optionable, NoElementError, Factory, Mapper, Predicate, Func } from ".";
import { Optionable, NoElementError } from ".";
import type { Factory, Func, Mapper, Predicate } from ".";
import { empty, ofNullable } from "./factories";

export default class Empty<T> implements Optionable<T> {
Expand All @@ -10,7 +11,7 @@ export default class Empty<T> implements Optionable<T> {
}

private isFunction(f: T | Factory<T>): f is Factory<T> {
return (f as Function).call !== undefined;
return typeof f === "function";
}

public orElse(supplier: T | Factory<T>): T {
Expand Down
4 changes: 2 additions & 2 deletions src/factories.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { Optionable } from ".";
import type { Optionable } from ".";
import { Present } from "./present";
import Empty from "./empty";

export function of<T>(value: T): Optionable<T> {
if (value === null || value === undefined) {
throw new Error("value is null");
}
return new Present(value);
return new Present<T>(value);
}

export function ofNullable<T>(value: T): Optionable<T> {
Expand Down
3 changes: 2 additions & 1 deletion src/present.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Optionable, Mapper, Factory, Predicate, Func } from ".";
import { Optionable } from ".";
import type { Factory, Func, Mapper, Predicate } from ".";
import { ofNullable, of, empty } from "./factories";

export class Present<T> implements Optionable<T> {
Expand Down
3 changes: 2 additions & 1 deletion tests/empty.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as faker from "faker";
import { faker } from "@faker-js/faker";
import { empty, NoElementError, of } from "../src";

describe("Empty Optionable", () => {
Expand Down Expand Up @@ -73,6 +73,7 @@ describe("Empty Optionable", () => {

it("should call runnable with ifPresent", () => {
const mock = jest.fn();
// eslint-disable-next-line @typescript-eslint/no-empty-function
option.ifPresentOrElse(() => {}, mock);
expect(mock).toHaveBeenCalled();
});
Expand Down
3 changes: 2 additions & 1 deletion tests/present.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as faker from "faker";
import { faker } from "@faker-js/faker";
import { of, empty } from "../src";

describe("Present Optionable", () => {
Expand Down Expand Up @@ -70,6 +70,7 @@ describe("Present Optionable", () => {

it("should call consumer with ifPresent", () => {
const mock = jest.fn();
// eslint-disable-next-line @typescript-eslint/no-empty-function
option.ifPresentOrElse(mock, () => {});
expect(mock).toHaveBeenCalledWith(str);
});
Expand Down
Loading