Sha256: dc9e17bed2237c8bcf45522e387f9e920091f77b1bea763336a2cb049ffbb560

Contents?: true

Size: 1.22 KB

Versions: 27

Compression:

Stored size: 1.22 KB

Contents

var types = require("../lib/types");
var Type = types.Type;
var builtin = types.builtInTypes;
var isNumber = builtin.number;

// An example of constructing a new type with arbitrary constraints from
// an existing type.
exports.geq = function(than) {
    return new Type(function(value) {
        return isNumber.check(value) && value >= than;
    }, isNumber + " >= " + than);
};

// Default value-returning functions that may optionally be passed as a
// third argument to Def.prototype.field.
exports.defaults = {
    // Functions were used because (among other reasons) that's the most
    // elegant way to allow for the emptyArray one always to give a new
    // array instance.
    "null": function() { return null },
    "emptyArray": function() { return [] },
    "false": function() { return false },
    "true": function() { return true },
    "undefined": function() {}
};

var naiveIsPrimitive = Type.or(
    builtin.string,
    builtin.number,
    builtin.boolean,
    builtin.null,
    builtin.undefined
);

exports.isPrimitive = new Type(function(value) {
    if (value === null)
        return true;
    var type = typeof value;
    return !(type === "object" ||
             type === "function");
}, naiveIsPrimitive.toString());

Version data entries

27 entries across 19 versions & 6 rubygems

Version Path
ilog-0.4.1 node_modules/recast/node_modules/ast-types/lib/shared.js
ilog-0.4.0 node_modules/recast/node_modules/ast-types/lib/shared.js
ilog-0.3.3 node_modules/recast/node_modules/ast-types/lib/shared.js
xcodebuild-helper-1.2.5 externals/ios-sim-master/node_modules/ast-types/lib/shared.js
brwy_rails-0.0.6 test/dummy/node_modules/ast-types/lib/shared.js
brwy_rails-0.0.5 test/dummy/node_modules/ast-types/lib/shared.js
xcodebuild-helper-1.2.3 externals/ios-sim-master/node_modules/ast-types/lib/shared.js
brwy_rails-0.0.4 test/dummy/node_modules/ast-types/lib/shared.js
brwy_rails-0.0.3 test/dummy/node_modules/ast-types/lib/shared.js
brwy_rails-0.0.2 test/dummy/node_modules/ast-types/lib/shared.js
brwy_rails-0.0.1 test/dummy/node_modules/ast-types/lib/shared.js
es6_tilt-0.1.2 test/dummy/node_modules/ast-types/lib/shared.js
es6_tilt-0.1.2 test/dummy/app/assets/javascripts/node_modules/ast-types/lib/shared.js
es6_tilt-0.1.1 test/dummy/app/assets/javascripts/node_modules/ast-types/lib/shared.js
es6_tilt-0.1.1 test/dummy/node_modules/ast-types/lib/shared.js
es6_tilt-0.1.0 test/dummy/app/assets/javascripts/node_modules/ast-types/lib/shared.js
gulp_assets-1.0.0.pre.5 template/node_modules/babel-core/node_modules/ast-types/lib/shared.js
gulp_assets-1.0.0.pre.5 template/node_modules/babel-core/node_modules/regenerator/node_modules/recast/node_modules/ast-types/lib/shared.js
gulp_assets-1.0.0.pre.5 template/node_modules/babel-core/node_modules/regexpu/node_modules/recast/node_modules/ast-types/lib/shared.js
gulp_assets-1.0.0.pre.4 template/node_modules/babel-core/node_modules/regexpu/node_modules/recast/node_modules/ast-types/lib/shared.js