@gql2ts/util
Advanced tools
Comparing version 1.2.2 to 1.3.0-alpha.c9e04a1e
export declare const badWriteHandler: (err?: Error) => void; | ||
export declare const readFile: (fileName: string) => string; | ||
export declare const readFile: (fileName: string) => string | object; | ||
export declare const safeJSONParse: (possibleJSON: string) => string | object; | ||
export declare const writeToFile: (fileName: string, data: string) => void; |
@@ -7,4 +7,26 @@ "use strict"; | ||
} }; | ||
exports.readFile = fileName => JSON.parse(fs.readFileSync(fileName).toString()); | ||
exports.readFile = fileName => { | ||
const stringifiedFile = fs.readFileSync(fileName).toString(); | ||
if (fileName.endsWith('.json')) { | ||
// force JSON Parse | ||
return JSON.parse(stringifiedFile); | ||
} | ||
else if (fileName.endsWith('.graphql') || fileName.endsWith('.gql')) { | ||
// assume graphql schema language | ||
return stringifiedFile; | ||
} | ||
else { | ||
// fallback when the type is unknown | ||
return exports.safeJSONParse(stringifiedFile); | ||
} | ||
}; | ||
exports.safeJSONParse = possibleJson => { | ||
try { | ||
return JSON.parse(possibleJson); | ||
} | ||
catch (e) { | ||
return possibleJson; | ||
} | ||
}; | ||
exports.writeToFile = (fileName, data) => fs.writeFile(fileName, data, exports.badWriteHandler); | ||
//# sourceMappingURL=fileIO.js.map |
@@ -1,2 +0,2 @@ | ||
export { readFile, writeToFile } from './fileIO'; | ||
export { readFile, writeToFile, safeJSONParse } from './fileIO'; | ||
export { PossibleIntrospectionInputs, PossibleSchemaInput, isIntrospectionResult, schemaFromInputs, isList, isNonNullable, isEnum } from './schema'; |
@@ -6,2 +6,3 @@ "use strict"; | ||
exports.writeToFile = fileIO_1.writeToFile; | ||
exports.safeJSONParse = fileIO_1.safeJSONParse; | ||
var schema_1 = require("./schema"); | ||
@@ -8,0 +9,0 @@ exports.isIntrospectionResult = schema_1.isIntrospectionResult; |
{ | ||
"name": "@gql2ts/util", | ||
"private": false, | ||
"version": "1.2.2", | ||
"version": "1.3.0-alpha.c9e04a1e", | ||
"description": "utilities for gql2ts", | ||
@@ -6,0 +6,0 @@ "main": "dist/index.js", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
7024
94
1