Files
firebase-tools/lib/identifierToProjectId.js
2018-04-10 18:29:02 -07:00

26 lines
554 B
JavaScript

"use strict";
var _ = require("lodash");
var api = require("./api");
module.exports = function(id) {
return api.getProjects().then(function(projects) {
// if exact match for a project id, return it
if (_.includes(_.keys(projects), id)) {
return id;
}
for (var projectId in projects) {
if (projects.hasOwnProperty(projectId)) {
var instance = _.get(projects, [projectId, "instances", "database", "0"]);
if (id === instance) {
return projectId;
}
}
}
return null;
});
};