@justinc/no-dups-validator

1.0.1 • Public • Published

no-dups-validator Build status NPM version License Semantic Release Js Standard Style

Checks for duplicates given an Iterable.

Install

npm i @justinc/no-dups-validator

Demo

(see tests for more examples)

const noDups = require('@justinc/no-dups-validator')
noDups([1, 2, 3])()
// [ true, [] ]

noDups([1, 2, 3, 2, 1])('Found the following duplicates: ')
// [ false, [ new Error('Found the following duplicates: 2, 1) ] ]

combine-validations

If you're OK with using Folktale Validation, you might be interested in combine-validations.

To use this package with combine-validations you will need to convert its output Tuple<Boolean, Array<Error>> to a Folktale Validation with something like this:

const Validation = require('data.validation')
const noDups = require('@justinc/no-dups-validator')
const combineValidations = require('@justinc/combine-validations')

const { Success, Failure } = Validation

const asValidation = ([isValid, errors]) => isValid ? Success(true) : Failure(errors)

const input = ['hello', 'world', 'hello']
const validation = combineValidations([
  asValidation(noDups(input)())
])

Tutorials

TODO: A JSDoc 3 tutorial (re currying) needs to be injected in this README.md. For now there's only a link:

  • tutorial: curry.md
  • issue: jsdoc2md/jsdoc-to-markdown#115

Modules

@justinc/no-dups-validator
@justinc/jsdocs

This module houses JSDoc 3 type definitions which can be re-used in different packages.

@justinc/no-dups-validator

@justinc/no-dups-validator~noDups([iterable], [errMsgPrefix]) ⇒ Tuple.<Boolean, Array.<Error>>

This function is curried.

Kind: inner method of @justinc/no-dups-validator
See: Tuple

Param Type Default Description
[iterable] Iterable [] The iterable whose elements are checked for duplicates
[errMsgPrefix] String '' A string to prefix any found duplicates in the error message

@justinc/jsdocs

This module houses JSDoc 3 type definitions which can be re-used in different packages.

@justinc/jsdocs.Tuple : Array

The type Tuple is an Array of fixed length whose elements at specific indices are of the specified types.

Kind: static typedef of @justinc/jsdocs
Example

// A Tuple of arity (length) 2, whose first el is a Boolean and second el is
// an Array of Error:
Tuple<Boolean, Array<Error>>
// e.g. [ true, [] ]
// e.g. [ false, [ new Error('computer says no') ] ]

Example

// A Tuple of arity (length) 3, whose first el is a String, and both the
// second and third els are an Array of String:
Tuple<String, Array<String>, Array<String>>
// e.g. [ 'hello', [ 'world' ], [ 'goodbye', 'world' ] ]

Package Sidebar

Install

npm i @justinc/no-dups-validator

Weekly Downloads

1

Version

1.0.1

License

MIT

Last publish

Collaborators

  • justinc