Skip to content

Commit

Permalink
improve jsdoc and parameter names (#223)
Browse files Browse the repository at this point in the history
  • Loading branch information
Uzlopak authored Jun 26, 2023
1 parent a67e164 commit 07614c0
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 15 deletions.
20 changes: 16 additions & 4 deletions lib/create-promise.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,31 @@
'use strict'

/**
* @callback PromiseResolve
* @param {any|PromiseLike<any>} value
* @returns {void}
*/

/**
* @callback PromiseReject
* @param {any} reason
* @returns {void}
*/

/**
* @typedef PromiseObject
* @property {Promise} promise
* @property {PromiseConstructor["resolve"]} resolve
* @property {PromiseConstructor["reject"]} reject
* @property {PromiseResolve} resolve
* @property {PromiseReject} reject
*/

/**
* @returns {PromiseObject}
*/
function createPromise () {
/**
* @type {PromiseObject}
*/
* @type {PromiseObject}
*/
const obj = {
resolve: null,
reject: null,
Expand Down
11 changes: 7 additions & 4 deletions lib/is-bundled-or-typescript-plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,15 @@
*/

/**
* @param {unknown} plugin
* @param {any} maybeBundledOrTypescriptPlugin
* @returns {plugin is BundledOrTypescriptPlugin}
*/

function isBundledOrTypescriptPlugin (plugin) {
return plugin !== null && typeof plugin === 'object' && typeof plugin.default === 'function'
function isBundledOrTypescriptPlugin (maybeBundledOrTypescriptPlugin) {
return (
maybeBundledOrTypescriptPlugin !== null &&
typeof maybeBundledOrTypescriptPlugin === 'object' &&
typeof maybeBundledOrTypescriptPlugin.default === 'function'
)
}

module.exports = {
Expand Down
15 changes: 8 additions & 7 deletions lib/validate-plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,20 @@
const { AVV_ERR_PLUGIN_NOT_VALID } = require('./errors')

/**
* @param {unknown} plugin
* @param {any} maybePlugin
* @throws {AVV_ERR_PLUGIN_NOT_VALID}
* @returns {Function}
*
* @returns {asserts plugin is Function|PromiseLike}
*/
function validatePlugin (plugin) {
function validatePlugin (maybePlugin) {
// validate if plugin is a function or Promise
if (!(plugin && (typeof plugin === 'function' || typeof plugin.then === 'function'))) {
if (Array.isArray(plugin)) {
if (!(maybePlugin && (typeof maybePlugin === 'function' || typeof maybePlugin.then === 'function'))) {
if (Array.isArray(maybePlugin)) {
throw new AVV_ERR_PLUGIN_NOT_VALID('array')
} else if (plugin === null) {
} else if (maybePlugin === null) {
throw new AVV_ERR_PLUGIN_NOT_VALID('null')
} else {
throw new AVV_ERR_PLUGIN_NOT_VALID(typeof plugin)
throw new AVV_ERR_PLUGIN_NOT_VALID(typeof maybePlugin)
}
}
}
Expand Down

0 comments on commit 07614c0

Please sign in to comment.