This repository has been archived by the owner on Jan 16, 2024. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Move `identity`, our only current helper function - Add noop function - Can take any number of arguments, or expect any type as output.
- Loading branch information
Showing
5 changed files
with
47 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/** | ||
* Returns the same value | ||
* @param value | ||
* @returns {T} | ||
*/ | ||
export function identity<T>(value: T): T { | ||
return value; | ||
} | ||
|
||
/** | ||
* A type- and argument-agnostic function that returns null. | ||
* @param args | ||
* @returns {any} | ||
*/ | ||
export function noop(...args: any[]): any { | ||
return null; | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import chai = require("chai"); | ||
import tsutil = require("../src/index"); | ||
|
||
var functions = tsutil.functions; | ||
var assert = chai.assert; | ||
|
||
suite("functions", () => { | ||
suite("identity", () => { | ||
test("should return the same value", () => { | ||
var value = {}; | ||
assert.equal(value, functions.identity(value)); | ||
}); | ||
}); | ||
|
||
suite("noop", () => { | ||
test("can be called with no arguments", () => { | ||
assert.isNull(functions.noop()); | ||
}); | ||
|
||
test("can be called with two arguments", () => { | ||
assert.isNull(functions.noop({}, {})); | ||
}); | ||
|
||
test("can be called for any expected return type", () => { | ||
var result: { fake_type: number } = functions.noop(); | ||
assert.isNull(result); | ||
}); | ||
}); | ||
}); |
This file was deleted.
Oops, something went wrong.