[d24f17c] | 1 | import { both, anyPass } from 'ramda';
|
---|
| 2 |
|
---|
| 3 | import isNotObj from './isNotObj';
|
---|
| 4 | import isString from './isString';
|
---|
| 5 | import isNumber from './isNumber';
|
---|
| 6 | import isBigInt from './isBigInt';
|
---|
| 7 | import isBoolean from './isBoolean';
|
---|
| 8 | import isUndefined from './isUndefined';
|
---|
| 9 | import isNull from './isNull';
|
---|
| 10 | import isSymbol from './isSymbol';
|
---|
| 11 |
|
---|
| 12 | /**
|
---|
| 13 | * Checks if value is a primitive data type. There are 6 primitive data types: `string`, `number`, `bigint`, `boolean`, `undefined`, `symbol` and a special case of `null`.
|
---|
| 14 | * See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Primitive_values
|
---|
| 15 | * for definition of what sub-types comprise a primitive.
|
---|
| 16 | *
|
---|
| 17 | * @func isPrimitive
|
---|
| 18 | * @memberOf RA
|
---|
| 19 | * @category Type
|
---|
| 20 | * @sig * -> Boolean
|
---|
| 21 | * @since {@link https://char0n.github.io/ramda-adjunct/2.32.0|v2.32.0}
|
---|
| 22 | * @param {*} val The value to test
|
---|
| 23 | * @return {boolean}
|
---|
| 24 | * @see {@link RA.isNotPrimitive|isNotPrimitive}, {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#primitive_values|MDN Primitive values}, {@link https://developer.mozilla.org/en-US/docs/Glossary/Primitive|MDN Primitive}
|
---|
| 25 | * @example
|
---|
| 26 | *
|
---|
| 27 | * RA.isPrimitive("string"); //=> true
|
---|
| 28 | * RA.isPrimitive(1); //=> true
|
---|
| 29 | * RA.isPrimitive(new String("string")); //=> false
|
---|
| 30 | * RA.isPrimitive(new Number(1)); //=> false
|
---|
| 31 | */
|
---|
| 32 |
|
---|
| 33 | const isPrimitive = both(
|
---|
| 34 | isNotObj,
|
---|
| 35 | anyPass([
|
---|
| 36 | isString,
|
---|
| 37 | isNumber,
|
---|
| 38 | isBigInt,
|
---|
| 39 | isBoolean,
|
---|
| 40 | isUndefined,
|
---|
| 41 | isNull,
|
---|
| 42 | isSymbol,
|
---|
| 43 | ])
|
---|
| 44 | );
|
---|
| 45 |
|
---|
| 46 | export default isPrimitive;
|
---|