Comparing version 1.1.1 to 1.1.2
@@ -5,3 +5,3 @@ "use strict"; | ||
const path = require("path"); | ||
const adapters = require("./adapter"); | ||
const adapters_1 = require("./adapters"); | ||
const WriteConfig_1 = require("./WriteConfig"); | ||
@@ -14,6 +14,6 @@ exports.read = (data, options) => { | ||
} | ||
let adapter = adapters[options.type]; | ||
let adapter = adapters_1.getAdapter(options.type); | ||
if (!adapter) { | ||
options.type = "raw"; | ||
adapter = adapters[options.type]; | ||
adapter = adapters_1.getAdapter(options.type); | ||
} | ||
@@ -36,33 +36,5 @@ const obj = adapter.parse(data); | ||
const filename = path.basename(p.toString()); | ||
const matches = [ | ||
{ | ||
match: /\.json$/, | ||
value: "json" | ||
}, | ||
{ | ||
match: /\.ya?ml$/, | ||
value: "yaml" | ||
}, | ||
{ | ||
match: /\.ini$/, | ||
value: "ini" | ||
}, | ||
{ | ||
match: /\.toml$/, | ||
value: "toml" | ||
}, | ||
{ | ||
match: /\.json5$/, | ||
value: "json5" | ||
}, | ||
{ | ||
match: /\.hjson$/, | ||
value: "hjson" | ||
} | ||
]; | ||
for (const item of matches) { | ||
if (item.match.test(filename)) { | ||
options.type = item.value; | ||
break; | ||
} | ||
const adapter = adapters_1.getMatchAdapter(filename); | ||
if (adapter) { | ||
options.type = adapter.key; | ||
} | ||
@@ -69,0 +41,0 @@ } |
@@ -6,3 +6,3 @@ "use strict"; | ||
const path = require("path"); | ||
const adapters = require("./adapter"); | ||
const adapters_1 = require("./adapters"); | ||
class WriteConfig { | ||
@@ -12,3 +12,3 @@ constructor(obj, options) { | ||
this.options = options; | ||
this.adapter = adapters[this.options.type]; | ||
this.adapter = adapters_1.getAdapter(this.options.type); | ||
} | ||
@@ -15,0 +15,0 @@ modify(fn) { |
import * as fs from "fs"; | ||
export interface IAdapter<T = any> { | ||
parse: (str: string) => T; | ||
stringify: (obj: T, options?) => string; | ||
key: string; | ||
match: RegExp; | ||
parse(str: string): T; | ||
stringify(obj: T, options?): string; | ||
} |
import * as fs from "fs"; | ||
import * as path from "path"; | ||
import * as adapters from "./adapter"; | ||
import { IAdapter } from "./adapter.d"; | ||
import { getAdapter, getMatchAdapter } from "./adapters"; | ||
import { IReadFileOptions, IReadOptions } from "./options.d"; | ||
@@ -14,6 +14,6 @@ import { WriteConfig } from "./WriteConfig"; | ||
} | ||
let adapter: IAdapter = adapters[options.type]; | ||
let adapter: IAdapter = getAdapter(options.type); | ||
if (!adapter) { | ||
options.type = "raw"; | ||
adapter = adapters[options.type]; | ||
adapter = getAdapter(options.type); | ||
} | ||
@@ -24,6 +24,3 @@ const obj: T = adapter.parse(data); | ||
export const readFile = <T = any>( | ||
p: fs.PathLike, | ||
options?: IReadFileOptions | ||
) => { | ||
export const readFile = <T = any>(p: fs.PathLike, options?: IReadFileOptions) => { | ||
if (!fs.existsSync(p)) { | ||
@@ -41,33 +38,5 @@ throw new Error(p.toString()); | ||
const filename = path.basename(p.toString()); | ||
const matches = [ | ||
{ | ||
match: /\.json$/, | ||
value: "json" | ||
}, | ||
{ | ||
match: /\.ya?ml$/, | ||
value: "yaml" | ||
}, | ||
{ | ||
match: /\.ini$/, | ||
value: "ini" | ||
}, | ||
{ | ||
match: /\.toml$/, | ||
value: "toml" | ||
}, | ||
{ | ||
match: /\.json5$/, | ||
value: "json5" | ||
}, | ||
{ | ||
match: /\.hjson$/, | ||
value: "hjson" | ||
} | ||
]; | ||
for (const item of matches) { | ||
if (item.match.test(filename)) { | ||
options.type = item.value; | ||
break; | ||
} | ||
const adapter = getMatchAdapter(filename); | ||
if (adapter) { | ||
options.type = adapter.key; | ||
} | ||
@@ -74,0 +43,0 @@ } |
import * as fs from "fs"; | ||
import makeDir = require("make-dir"); | ||
import * as path from "path"; | ||
import * as adapters from "./adapter"; | ||
import { IAdapter } from "./adapter.d"; | ||
import { getAdapter } from "./adapters"; | ||
import { IWriteOptions } from "./options.d"; | ||
@@ -16,3 +16,3 @@ | ||
this.options = options; | ||
this.adapter = adapters[this.options.type]; | ||
this.adapter = getAdapter(this.options.type); | ||
} | ||
@@ -19,0 +19,0 @@ |
{ | ||
"name": "ftconfig", | ||
"version": "1.1.1", | ||
"version": "1.1.2", | ||
"description": "F*ck the config", | ||
@@ -15,3 +15,3 @@ "main": "dist/index.js", | ||
"test": "ava dist/test/**/*.{spec,e2e}.js", | ||
"lint": "npm run lint:typescript && npm run lint:javascript", | ||
"lint": "npm run lint:typescript", | ||
"lint:typescript": "tslint {lib,test}/**/*.ts", | ||
@@ -52,30 +52,38 @@ "lint:javascript": "eslint ./**/*.js" | ||
"license": "MIT", | ||
"yVersion": "2.1.11", | ||
"yVersion": "2.1.25", | ||
"devDependencies": { | ||
"@commitlint/cli": "^7.2.1", | ||
"@commitlint/config-conventional": "^7.1.2", | ||
"@commitlint/lint": "^7.2.1", | ||
"@commitlint/cli": "^8.0.0", | ||
"@commitlint/config-conventional": "^8.0.0", | ||
"@commitlint/lint": "^8.0.0", | ||
"@iarna/toml": "^2.2.3", | ||
"@types/find-up": "^2.1.1", | ||
"@types/hjson": "^2.4.0", | ||
"@types/hjson": "^2.4.1", | ||
"@types/ini": "^1.3.30", | ||
"@types/js-yaml": "^3.11.2", | ||
"@types/js-yaml": "^3.12.1", | ||
"@types/json5": "0.0.30", | ||
"@types/make-dir": "^1.0.3", | ||
"@types/node": "^10.1.2", | ||
"ava": "^0.25.0", | ||
"eslint": "^4.19.1", | ||
"eslint-config-standard": "^11.0.0", | ||
"eslint-plugin-import": "^2.10.0", | ||
"eslint-plugin-node": "^6.0.1", | ||
"eslint-plugin-promise": "^3.7.0", | ||
"eslint-plugin-standard": "^3.0.1", | ||
"@types/node": "^12.0.4", | ||
"ava": "^1.4.1", | ||
"eslint": "^5.10.0", | ||
"eslint-config-standard": "^12.0.0", | ||
"eslint-plugin-import": "^2.14.0", | ||
"eslint-plugin-node": "^8.0.0", | ||
"eslint-plugin-promise": "^4.0.1", | ||
"eslint-plugin-standard": "^4.0.0", | ||
"find-up": "^3.0.0", | ||
"husky": "^1.1.2", | ||
"lint-staged": "^7.3.0", | ||
"prettier": "^1.14.3", | ||
"rimraf": "^2.6.2", | ||
"tslint": "^5.10.0", | ||
"typescript": "^3.1.3" | ||
"husky": "^2.3.0", | ||
"lint-staged": "^8.1.7", | ||
"prettier": "^1.17.1", | ||
"rimraf": "^2.6.3", | ||
"tslint": "^5.17.0", | ||
"typescript": "^3.5.1" | ||
}, | ||
"dependencies": { | ||
"hjson": "^3.1.2", | ||
"ini": "^1.3.5", | ||
"js-yaml": "^3.13.1", | ||
"json5": "^2.1.0", | ||
"make-dir": "^1.3.0" | ||
}, | ||
"peerDependencies": { | ||
"@iarna/toml": "^2.2.1", | ||
@@ -85,5 +93,4 @@ "hjson": "^3.1.2", | ||
"js-yaml": "^3.12.0", | ||
"json5": "^2.1.0", | ||
"make-dir": "^1.3.0" | ||
"json5": "^2.1.0" | ||
} | ||
} |
@@ -11,3 +11,4 @@ # ftconfig | ||
[![Author][AUTHOR_URL]][AUTHOR_HREF] | ||
[![license][LICENSE_URL]][LICENSE_HREF] | ||
[![MIT-License][LICENSE_URL]][LICENSE_HREF] | ||
[![996ICU-License][LICENSE_996_URL]][LICENSE_996_HREF] | ||
@@ -152,1 +153,4 @@ ## Usage | ||
[LICENSE_HREF]: https://opensource.org/licenses/MIT | ||
[LICENSE_996_URL]: https://img.shields.io/badge/license-NPL%20(The%20996%20Prohibited%20License)-blue.svg?style=flat-square&maxAge=7200 | ||
[LICENSE_996_HREF]: https://github.com/996icu/996.ICU |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Unidentified License
License(Experimental) Something that seems like a license was found, but its contents could not be matched with a known license.
Found 1 instance in 1 package
23923
36
559
154
10
25
1
80
4
1
- Removed@iarna/toml@^2.2.1
Updatedjs-yaml@^3.13.1