busypeoples / spected

Validation library
MIT License
703 stars 32 forks source link

Documentation suggests I can do something I cannot #4

Closed bookercodes closed 7 years ago

bookercodes commented 7 years ago

The documentation says,

Calling validate spected(validationRules, inputData) should return

Which would suggest I can do something like this,

const spected = require('spected')

const isGreaterThan = num => num > 5
const hasCapitalLetter = text => /[A-Z]/.test(text)

const validationRules = {
  name: [
    [ isGreaterThan(5),
      `Minimum Name length of 6 is required.`
    ],
  ],
  random: [
    [ isGreaterThan(7), 'Minimum Random length of 8 is required.' ],
    [ hasCapitalLetter, 'Random should contain at least one uppercase letter.' ],
  ]
}

const inputData = { name: 'abcdef', random: 'z'}

const res = spected(validationRules, inputData)

console.log(res)

However, spected is not a function

Just a little kink in the onboarding, which would be good to solve with better documentation!

bookercodes commented 7 years ago

Ah, I realise this is probably because I did require('spected') instead of require('spected').default!

busypeoples commented 7 years ago

Yes, require('spected').default should solve the problem. Let me know if there is still some trouble.

bookercodes commented 7 years ago

Thanks @busypeoples! I am encountering an error, but I have created a separate issue for that (easier for newcomers to search)