<commit_before>/*global module: false, require: false */
'use strict';
var _ = require('underscore');
var S;

// Allow literal shorthand for some schemas.
function literals(value) {
	if (_.isString(value)) {
		return S.string(value);
	}
	if (_.isNumber(value)) {
		return S.number(value);
	}
	return value;
}

// Identify pattern keys.
function key(schema, k) {
    return (k[0] === '/' && k[k.length - 1] === '/') ?
        ['pattern', k.slice(1, k.length - 1), literals(schema)] :
        ['literal', k, literals(schema)];
}

S = module.exports = function (obj) {
    return ['object', {}, ..._.map(obj, key)];
};

// merge, dropping undefined props
var m = (...objs) => _.pick(_.extend.apply(null, [{}, ...objs]), v => v !== undefined);

// how to represent
//   required (we really want to tag 'optional', not 'required')
var methods = {
    string: function (value) {
        var val = _.isString(value) ? ['value', value] :
            (_.isRegExp(value) ? ['pattern', value] : []);
        return ['string', {}, val];
    },
    number: function (value) {
        var val = _.isArray(value) ? ['interval', value] :
            (_.isNumber(value) ? ['value', value] : []);
        return ['number', {}, val];
    },
    or: function (...schemas) {
        return ['or', {}, ..._.map(schemas, literals)];
    },
    array: function (...schemas) {
        return ['array', {}, ['tuple', ..._.map(schemas, literals)]];
    },
    d: function (...args) {
        if (args.length === 2) {
            args.unshift(undefined);
        }
        var [title, description, [type, opts, ...rest]] = args;
        return [type,
               m({title: title, description: description}, opts),
               ...rest];
    },
};

methods.array.of = function (schema) {
    return ['array', {}, ['list', literals(schema)]];
};

_.extend(S, methods);<commit_msg>Support null values in schema.<commit_after>/*global module: false, require: false */
'use strict';
var _ = require('underscore');
var S;

// Allow literal shorthand for some schemas.
function literals(value) {
	if (_.isString(value)) {
		return S.string(value);
	}
	if (_.isNumber(value)) {
		return S.number(value);
	}
	return value;
}

// Identify pattern keys.
function key(schema, k) {
    return (k[0] === '/' && k[k.length - 1] === '/') ?
        ['pattern', k.slice(1, k.length - 1), literals(schema)] :
        ['literal', k, literals(schema)];
}

S = module.exports = function (obj) {
    return ['object', {}, ..._.map(obj, key)];
};

// merge, dropping undefined props
var m = (...objs) => _.pick(_.extend.apply(null, [{}, ...objs]), v => v !== undefined);

// how to represent
//   required (we really want to tag 'optional', not 'required')
var methods = {
    string: function (value) {
        var val = _.isString(value) ? ['value', value] :
            (_.isRegExp(value) ? ['pattern', value] : []);
        return ['string', {}, val];
    },
    number: function (value) {
        var val = _.isArray(value) ? ['interval', value] :
            (_.isNumber(value) ? ['value', value] : []);
        return ['number', {}, val];
    },
    or: function (...schemas) {
        return ['or', {}, ..._.map(schemas, literals)];
    },
    array: function (...schemas) {
        return ['array', {}, ['tuple', ..._.map(schemas, literals)]];
    },
    d: function (...args) {
        if (args.length === 2) {
            args.unshift(undefined);
        }
        var [title, description, [type, opts, ...rest]] = args;
        return [type,
               m({title: title, description: description}, opts),
               ...rest];
    },
	nullval: ['null', {}]
};

methods.array.of = function (schema) {
    return ['array', {}, ['list', literals(schema)]];
};

_.extend(S, methods);
{'fraction_non_alphanumeric': 0.21253333333333332, 'fraction_numerical': 0.0026666666666666666, 'mean_word_length': 2.512172284644195, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5469354', 'n_tokens_mistral': 1209, 'n_tokens_neox': 1182, 'n_words': 315}