Clause


(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:

var ArrayClause = C.cat('foos', C.oneOrMore(C.equal('foo')),
                    'bars', C.oneOrMore(C.equal('bar')));

C.conform(ArrayClause, ['foo', 'foo', 'foo', 'bar', 'bar']);
// returns { foos: ['foo', 'foo', 'foo'], bars: ['bar', 'bar'] };

var StrClause = C.cat('foos', C.oneOrMore(C.sEqual('foo')),
                    'bars', C.oneOrMore(C.sEqual('bar')));

C.conform(StrClause, 'foofoofoobarbar');
// returns { foos: 'foofoofoo', bars: 'barbarbar' };

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.sEqual() to suggest that each character in the string is part of a 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.

C()
  function
Registers or retrieves a clause from global clause regitry by path.
Synopsis
  • <register>:
      C(nsPath, expression)
  • <retrieve>:
      C(nsPath)
Argument clause
or (alts)

Should be one of the following:

  1. Option 1 <register> : Put the given expression onto the given path in the global clause registry.
    cat (concatenation) of

    Should be an ordered list of the following:

    1. 1st <nsPath>

      of predicate
      A value that satisfies isNamespacePath()
    2. 2nd <expression>

      of clause
      A value that is of clausejs.types/Expression
  2. Option 2 <retrieve> : Retrieves an expression from the given namespace path, or returns null if not found.
    cat (concatenation) of

    Should be an ordered list of the following:

    1. 1st <nsPath>

      of predicate
      A value that satisfies isNamespacePath()

clausejs.compose/


cat()
  function
Synopsis
AND
Argument clause
and

Should satisfy all of the following expression:

  1. Part 1
    cat (concatenation) of

    Should be an ordered list of the following:

    1. 1st <expressions>

      or (alts)

      Should be one of the following:

      1. Option 1 <withLabels>
        or (alts)

        Should be one of the following:

        1. Option 1
          zero or more of (*)
          cat (concatenation) of

          Should be an ordered list of the following:

          1. 1st <name>

            of predicate
            A value that satisfies isClauseName()
          2. 2nd <comment>

            optional (?)
            of predicate
            A value that satisfies isString()
            TODO
          3. 3rd <expr>

            of clause
            A value that is of clausejs.types/Expression
          TODO
        2. Option 2
          collection of
          cat (concatenation) of

          Should be an ordered list of the following:

          1. 1st <name>

            of predicate
            A value that satisfies isClauseName()
          2. 2nd <comment>

            optional (?)
            of predicate
            A value that satisfies isString()
            TODO
          3. 3rd <expr>

            of clause
            A value that is of clausejs.types/Expression
          TODO
      2. Option 2 <withoutLabels>
        zero or more of (*)
        of clause
        A value that is of clausejs.types/Expression
        TODO
    2. 2nd <options>

      optional (?)
      and

      Should satisfy all of the following expression:

      1. Part 1
        of predicate
        A value that satisfies isObject()
      2. Part 2
        of predicate
        A value that satisfies not_isExpr()
      TODO
  2. Part 2
    of predicate
    A value that satisfies noDupelicateLabels()
Return value clause
of predicate
A value that satisfies isClause()
or()
  function
Synopsis
AND
Argument clause
and

Should satisfy all of the following expression:

  1. Part 1
    cat (concatenation) of

    Should be an ordered list of the following:

    1. 1st <expressions>

      or (alts)

      Should be one of the following:

      1. Option 1 <withLabels>
        or (alts)

        Should be one of the following:

        1. Option 1
          zero or more of (*)
          cat (concatenation) of

          Should be an ordered list of the following:

          1. 1st <name>

            of predicate
            A value that satisfies isClauseName()
          2. 2nd <comment>

            optional (?)
            of predicate
            A value that satisfies isString()
            TODO
          3. 3rd <expr>

            of clause
            A value that is of clausejs.types/Expression
          TODO
        2. Option 2
          collection of
          cat (concatenation) of

          Should be an ordered list of the following:

          1. 1st <name>

            of predicate
            A value that satisfies isClauseName()
          2. 2nd <comment>

            optional (?)
            of predicate
            A value that satisfies isString()
            TODO
          3. 3rd <expr>

            of clause
            A value that is of clausejs.types/Expression
          TODO
      2. Option 2 <withoutLabels>
        zero or more of (*)
        of clause
        A value that is of clausejs.types/Expression
        TODO
    2. 2nd <options>

      optional (?)
      and

      Should satisfy all of the following expression:

      1. Part 1
        of predicate
        A value that satisfies isObject()
      2. Part 2
        of predicate
        A value that satisfies not_isExpr()
      TODO
  2. Part 2
    of predicate
    A value that satisfies noDupelicateLabels()
Return value clause
of predicate
A value that satisfies isClause()
zeroOrMore()
  function
Synopsis
    zeroOrMore(expr, opts)
Argument clause
cat (concatenation) of

Should be an ordered list of the following:

  1. 1st <expr>

    of clause
    A value that is of clausejs.types/Expression
  2. 2nd <opts>

    optional (?)
    of predicate
    A value that satisfies isObject()
    TODO
Return value clause
of predicate
A value that satisfies isClause()
oneOrMore()
  function
Synopsis
    oneOrMore(expr, opts)
Argument clause
cat (concatenation) of

Should be an ordered list of the following:

  1. 1st <expr>

    of clause
    A value that is of clausejs.types/Expression
  2. 2nd <opts>

    optional (?)
    of predicate
    A value that satisfies isObject()
    TODO
Return value clause
of predicate
A value that satisfies isClause()
zeroOrOne()
  function
Synopsis
    zeroOrOne(expr, opts)
Argument clause
cat (concatenation) of

Should be an ordered list of the following:

  1. 1st <expr>

    of clause
    A value that is of clausejs.types/Expression
  2. 2nd <opts>

    optional (?)
    of predicate
    A value that satisfies isObject()
    TODO
Return value clause
of predicate
A value that satisfies isClause()
and()
  function
Synopsis
O_OR_M
Argument clause
one or more of (+)
of clause
A value that is of clausejs.types/Expression
TODO
Return value clause
of predicate
A value that satisfies isClause()
collOf()
  function
Synopsis
Argument clause
cat (concatenation) of

Should be an ordered list of the following:

  1. 1st <expr>

    of clause
    A value that is of clausejs.types/Expression
  2. 2nd <opts>

    optional (?)
    of predicate
    A value that satisfies isObject()
    TODO
Return value clause
of predicate
A value that satisfies isClause()
mapOf()
  function
Synopsis
Argument clause
cat (concatenation) of

Should be an ordered list of the following:

  1. 1st <keyExpression>

    of clause
    A value that is of clausejs.types/Expression
  2. 2nd <valExpression>

    of clause
    A value that is of clausejs.types/Expression
Return value clause
of predicate
A value that satisfies isClause()
shape()
  function
Synopsis
    shape(shapeArgs)
Argument clause
cat (concatenation) of

Should be an ordered list of the following:

  1. 1st <shapeArgs>

    shape
    TODO
Return value clause
of predicate
A value that satisfies isClause()
any()
  function
Return value clause
of clause
A value that is of clausejs.types/Clause
wall()
  function
Synopsis
Argument clause
cat (concatenation) of

Should be an ordered list of the following:

  1. 1st
    of clause
    A value that is of clausejs.types/Expression
Return value clause
of clause
A value that is of clausejs.types/Expression
fclause()
  function
Synopsis
    fclause(fclauseFields)
Argument clause
cat (concatenation) of

Should be an ordered list of the following:

  1. 1st <fclauseFields>

    shape
    TODO
nullable()
  function
Synopsis
Argument clause
cat (concatenation) of

Should be an ordered list of the following:

  1. 1st
    of clause
    A value that is of clausejs.types/Expression
undefinable()
  function
Synopsis
Argument clause
cat (concatenation) of

Should be an ordered list of the following:

  1. 1st
    of clause
    A value that is of clausejs.types/Expression

clausejs.utils/


enforce()
  function
Synopsis
Argument clause
cat (concatenation) of

Should be an ordered list of the following:

  1. 1st <expression>

    of clause
    A value that is of clausejs.types/Expression
  2. 2nd <valueToCheck>

    any
    Any value.
Return value clause
of predicate
A value that satisfies isUndefined()
conform()
  function
Synopsis
Argument clause
cat (concatenation) of

Should be an ordered list of the following:

  1. 1st <expression>

    of clause
    A value that is of clausejs.types/Expression
  2. 2nd <valueToConform>

    any
    Any value.
Return value clause
or (alts)

Should be one of the following:

  1. Option 1 <conformedValue>
    any
    Any value.
  2. Option 2 <problem>
    of predicate
    A value that is of clausejs.types/Problem
delayed()
  function
Synopsis
    delayed(getFn)
Argument clause
cat (concatenation) of

Should be an ordered list of the following:

  1. 1st <getFn>

    of fclause (function)
    Return value clause
    of clause
    A value that is of clausejs.types/Expression
Return value clause
of clause
A value that is of clausejs.types/DelayedClause
C.describe()
  function
Returns an abbreviated description of the clause as a simple tree structure.
Synopsis
    C.describe()
Argument clause
cat (concatenation) of

Should be an ordered list of the following:

  1. 1st
    or (alts)
    A value that is of clausejs.types/Expression
Return value clause
of predicate
A value that satisfies isString()

clausejs.preds/


not()
  function
Synopsis
    not(predicateToNegate)
Argument clause
cat (concatenation) of

Should be an ordered list of the following:

  1. 1st <predicateToNegate>

    of predicate
    A value that is of clausejs.types/Predicate
Return value clause
of fclause (function)
Synopsis
    (x)
Argument clause
cat (concatenation) of

Should be an ordered list of the following:

  1. 1st <x>

    any
    Any value.
Return value clause
of predicate
A value that satisfies isBool()
isObj()
  function
Synopsis
    isObj(x)
Argument clause
cat (concatenation) of

Should be an ordered list of the following:

  1. 1st <x>

    any
    Any value.
Return value clause
of predicate
A value that satisfies isBool()
isStr()
  function
Synopsis
    isStr(x)
Argument clause
cat (concatenation) of

Should be an ordered list of the following:

  1. 1st <x>

    any
    Any value.
Return value clause
of predicate
A value that satisfies isBool()
isArray()
  function
Synopsis
    isArray(x)
Argument clause
cat (concatenation) of

Should be an ordered list of the following:

  1. 1st <x>

    any
    Any value.
Return value clause
of predicate
A value that satisfies isBool()
isDate()
  function
Synopsis
    isDate(x)
Argument clause
cat (concatenation) of

Should be an ordered list of the following:

  1. 1st <x>

    any
    Any value.
Return value clause
of predicate
A value that satisfies isBool()
isNull()
  function
Synopsis
    isNull(x)
Argument clause
cat (concatenation) of

Should be an ordered list of the following:

  1. 1st <x>

    any
    Any value.
Return value clause
of predicate
A value that satisfies isBool()
isUndefined()
  function
Synopsis
    isUndefined(x)
Argument clause
cat (concatenation) of

Should be an ordered list of the following:

  1. 1st <x>

    any
    Any value.
Return value clause
of predicate
A value that satisfies isBool()
notEmpty()
  function
Synopsis
    notEmpty(x)
Argument clause
cat (concatenation) of

Should be an ordered list of the following:

  1. 1st <x>

    any
    Any value.
Return value clause
of predicate
A value that satisfies isBool()
isBool()
  function
Synopsis
    isBool(x)
Argument clause
cat (concatenation) of

Should be an ordered list of the following:

  1. 1st <x>

    any
    Any value.
Return value clause
of predicate
A value that satisfies isBool()
isFn()
  function
Synopsis
    isFn(x)
Argument clause
cat (concatenation) of

Should be an ordered list of the following:

  1. 1st <x>

    any
    Any value.
Return value clause
of predicate
A value that satisfies isBool()
isNum()
  function
Synopsis
    isNum(x)
Argument clause
cat (concatenation) of

Should be an ordered list of the following:

  1. 1st <x>

    any
    Any value.
Return value clause
of predicate
A value that satisfies isBool()
isInt()
  function
Synopsis
    isInt(x)
Argument clause
cat (concatenation) of

Should be an ordered list of the following:

  1. 1st <x>

    any
    Any value.
Return value clause
of predicate
A value that satisfies isBool()
isNatInt()
  function
Synopsis
    isNatInt(x)
Argument clause
cat (concatenation) of

Should be an ordered list of the following:

  1. 1st <x>

    any
    Any value.
Return value clause
of predicate
A value that satisfies isBool()
isUuid()
  function
Synopsis
    isUuid(x)
Argument clause
cat (concatenation) of

Should be an ordered list of the following:

  1. 1st <x>

    any
    Any value.
Return value clause
of predicate
A value that satisfies isBool()
oneOf()
  function
Synopsis
    oneOf(valueOptions)
Argument clause
cat (concatenation) of

Should be an ordered list of the following:

  1. 1st <valueOptions>

    collection of
    or (alts)
    A value that is of clausejs.types/Primitive
    TODO
Return value clause
of fclause (function)
Synopsis
    (x)
Argument clause
cat (concatenation) of

Should be an ordered list of the following:

  1. 1st <x>

    any
    Any value.
Return value clause
of predicate
A value that satisfies isBool()
equals()
  function
Synopsis
    equals(valueToCompareWith)
Argument clause
cat (concatenation) of

Should be an ordered list of the following:

  1. 1st <valueToCompareWith>

    any
    Any value.
Return value clause
of fclause (function)
Synopsis
    (x)
Argument clause
cat (concatenation) of

Should be an ordered list of the following:

  1. 1st <x>

    any
    Any value.
Return value clause
of predicate
A value that satisfies isBool()
instanceOf()
  function
Synopsis
    instanceOf(instanceType)
Argument clause
cat (concatenation) of

Should be an ordered list of the following:

  1. 1st <instanceType>

    of predicate
    A value that satisfies isFunction()
Return value clause
of fclause (function)
Synopsis
    (x)
Argument clause
cat (concatenation) of

Should be an ordered list of the following:

  1. 1st <x>

    any
    Any value.
Return value clause
of predicate
A value that satisfies isBool()

clausejs.namespace/


set()
  function
Synopsis
    set(nsPath, expression)
Argument clause
cat (concatenation) of

Should be an ordered list of the following:

  1. 1st <nsPath>

    of predicate
    A value that satisfies isNamespacePath()
  2. 2nd <expression>

    of clause
    A value that is of clausejs.types/Expression
Return value clause
of predicate
A value that satisfies isUndefined()
get()
  function
Synopsis
    get(nsPath)
Argument clause
cat (concatenation) of

Should be an ordered list of the following:

  1. 1st <nsPath>

    of predicate
    A value that satisfies isNamespacePath()
Return value clause
of clause
A value that is of clausejs.types/Expression
meta()
  function
Synopsis
    meta(source, metaObj)
Argument clause
cat (concatenation) of

Should be an ordered list of the following:

  1. 1st <source>

    or (alts)

    Should be one of the following:

    1. Option 1 <namespacePath>
      of predicate
      A value that satisfies isNamespacePath()
    2. Option 2 <expression>
      of predicate
      A value that satisfies isExpr()
  2. 2nd <metaObj>

    of predicate
    A value that satisfies isObject()
Return value clause
of predicate
A value that satisfies isExpr()

clausejs.types/


Expression
  or

Should be one of the following:

  1. Option 1 <clause>
    of clause
    A value that is of clausejs.types/Clause
  2. Option 2 <pred>
    of clause
    A value that is of clausejs.types/Predicate
  3. Option 3 <delayedClause>
    of clause
    A value that is of clausejs.types/DelayedClause
  4. Option 4 <clauseRef>
    of clause
    A value that is of clausejs.types/ClauseReference
Clause
  predicate
A value that satisfies isClause()
FClause
  and

Should satisfy all of the following expression:

  1. Part 1
    of predicate
    A value that satisfies isFclause()
Predicate
  predicate
A value that satisfies isPred()
DelayedClause
  predicate
A value that satisfies isDelayedClause()
ClauseReference
  predicate
A value that satisfies isClauseRef()
Problem
  predicate
A value that satisfies isProblem()
NamespaceObj
  shape
TODO
NamespacePath
  predicate
A value that satisfies isNamespacePath()
Primitive
  or

Should be one of the following:

  1. Option 1
    of predicate
    A value that satisfies isString()
  2. Option 2
    of predicate
    A value that satisfies isNum()
  3. Option 3
    of predicate
    A value that satisfies isBool()
  4. Option 4
    of predicate
    A value that satisfies isNull()
  5. Option 5
    of predicate
    A value that satisfies isUndefined()