Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor kind logic, add enum, tuple, dict, union, intersection #28

Merged
merged 1 commit into from Dec 2, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/error.js
Expand Up @@ -8,14 +8,15 @@
class StructError extends TypeError {

constructor(attrs) {
const { data, value, type, path = [] } = attrs
const message = `Expected a value of type "${type}" ${path.length ? `for \`${path.join('.')}\`` : ''} but received \`${value}\`.`
const { data, value, type, path, errors = [] } = attrs
const message = `Expected a value of type \`${type}\`${path.length ? ` for \`${path.join('.')}\`` : ''} but received \`${value}\`.`
super(message)
this.data = data
this.path = path
this.value = value
this.type = type
this.errors = [this]
this.errors = errors
if (!errors.length) errors.push(this)
Error.captureStackTrace(this, this.constructor)
}

Expand Down
28 changes: 28 additions & 0 deletions src/is-struct.js
@@ -0,0 +1,28 @@

/**
* A private string to identify structs by.
*
* @type {String}
*/

const IS_STRUCT = '@@__STRUCT__@@'

/**
* Check if a `value` is a struct.
*
* @param {Any} value
* @return {Boolean}
*/

function isStruct(value) {
return !!(value && value[IS_STRUCT])
}

/**
* Export.
*
* @type {Function}
*/

export default isStruct
export { IS_STRUCT }