Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>JS Bin</title>
</head>
<body>
<script src="https://cdnjs.cloudflare.com/ajax/libs/ramda/0.22.1/ramda.min.js"></script>
  <script src="https://unpkg.com/spected@0.5.0/dist/spected.min.js"></script>
</body>
</html>
 
const spected = Spected.default
const validate = Spected.validate
const successFn = () => null
const failureFn = a => a
const data = {
  nr: 4,
  name: 'foobar'
}
const spec = {
  nr: [[ nr => nr > 2, 'Nr has to be greater than 2' ]],
  name: [[ name => name.length > 4, 'Name has to be minimum lenght of 5!' ]]
}
const specialSpected = validate(successFn, failureFn)
const r1 = specialSpected(spec, data)
const isValid = input => Object.values(input).filter(x => x !== null).length === 0 
// or functional...
// const isValid = R.compose(R.isEmpty, R.filter(R.identity), R.values)
console.log(r1, isValid(r1))
Output

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
anonymouspro
0viewers