Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve jsdoc and parameter names #223

Merged
merged 1 commit into from
Jun 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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