-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
25 changed files
with
518 additions
and
190 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
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,19 @@ | ||
import * as method from "./method"; | ||
|
||
declare global { | ||
interface Array<T> { | ||
empty(): boolean; | ||
} | ||
} | ||
|
||
/** | ||
* Checks if the array is empty | ||
* @memberof Array | ||
* @returns {boolean} | ||
* @example | ||
* [1,2].empty(); // false | ||
* [].empty(); // true | ||
*/ | ||
Array.prototype.empty = function() { | ||
return method(this); | ||
}; |
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,3 @@ | ||
const method = (arr: any[]) => arr.length === 0; | ||
|
||
export = method; |
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,11 @@ | ||
import "./index"; | ||
|
||
describe("Array.prototype.empty", () => { | ||
test("[1,2].empty() returns false", () => { | ||
expect([1, 2].empty()).toEqual(false); | ||
}); | ||
|
||
test("[].empty() returns true", () => { | ||
expect([].empty()).toBe(true); | ||
}); | ||
}); |
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
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,22 @@ | ||
import * as method from "./method"; | ||
import { addPrototype } from "../utils"; | ||
|
||
declare global { | ||
interface Object { | ||
$empty(): boolean; | ||
} | ||
} | ||
|
||
/** | ||
* Checks if the object is empty | ||
* @memberof Object.prototype | ||
* @returns {boolean} | ||
* @example | ||
* { a: 1 }.$empty(); // false | ||
* {}.$empty(); // true | ||
*/ | ||
function $empty(this: object): boolean { | ||
return method(this); | ||
} | ||
|
||
addPrototype("$empty", $empty); |
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,5 @@ | ||
import * as size from "../size/method"; | ||
|
||
const method = (obj: object) => size(obj) === 0; | ||
|
||
export = method; |
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,11 @@ | ||
import "./index"; | ||
|
||
describe("Object.prototype.$empty", () => { | ||
test("{ a: 1 }.$empty() returns false", () => { | ||
expect({ a: 1 }.$empty()).toEqual(false); | ||
}); | ||
|
||
test("{}.$empty() returns true", () => { | ||
expect({}.$empty()).toBe(true); | ||
}); | ||
}); |
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
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,19 @@ | ||
import * as method from "./method"; | ||
|
||
declare global { | ||
interface String { | ||
empty(): boolean; | ||
} | ||
} | ||
|
||
/** | ||
* Checks if the string is empty | ||
* @memberof String | ||
* @returns {boolean} | ||
* @example | ||
* "123".empty(); // false | ||
* "".empty(); // true | ||
*/ | ||
String.prototype.empty = function() { | ||
return method(this as string); | ||
}; |
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,3 @@ | ||
const method = (str: string) => str.length === 0; | ||
|
||
export = method; |
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,11 @@ | ||
import "./index"; | ||
|
||
describe("String.prototype.empty", () => { | ||
test("\"123\".empty() returns false", () => { | ||
expect("123".empty()).toEqual(false); | ||
}); | ||
|
||
test("\"\".empty() returns true", () => { | ||
expect("".empty()).toBe(true); | ||
}); | ||
}); |
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
Oops, something went wrong.