Code coverage report for index.js

Statements: 100% (15 / 15)      Branches: 100% (4 / 4)      Functions: 100% (1 / 1)      Lines: 100% (15 / 15)      Ignored: none     

All files » __root__/ » index.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 441                       1   1462   1462 1370 92 91 91   2 2 2             1           1459   1459     1  
var jsonlint = require('jsonlint-lines'),
  geojsonHintObject = require('./object');
 
/**
 * @alias geojsonhint
 * @param {(string|object)} GeoJSON given as a string or as an object
 * @param {Object} options
 * @param {boolean} [options.noDuplicateMembers=true] forbid repeated
 * properties. This is only available for string input, becaused parsed
 * Objects cannot have duplicate properties.
 * @returns {Array<Object>} an array of errors
 */
function hint(str, options) {
 
    var gj, errors = [];
 
    if (typeof str === 'object') {
        gj = str;
    } else if (typeof str === 'string') {
        try {
            gj = jsonlint.parse(str);
        } catch(e) {
            var match = e.message.match(/line (\d+)/);
            var lineNumber = parseInt(match[1], 10);
            return [{
                line: lineNumber - 1,
                message: e.message,
                error: e
            }];
        }
    } else {
        return [{
            message: 'Expected string or object as input',
            line: 0
        }];
    }
 
    errors = errors.concat(geojsonHintObject.hint(gj, options));
 
    return errors;
}
 
module.exports.hint = hint;