Learn more  » Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Bower components Debian packages RPM packages NuGet packages

skava / exotic   js

Repository URL to install this package:

Version: 2.0.8 

/ src / types / array / pairs / isPairs.ts

import isArrayOf from '../../array/check/isArrayOf'
import isSize from '../../attributes/properties/isSize'
import { PairedArrayOf } from './Pairs.typings'

const isTwo = (size: number) => size === 2

// @TODO can also add "isPairsLike" to just check ONE
// @TODO can also do this
// const firstOfFirst = pipeTwo(first, first)
// isPairs = x =>
//   multiDimensionalArray(x) && isStringOrNumber(firstOfFirst(x))

/* prettier-ignore */
/**
 * @since 5.0.0-beta.9
 * @memberOf is
 *
 * @name isPairs
 * @alias isArrayPairs
 * @alias isArrayOfPairs
 * @alias isPairedArray
 * @alias isMultiDimensionalArray
 * @alias isNestedArray
 *
 * @param {Array<Array> | *} x possible pairs
 * @return {boolean} x isPairs
 *
 * @TODO @FIXME @HACK @TIME remove the `isTwo`
 * @see is/arrayOf
 * @NOTE could also be written similar to `pipeTwo(first, isArray)`
 *
 * @example isPairs([[1, 2], [1, 2]]) //=> true
 * @example isPairs([[1], [1, 2]])    //=> false
 * @example isPairs([])               //=> false
 *
 */
function isPairs<Type>(x: any): x is PairedArrayOf<Type> {
  return isArrayOf(
    isArrayOf(
      isSize(isTwo)
    )
  )
}

export { isPairs }
export default isPairs