-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(gettag): adding util function to get to string tag of a value
- Loading branch information
1 parent
4e88c35
commit 29c981f
Showing
4 changed files
with
45 additions
and
4 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,16 @@ | ||
import { getTag } from './getTag'; | ||
|
||
describe('getTag', () => { | ||
it('should get Number tag', () => { | ||
expect(getTag(1)).toEqual('[object Number]'); | ||
}); | ||
it('should get String tag', () => { | ||
expect(getTag('hello')).toEqual('[object String]'); | ||
}); | ||
it('should get Undefined tag', () => { | ||
expect(getTag(undefined)).toEqual('[object Undefined]'); | ||
}); | ||
it('should get Null tag', () => { | ||
expect(getTag(null)).toEqual('[object Null]'); | ||
}); | ||
}); |
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,21 @@ | ||
const toString = Object.prototype.toString; | ||
|
||
/** | ||
* Gets the `toStringTag` of `value`. | ||
* @private | ||
* @param {*} value The value to query. | ||
* @returns {string} Returns the `toStringTag`. | ||
* @example | ||
* ```javascript | ||
* getTag(1) | ||
* // => '[object Number]' | ||
* | ||
* getTag(null) | ||
* // => '[object Null]' | ||
* ``` | ||
*/ | ||
export function getTag(value: any): string { | ||
return toString.call(value); | ||
} | ||
|
||
export default getTag; |
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