1+ /**
2+ * Creates an error object with ERR_INVALID_ARG_TYPE code
3+ * @param {string } message - The error message
4+ * @returns {Error } Error with code ERR_INVALID_ARG_TYPE
5+ */
16function ERR_INVALID_ARG_TYPE ( message ) {
27 const err = new Error ( message ) ;
38 err . code = "ERR_INVALID_ARG_TYPE" ;
49 return err ;
510}
611
12+ /**
13+ * Creates an error object with ERR_INVALID_ARG_VALUE code
14+ * @param {string } message - The error message
15+ * @returns {Error } Error with code ERR_INVALID_ARG_VALUE
16+ */
717function ERR_INVALID_ARG_VALUE ( message ) {
818 const err = new Error ( message ) ;
919 err . code = "ERR_INVALID_ARG_VALUE" ;
1020 return err ;
1121}
1222
23+ /**
24+ * Validates that a value is a number within an optional range
25+ * @param {any } value - The value to validate
26+ * @param {string } name - Name of the parameter being validated
27+ * @param {number } [min] - Optional minimum value (inclusive)
28+ * @param {number } [max] - Optional maximum value (inclusive)
29+ * @throws {Error } If validation fails
30+ */
1331function validateNumber ( value , name , min , max ) {
1432 if ( typeof value !== "number" )
1533 throw ERR_INVALID_ARG_TYPE (
@@ -27,6 +45,12 @@ function validateNumber(value, name, min, max) {
2745 }
2846}
2947
48+ /**
49+ * Validates that a value is an object (not null and not an array)
50+ * @param {any } value - The value to validate
51+ * @param {string } name - Name of the parameter being validated
52+ * @throws {Error } If validation fails
53+ */
3054function validateObject ( value , name ) {
3155 if ( value === null || Array . isArray ( value ) ) {
3256 throw ERR_INVALID_ARG_TYPE (
@@ -41,20 +65,38 @@ function validateObject(value, name) {
4165 }
4266}
4367
68+ /**
69+ * Validates that a value is a function
70+ * @param {any } value - The value to validate
71+ * @param {string } name - Name of the parameter being validated
72+ * @throws {Error } If validation fails
73+ */
4474function validateFunction ( value , name ) {
4575 if ( typeof value !== "function" )
4676 throw ERR_INVALID_ARG_TYPE (
4777 `value must be a function, name: ${ name } , value: ${ value } ` ,
4878 ) ;
4979}
5080
81+ /**
82+ * Validates that a value is a string
83+ * @param {any } value - The value to validate
84+ * @param {string } name - Name of the parameter being validated
85+ * @throws {Error } If validation fails
86+ */
5187function validateString ( value , name ) {
5288 if ( typeof value !== "string" )
5389 throw ERR_INVALID_ARG_TYPE (
5490 `value must be a string, name: ${ name } , value: ${ value } ` ,
5591 ) ;
5692}
5793
94+ /**
95+ * Validates that a value is an array
96+ * @param {any } value - The value to validate
97+ * @param {string } name - Name of the parameter being validated
98+ * @throws {Error } If validation fails
99+ */
58100function validateArray ( value , name ) {
59101 if ( ! Array . isArray ( value ) )
60102 throw ERR_INVALID_ARG_TYPE (
0 commit comments