stable-ts-type
Version:
Obtain the most stable type code of 'typescript' through multiple network requests
25 lines (24 loc) • 1.37 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
const quicktype_core_1 = require("quicktype-core");
const json2Type = (modalName, jsonSamples, opts = {}) => __awaiter(void 0, void 0, void 0, function* () {
const jsonInput = (0, quicktype_core_1.jsonInputForTargetLanguage)('ts');
yield jsonInput.addSource({
name: modalName,
samples: jsonSamples,
});
const inputData = new quicktype_core_1.InputData();
inputData.addInput(jsonInput);
const result = yield (0, quicktype_core_1.quicktype)(Object.assign(Object.assign({}, opts), { lang: 'ts', inputData }));
return result.lines.join('\n');
});
exports.default = json2Type;