-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(package): replace lodash.hasin
Replace module lodash.hasin (4 KB) with private function objectHasPropertyName (500 B) #97
- Loading branch information
1 parent
ea5711f
commit 035db0f
Showing
6 changed files
with
38 additions
and
17 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
const get = require('lodash.get') | ||
const hasIn = require('lodash.hasin') | ||
const objectHasPropertyName = require('./object-has-property-name') | ||
const types = require('./types.json') | ||
|
||
const isType = (object, type) => | ||
hasIn(object, 'type') && object.type === get(types, type) | ||
const isType = (instance, type) => | ||
objectHasPropertyName(instance) && instance.type === get(types, type) | ||
|
||
module.exports = isType |
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 |
---|---|---|
@@ -1,11 +1,11 @@ | ||
const hasIn = require('lodash.hasin') | ||
const objectHasPropertyName = require('./object-has-property-name') | ||
const typeMap = require('./type-map') | ||
|
||
const isValueTypeOf = (value, type) => { | ||
if (hasIn(value, 'value')) { | ||
return typeMap.get(type)(value.value) | ||
const isValueTypeOf = (instance, type) => { | ||
if (objectHasPropertyName(instance, 'value')) { | ||
return typeMap.get(type)(instance.value) | ||
} | ||
return typeMap.get(type)(value) | ||
return typeMap.get(type)(instance) | ||
} | ||
|
||
module.exports = isValueTypeOf |
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 { | ||
isValid, | ||
object | ||
} = require('ow') | ||
|
||
/** | ||
* Determine whether a value is an object with a given property. | ||
* | ||
* @private | ||
* @param {*} instance - An ECMAScript variable. | ||
* @param {string} [propertyName='type'] - The name of the property | ||
* being searched for. | ||
* @returns {boolean} - `true` if the property exists; otherwise, `false`. | ||
*/ | ||
|
||
const objectHasPropertyName = (instance, propertyName = 'type') => { | ||
return isValid(instance, object) && | ||
Object.getOwnPropertyNames(instance).includes(propertyName) | ||
} | ||
|
||
module.exports = objectHasPropertyName |
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 |
---|---|---|
@@ -1,11 +1,11 @@ | ||
const hasIn = require('lodash.hasin') | ||
const is = require('@sindresorhus/is') | ||
const objectHasPropertyName = require('./object-has-property-name') | ||
|
||
const valueTypeOf = (value) => { | ||
if (hasIn(value, 'value')) { | ||
return is(value.value) | ||
const valueTypeOf = (instance) => { | ||
if (objectHasPropertyName(instance, 'value')) { | ||
return is(instance.value) | ||
} | ||
return is(value) | ||
return is(instance) | ||
} | ||
|
||
module.exports = valueTypeOf |