Skip to content

Commit 20164d6

Browse files
getTypeof Data Is Also a Class (#9)
1 parent 4f74de8 commit 20164d6

File tree

4 files changed

+73
-3
lines changed

4 files changed

+73
-3
lines changed

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1313

1414
### Removed
1515

16+
## [1.0.2] - 2021-10-16
17+
18+
### Added
19+
20+
### Changed
21+
22+
- `getTypeof` returns `class` for `Date`
23+
24+
### Removed
25+
1626
## [1.0.1] - 2021-10-16
1727

1828
### Added

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@techmmunity/utils",
3-
"version": "1.0.1",
3+
"version": "1.0.2",
44
"main": "index.js",
55
"types": "index.d.ts",
66
"license": "Apache-2.0",
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
export const isClass = (value: any) => {
22
if (value.toString().startsWith("class")) return true;
33

4-
return ["String", "Number", "Boolean", "Object", "Array"].includes(
4+
return ["String", "Number", "Boolean", "Object", "Array", "Date"].includes(
55
value.name,
66
);
77
};

src/tests/get-typeof.spec.ts

Lines changed: 61 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ describe("getTypeof Util", () => {
8080
});
8181

8282
describe('type "class"', () => {
83-
it('should return "class" with an native javascript class', () => {
83+
it('should return "class" with an native javascript class (String)', () => {
8484
let result: any;
8585

8686
try {
@@ -92,6 +92,66 @@ describe("getTypeof Util", () => {
9292
expect(result).toBe("class");
9393
});
9494

95+
it('should return "class" with an native javascript class (Number)', () => {
96+
let result: any;
97+
98+
try {
99+
result = getTypeof(Number);
100+
} catch (err: any) {
101+
result = err;
102+
}
103+
104+
expect(result).toBe("class");
105+
});
106+
107+
it('should return "class" with an native javascript class (Object)', () => {
108+
let result: any;
109+
110+
try {
111+
result = getTypeof(Object);
112+
} catch (err: any) {
113+
result = err;
114+
}
115+
116+
expect(result).toBe("class");
117+
});
118+
119+
it('should return "class" with an native javascript class (Date)', () => {
120+
let result: any;
121+
122+
try {
123+
result = getTypeof(Date);
124+
} catch (err: any) {
125+
result = err;
126+
}
127+
128+
expect(result).toBe("class");
129+
});
130+
131+
it('should return "class" with an native javascript class (Boolean)', () => {
132+
let result: any;
133+
134+
try {
135+
result = getTypeof(Boolean);
136+
} catch (err: any) {
137+
result = err;
138+
}
139+
140+
expect(result).toBe("class");
141+
});
142+
143+
it('should return "class" with an native javascript class (Array)', () => {
144+
let result: any;
145+
146+
try {
147+
result = getTypeof(Array);
148+
} catch (err: any) {
149+
result = err;
150+
}
151+
152+
expect(result).toBe("class");
153+
});
154+
95155
it('should return "class" with a custom class', () => {
96156
let result: any;
97157

0 commit comments

Comments
 (0)