_(data) .map((value, index) => new Table(value, opts)) .map(table => table.toString()) .thru(data => data.join(os.EOL)) .value()
/** * Returns the normalized collection path from the given full resource path. * * @param {string} path - The full resource path (e.g. "/restaurants/washington/seattle/joes-diner") * @returns {string} - The normalized collection path (e.g. "/restaurants/washington/seattle") */ function getCollectionFromPath (path) { path = _(path).toString(); let lastSlash = path.substring(0, path.length - 1).lastIndexOf("/"); if (lastSlash === -1) { return ""; } else { return normalizeCollection(path.substring(0, lastSlash)); } }
name = _(name).toString(); if (_.isEmpty(name) || name === "/" || name === "//") { return "/";
/** * Returns the normalized resource name from the given full resource path. * * @param {string} path - The full resource path (e.g. "/restaurants/washington/seattle/joes-diner") * @returns {string} - The normalized resource name (e.g. "/joes-diner") */ function getNameFromPath (path) { path = _(path).toString(); let lastSlash = path.substring(0, path.length - 1).lastIndexOf("/"); if (lastSlash === -1) { return normalizeName(path); } else { return normalizeName(path.substring(lastSlash)); } }
/** * Normalizes collection paths. * * Examples: * / => (empty string) * /users => /users * /users/jdoe/ => /users/jdoe * * @param {string} collection * @returns {string} */ function normalizeCollection (collection) { // Normalize the root path as an empty string collection = _(collection).toString(); if (_.isEmpty(collection) || collection === "/" || collection === "//") { return ""; } // Add a leading slash if (!_.startsWith(collection, "/")) { collection = "/" + collection; } // Remove a trailing slash if (_.endsWith(collection, "/")) { collection = collection.substring(0, collection.length - 1); } return collection; }