Skip to content

Instantly share code, notes, and snippets.

@danielb2
Last active December 26, 2015 20:14
Show Gist options
  • Save danielb2/64d8974e44d39882e891 to your computer and use it in GitHub Desktop.
Save danielb2/64d8974e44d39882e891 to your computer and use it in GitHub Desktop.

Revisions

  1. danielb2 revised this gist Dec 26, 2015. 1 changed file with 4 additions and 3 deletions.
    7 changes: 4 additions & 3 deletions doc.md
    Original file line number Diff line number Diff line change
    @@ -1,18 +1,19 @@
    ### `alternatives`

    Generates a type that will match one of the provided alternative schemas via the [`try()`](#alternativestryschemas)
    method. If no schemas are added, the type will not match any value except for `undefined`.
    method. If no schemas are added, the type will not match any value except for `undefined`. Schemas can be expressed as
    multiple arguments or given as an array.

    Supports the same methods of the [`any()`](#any) type.

    ```javascript
    var alt = Joi.alternatives().try(Joi.number(), Joi.string());
    // or: var alt = Joi.alternatives.try([Joi.number(), Joi.string()])
    // Same as var alt = Joi.alternatives.try([Joi.number(), Joi.string()])
    ```

    Alternatives can be expressed using a shorter notation.

    ```javascript
    var alt = Joi.alternatives(Joi.number(), Joi.string())
    // or: var alt = Joi.alternatives.try([Joi.number(), Joi.string()])
    // Same as var alt = Joi.alternatives.try([Joi.number(), Joi.string()])
    ```
  2. danielb2 revised this gist Dec 26, 2015. 1 changed file with 0 additions and 1 deletion.
    1 change: 0 additions & 1 deletion doc.md
    Original file line number Diff line number Diff line change
    @@ -14,6 +14,5 @@ Alternatives can be expressed using a shorter notation.

    ```javascript
    var alt = Joi.alternatives(Joi.number(), Joi.string())

    // or: var alt = Joi.alternatives.try([Joi.number(), Joi.string()])
    ```
  3. danielb2 revised this gist Dec 26, 2015. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions doc.md
    Original file line number Diff line number Diff line change
    @@ -10,10 +10,10 @@ var alt = Joi.alternatives().try(Joi.number(), Joi.string());
    // or: var alt = Joi.alternatives.try([Joi.number(), Joi.string()])
    ```

    Alternatives can be expressed using the shorter `[]` notation.
    Alternatives can be expressed using a shorter notation.

    ```javascript
    var alt = Joi.alternatives.try([Joi.number(), Joi.string()])
    var alt = Joi.alternatives(Joi.number(), Joi.string())

    // or: var alt = Joi.alternatives(Joi.number(), Joi.string())
    // or: var alt = Joi.alternatives.try([Joi.number(), Joi.string()])
    ```
  4. danielb2 created this gist Dec 26, 2015.
    19 changes: 19 additions & 0 deletions doc.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,19 @@
    ### `alternatives`

    Generates a type that will match one of the provided alternative schemas via the [`try()`](#alternativestryschemas)
    method. If no schemas are added, the type will not match any value except for `undefined`.

    Supports the same methods of the [`any()`](#any) type.

    ```javascript
    var alt = Joi.alternatives().try(Joi.number(), Joi.string());
    // or: var alt = Joi.alternatives.try([Joi.number(), Joi.string()])
    ```

    Alternatives can be expressed using the shorter `[]` notation.

    ```javascript
    var alt = Joi.alternatives.try([Joi.number(), Joi.string()])

    // or: var alt = Joi.alternatives(Joi.number(), Joi.string())
    ```