Clause
(0.0.23)Introduction
Concepts
API
- clause.compose
- clause.compose.string
- clause.utils
- clause.preds
- clause.namespace
- clause.types
Clause (js)
(
API docs and the index table are auto-generated with spec-docgen.
To contribute to API notes & examples, make a pull request to annotation source files here.)
Introduction
Refer to README file for basic intro.What is Conformation?
To put it plainly, as a developer you expect your data to be of certain "shape".
You define the shape of the data with clauses.
To "conform" your data with your clauses is to shape it in a way that is better organized, making it easier for your code to consume.
[TODO: more write-up]
Regex-like Operations on Iterables
Both array and string are treated as iterables in Clause, which means both types can be the subject of regex-like operations.
For example, both of the following clause definitions are valid:
Array
var ArrayClause = C.cat('foos', C.oneOrMore(C.equal('foo')),
'bars', C.oneOrMore(C.equal('bar')));
C.conform(ArrayClause, ['foo', 'foo', 'foo', 'bar', 'bar']);
String
var StrClause = C.cat('foos', C.oneOrMore(C.sCat('foo')),
'bars', C.oneOrMore(C.sCat('bar')));
C.conform(StrClause, 'foofoofoobarbar');
Notice that in the first clause, we use C.equals()
to treat
the string as a single entity, whereas in the second, we use
C.sCat()
to indicate that each character in the string is
part of the collection that we run regex ops on.
API
Work in progress.
Below is a set of auto-generated API reference by
clausejs-docgen based on clause declarations and their corrosponding annotations.
Should be one of the following:
Should satisfy all of the following expression:
Should be an ordered list of the following:
Should be one of the following:
Should be one of the following:
Should be an ordered list of the following:
Should be an ordered list of the following:
Should satisfy all of the following expression:
Should be an ordered list of the following:
Should be one of the following:
Should be one of the following:
Should be an ordered list of the following:
Should be an ordered list of the following:
Should be an ordered list of the following:
Should be an ordered list of the following:
Should be an ordered list of the following:
Should be an ordered list of the following:
Should be an ordered list of the following:
Should be an ordered list of the following:
Should be an ordered list of the following:
Should be an ordered list of the following:
Should be an ordered list of the following:
Should be an ordered list of the following:
Should be an ordered list of the following:
Should be an ordered list of the following:
Should be an ordered list of the following:
Should be an ordered list of the following:
Should be one of the following:
Should be an ordered list of the following:
Should be an ordered list of the following:
Should be an ordered list of the following:
Should be an ordered list of the following:
Should be one of the following:
Should be an ordered list of the following:
Should be an ordered list of the following:
Should be an ordered list of the following:
Should be an ordered list of the following:
Should be an ordered list of the following:
Should be an ordered list of the following:
Should be an ordered list of the following:
Should be an ordered list of the following:
Should be an ordered list of the following:
Should be an ordered list of the following:
Should be an ordered list of the following:
Should be an ordered list of the following:
Should be an ordered list of the following:
Should be an ordered list of the following:
Should be an ordered list of the following:
Should be an ordered list of the following:
Should be an ordered list of the following:
Should be an ordered list of the following:
Should be an ordered list of the following:
Should be an ordered list of the following:
Should be an ordered list of the following:
Should be an ordered list of the following:
Should be an ordered list of the following:
Should be an ordered list of the following:
Should be an ordered list of the following:
Should be an ordered list of the following:
Should be an ordered list of the following:
Should be one of the following:
Should be an ordered list of the following:
Should be one of the following:
Should be one of the following:
Should be one of the following:
Should be one of the following:
Should be an ordered list of the following:
Should be an ordered list of the following:
Should be one of the following:
Should be an ordered list of the following:
Should be one of the following:
Should be one of the following:
Should satisfy all of the following expression:
Should satisfy all of the following expression:
Should be an ordered list of the following:
Should be one of the following:
Should satisfy all of the following expression:
Should satisfy all of the following expression:
C
function
C("awesomeapp/TodoItem", TodoItemClause)
var ref = C("awesomeapp/TodoItem");
ref.get()
fclause( {
<args>: or(
"register", cat(
"nsPath", NamespacePath,
"expression", Expression
),
"retrieve", cat( "nsPath", NamespacePath )
),
<ret>: or(
Undefined,
ClauseReference
)
} )
clause.compose/
cat()
function
fclause( {
<args>: and(
cat(
"expressions", or(
"withLabels", or(
zeroOrMore( cat(
"name", ClauseLabel,
"comment", zeroOrOne( String ),
"expr", Expression
) ),
collOf( cat(
"name", ClauseLabel,
"comment", zeroOrOne( String ),
"expr", Expression
) )
),
"withoutLabels", zeroOrMore( Expression )
),
"options", zeroOrOne( PlainObject )
),
noDupelicateLabels
),
<ret>: Clause
} )
or()
function
fclause( {
<args>: and(
cat(
"expressions", or(
"withLabels", or(
zeroOrMore( cat(
"name", ClauseLabel,
"comment", zeroOrOne( String ),
"expr", Expression
) ),
collOf( cat(
"name", ClauseLabel,
"comment", zeroOrOne( String ),
"expr", Expression
) )
),
"withoutLabels", zeroOrMore( Expression )
),
"options", zeroOrOne( PlainObject )
),
noDupelicateLabels
),
<ret>: Clause
} )
zeroOrMore()
function
fclause( {
<args>: cat(
"expr", Expression,
"opts", zeroOrOne( Object )
),
<ret>: Clause
} )
oneOrMore()
function
fclause( {
<args>: cat(
"expr", Expression,
"opts", zeroOrOne( Object )
),
<ret>: Clause
} )
zeroOrOne()
function
fclause( {
<args>: cat(
"expr", Expression,
"opts", zeroOrOne( Object )
),
<ret>: Clause
} )
and()
function
fclause( {
<args>: oneOrMore( Expression ),
<ret>: Clause
} )
collOf()
function
fclause( {
<args>: cat(
"expr", Expression,
"opts", zeroOrOne( Object )
),
<ret>: Clause
} )
mapOf()
function
fclause( {
<args>: cat(
"keyExpression", Expression,
"valExpression", Expression
),
<ret>: Clause
} )
shape()
function
fclause( {
<args>: cat( "shapeArgs", shape( {
<optional>: {
"requiredFields": {
<key>: oneOf("req", "required"),
<val>: or(
"keyList", zeroOrMore( isPropName ),
"fieldDefs", mapOf( {
<key>: String,
<val>: or(
"valExpressionOnly", Expression,
"keyValExprPair", cat(
"keyExpression", Expression,
"valExpression", Expression
)
)
} )
)
},
"optionalFields": {
<key>: oneOf("opt", "optional"),
<val>: or(
"keyList", zeroOrMore( isPropName ),
"fieldDefs", mapOf( {
<key>: String,
<val>: or(
"valExpressionOnly", Expression,
"keyValExprPair", cat(
"keyExpression", Expression,
"valExpression", Expression
)
)
} )
)
}
}
} ) ),
<ret>: Clause
} )
any()
function
fclause( {
<ret>: Clause
} )
wall()
function
fclause( {
<args>: cat( Expression ),
<ret>: Expression
} )
fclause()
function
fclause( {
<args>: cat( shape( {
<optional>: {
"args": and(
isArray,
Expression
),
"ret": Expression,
"fn": fclause( {
<args>: cat(
"conformedArguments", any,
"conformedReturnValue", any
),
<ret>: any
} )
}
} ) )
} )
nullable()
function
fclause( {
<args>: cat( Expression ),
<ret>: Clause
} )
undefinable()
function
fclause( {
<args>: cat( Expression ),
<ret>: Clause
} )
maybe()
function
fclause( {
<args>: cat( Expression ),
<ret>: Clause
} )
clause.compose.string/
sCat()
function
var StrClause = C.cat('part1', C.zeroOrMore(C.sCat('foo')),
'part2.5', C.zeroOrMore(C.sCat('i am optional')),
'part2', C.zeroOrMore(C.sCat('bar')));
C.conform(StrClause, 'foofoofoobarbar');
fclause( {
<args>: cat( "string", String ),
<ret>: Clause
} )
clause.utils/
enforce()
function
fclause( {
<args>: cat(
"expression", Expression,
"valueToCheck", any()
),
<ret>: Undefined
} )
conform()
function
fclause( {
<args>: cat(
"expression", Expression,
"valueToConform", any()
),
<ret>: or(
"conformedValue", any(),
"problem", Problem
)
} )
delayed()
function
fclause( {
<args>: cat( "getFn", fclause( {
<args>: cat(),
<ret>: Expression
} ) ),
<ret>: DelayedClause
} )
describe()
function
fclause( {
<args>: cat(
"expression", Expression,
"replacer", zeroOrOne( fclause( {
<args>: cat( Expression ),
<ret>: or(
Undefined,
Null,
collOf( String )
)
} ) ),
"space", zeroOrOne( isNatInt )
),
<ret>: String
} )
sExpression()
function
fclause( {
<args>: cat( "expression", Expression ),
<ret>: SExpression
} )
clause.preds/
not()
function
fclause( {
<args>: cat( "predicateToNegate", Predicate ),
<ret>: fclause( {
<args>: cat( "x", any() ),
<ret>: Bool
} )
} )
isObj()
function
fclause( {
<args>: cat( "x", any() ),
<ret>: Bool
} )
isPlainObj()
function
fclause( {
<args>: cat( "x", any() ),
<ret>: Bool
} )
isStr()
function
fclause( {
<args>: cat( "x", any() ),
<ret>: Bool
} )
isArray()
function
fclause( {
<args>: cat( "x", any() ),
<ret>: Bool
} )
isDate()
function
fclause( {
<args>: cat( "x", any() ),
<ret>: Bool
} )
isNull()
function
fclause( {
<args>: cat( "x", any() ),
<ret>: Bool
} )
isUndefined()
function
fclause( {
<args>: cat( "x", any() ),
<ret>: Bool
} )
notEmpty()
function
fclause( {
<args>: cat( "x", any() ),
<ret>: Bool
} )
isBool()
function
fclause( {
<args>: cat( "x", any() ),
<ret>: Bool
} )
isFn()
function
fclause( {
<args>: cat( "x", any() ),
<ret>: Bool
} )
isNum()
function
fclause( {
<args>: cat( "x", any() ),
<ret>: Bool
} )
isInt()
function
fclause( {
<args>: cat( "x", any() ),
<ret>: Bool
} )
isNatInt()
function
fclause( {
<args>: cat( "x", any() ),
<ret>: Bool
} )
isUuid()
function
fclause( {
<args>: cat( "x", String ),
<ret>: Bool
} )
oneOf()
function
fclause( {
<args>: cat( "valueOptions", collOf( Primitive ) ),
<ret>: fclause( {
<args>: cat( "x", any() ),
<ret>: Bool
} )
} )
equals()
function
fclause( {
<args>: cat( "valueToCompareWith", any() ),
<ret>: fclause( {
<args>: cat( "x", any() ),
<ret>: Bool
} )
} )
instanceOf()
function
fclause( {
<args>: cat( "instanceType", isFunction ),
<ret>: fclause( {
<args>: cat( "x", any() ),
<ret>: Bool
} )
} )
clause.namespace/
set()
function
fclause( {
<args>: cat(
"nsPath", NamespacePath,
"expression", Expression
),
<ret>: Bool
} )
get()
function
fclause( {
<args>: cat( "nsPath", NamespacePath ),
<ret>: ClauseReference
} )
resolve()
function
fclause( {
<args>: cat(
"expression", Expression,
"registry", zeroOrOne( Object )
),
<ret>: NamespacePath
} )
setMeta()
function
fclause( {
<args>: cat(
"source", or(
"namespacePath", NamespacePath,
"expression", Expression
),
"metaObj", Object,
"registry", zeroOrOne( Object )
),
<ret>: Undefined
} )
getMeta()
function
fclause( {
<args>: cat(
"source", or(
"namespacePath", NamespacePath,
"expression", Expression
),
"registry", zeroOrOne( Object )
),
<ret>: or(
Null,
Undefined,
Object
)
} )
clause.types/
Expression
or
Primitive
or
Clause
predicate
FClause
predicate
Predicate
function
fclause( {
<args>: cat( "x", any() ),
<ret>: Bool
} )
DelayedClause
predicate
ClauseReference
predicate
Problem
predicate
NamespaceObj
shape
NamespacePath
predicate
ClauseLabel
predicate
SExpression
wall
String
predicate
Bool
predicate
Number
predicate
Object
predicate
PlainObject
predicate
Undefined
predicate
Null
predicate