Skip to content

Commit 76b6fb5

Browse files
update
1 parent dab3691 commit 76b6fb5

File tree

6 files changed

+31
-28
lines changed

6 files changed

+31
-28
lines changed

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

recipes/util-is/README.md

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -76,49 +76,52 @@ if (util.isUndefined(someValue)) {
7676
**After:**
7777

7878
```js
79+
80+
7981
if (Array.isArray(someValue)) {
80-
console.log('someValue is an array');
82+
console.log('someValue is an array');
8183
}
8284
if (typeof someValue === 'boolean') {
83-
console.log('someValue is a boolean');
85+
console.log('someValue is a boolean');
8486
}
8587
if (Buffer.isBuffer(someValue)) {
86-
console.log('someValue is a buffer');
88+
console.log('someValue is a buffer');
8789
}
8890
if (someValue instanceof Date) {
89-
console.log('someValue is a date');
91+
console.log('someValue is a date');
9092
}
91-
if (someValue instanceof Error) {
92-
console.log('someValue is an error');
93+
if (Error.isError(someValue)) {
94+
console.log('someValue is an error');
9395
}
9496
if (typeof someValue === 'function') {
95-
console.log('someValue is a function');
97+
console.log('someValue is a function');
9698
}
9799
if (someValue === null) {
98-
console.log('someValue is null');
100+
console.log('someValue is null');
99101
}
100102
if (someValue == null) {
101-
console.log('someValue is null or undefined');
103+
console.log('someValue is null or undefined');
102104
}
103105
if (typeof someValue === 'number') {
104-
console.log('someValue is a number');
106+
console.log('someValue is a number');
105107
}
106-
if (typeof someValue === 'object' && someValue !== null) {
107-
console.log('someValue is an object');
108+
if (someValue && typeof someValue === 'object') {
109+
console.log('someValue is an object');
108110
}
109-
if (someValue !== Object(someValue)) {
110-
console.log('someValue is a primitive');
111+
if (Object(someValue) !== someValue) {
112+
console.log('someValue is a primitive');
111113
}
112114
if (someValue instanceof RegExp) {
113-
console.log('someValue is a regular expression');
115+
console.log('someValue is a regular expression');
114116
}
115117
if (typeof someValue === 'string') {
116-
console.log('someValue is a string');
118+
console.log('someValue is a string');
117119
}
118120
if (typeof someValue === 'symbol') {
119-
console.log('someValue is a symbol');
121+
console.log('someValue is a symbol');
120122
}
121123
if (typeof someValue === 'undefined') {
122-
console.log('someValue is undefined');
124+
console.log('someValue is undefined');
123125
}
126+
124127
```

recipes/util-is/codemod.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
schema_version: "1.0"
2-
name: nodejs/util-is
3-
version: 0.0.1
2+
name: "@nodejs/util-is"
3+
version: 1.0.0
44
description: ""
55
author: Augustin Mauroy
66
license: MIT

recipes/util-is/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@nodejs/util-is",
3-
"version": "0.0.1",
3+
"version": "1.0.0",
44
"description": "",
55
"type": "module",
66
"scripts": {

recipes/util-is/src/workflow.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,13 @@ export default function transform(root: SgRoot): string | null {
3434
'isBoolean': (arg: string) => `typeof ${arg} === 'boolean'`,
3535
'isBuffer': (arg: string) => `Buffer.isBuffer(${arg})`,
3636
'isDate': (arg: string) => `${arg} instanceof Date`,
37-
'isError': (arg: string) => `Object.prototype.toString(${arg}) === '[object Error]' || ${arg} instanceof Error `,
37+
'isError': (arg: string) => `Error.isError(${arg})`,
3838
'isFunction': (arg: string) => `typeof ${arg} === 'function'`,
3939
'isNull': (arg: string) => `${arg} === null`,
40-
'isNullOrUndefined': (arg: string) => `${arg} === null || ${arg} === undefined`,
40+
'isNullOrUndefined': (arg: string) => `${arg} == null`,
4141
'isNumber': (arg: string) => `typeof ${arg} === 'number'`,
4242
'isObject': (arg: string) => `${arg} && typeof ${arg} === 'object'`,
43-
'isPrimitive': (arg: string) => `${arg} === null || (typeof ${arg} !=='object' && typeof ${arg} !== 'function')`,
43+
'isPrimitive': (arg: string) => `Object(${arg}) !== ${arg}`,
4444
'isRegExp': (arg: string) => `${arg} instanceof RegExp`,
4545
'isString': (arg: string) => `typeof ${arg} === 'string'`,
4646
'isSymbol': (arg: string) => `typeof ${arg} === 'symbol'`,

recipes/util-is/tests/expected/file-1.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ if (Buffer.isBuffer(someValue)) {
1212
if (someValue instanceof Date) {
1313
console.log('someValue is a date');
1414
}
15-
if (Object.prototype.toString(someValue) === '[object Error]' || someValue instanceof Error ) {
15+
if (Error.isError(someValue)) {
1616
console.log('someValue is an error');
1717
}
1818
if (typeof someValue === 'function') {
@@ -21,7 +21,7 @@ if (typeof someValue === 'function') {
2121
if (someValue === null) {
2222
console.log('someValue is null');
2323
}
24-
if (someValue === null || someValue === undefined) {
24+
if (someValue == null) {
2525
console.log('someValue is null or undefined');
2626
}
2727
if (typeof someValue === 'number') {
@@ -30,7 +30,7 @@ if (typeof someValue === 'number') {
3030
if (someValue && typeof someValue === 'object') {
3131
console.log('someValue is an object');
3232
}
33-
if (someValue === null || (typeof someValue !=='object' && typeof someValue !== 'function')) {
33+
if (Object(someValue) !== someValue) {
3434
console.log('someValue is a primitive');
3535
}
3636
if (someValue instanceof RegExp) {

0 commit comments

Comments
 (0)