Skip to main content
Left closed in review as "Original close reason(s) were not resolved" by Adrian Mole, Toto, bguiz
added 71 characters in body
Source Link

Use case: I have an http request represented by an object and I want to check the fields of the object before I make an http call with the request(i.e. makeHttpCall(request)). For example, given the object below:

{ "classic": false, "billing-account": "1234567890", "device": "123456" } 

I want to validate the following fields from the object:

  • "classic" is a bool true/false
  • "billing-account" is a string with length 9
  • "device" value is a string with length 6

I want to be able to write a config that can be used to validate the fields, similar PropTypes or Formik. For example:

{ "classic": boolean "billing-account": string.length===9 "device": string.length===9 } 

UPDATE: yup is what I was looking for https://github.com/jquense/yup

Use case: I have an http request represented by an object and I want to check the fields of the object before I make an http call with the request(i.e. makeHttpCall(request)). For example, given the object below:

{ "classic": false, "billing-account": "1234567890", "device": "123456" } 

I want to validate the following fields from the object:

  • "classic" is a bool true/false
  • "billing-account" is a string with length 9
  • "device" value is a string with length 6

I want to be able to write a config that can be used to validate the fields, similar PropTypes or Formik. For example:

{ "classic": boolean "billing-account": string.length===9 "device": string.length===9 } 

Use case: I have an http request represented by an object and I want to check the fields of the object before I make an http call with the request(i.e. makeHttpCall(request)). For example, given the object below:

{ "classic": false, "billing-account": "1234567890", "device": "123456" } 

I want to validate the following fields from the object:

  • "classic" is a bool true/false
  • "billing-account" is a string with length 9
  • "device" value is a string with length 6

I want to be able to write a config that can be used to validate the fields, similar PropTypes or Formik. For example:

{ "classic": boolean "billing-account": string.length===9 "device": string.length===9 } 

UPDATE: yup is what I was looking for https://github.com/jquense/yup

Post Closed as "Duplicate" by CommunityBot, juliomalves, Lin Du
Source Link

How can I check the values of an object in JavaScript?

Use case: I have an http request represented by an object and I want to check the fields of the object before I make an http call with the request(i.e. makeHttpCall(request)). For example, given the object below:

{ "classic": false, "billing-account": "1234567890", "device": "123456" } 

I want to validate the following fields from the object:

  • "classic" is a bool true/false
  • "billing-account" is a string with length 9
  • "device" value is a string with length 6

I want to be able to write a config that can be used to validate the fields, similar PropTypes or Formik. For example:

{ "classic": boolean "billing-account": string.length===9 "device": string.length===9 }