Comparing version 1.11.21 to 1.12.0
@@ -10,3 +10,4 @@ "use strict"; | ||
module.exports.cleaningDelete = require('./logic/cleaning-delete'); | ||
module.exports.smartParse = require('./logic/smart-parse'); | ||
module.exports.smartRead = require('./logic/smart-read'); | ||
module.exports.smartWrite = require('./logic/smart-write'); |
@@ -7,10 +7,6 @@ "use strict"; | ||
const yamlBoost = require('yaml-boost'); | ||
const getExt = require('../util/get-ext'); | ||
const yaml = require('js-yaml'); | ||
const smartParse = require('./smart-parse'); | ||
const xmlParser = require('../util/xml-parser'); | ||
const getExt = require('../util/get-ext'); | ||
module.exports = (filepath, options = {}) => { | ||
@@ -27,34 +23,6 @@ assert(typeof filepath === 'string'); | ||
assert(typeof ctx.resolve === 'boolean'); | ||
let result; | ||
switch (ctx.treatAs || getExt(filepath)) { | ||
case 'json': | ||
result = JSON.parse(fs.readFileSync(filepath, 'utf8')); | ||
break; | ||
case 'xml': | ||
result = xmlParser.parse(fs.readFileSync(filepath, 'utf8'), options); | ||
break; | ||
case 'yml': | ||
case 'yaml': | ||
result = ctx.resolve ? yamlBoost.load(filepath, {}) : yaml.load(fs.readFileSync(filepath, 'utf8')); | ||
break; | ||
case 'js': | ||
// eslint-disable-next-line import/no-dynamic-require,global-require | ||
result = require(filepath); | ||
break; | ||
default: | ||
result = fs.readFileSync(filepath, 'utf8').split('\n'); | ||
if (result[result.length - 1].trim() === '') { | ||
result.pop(); | ||
} | ||
break; | ||
} | ||
return result; | ||
return smartParse(fs.readFileSync(filepath, 'utf8'), { ...ctx, | ||
refPath: filepath, | ||
treatAs: ctx.treatAs || getExt(filepath) | ||
}); | ||
}; |
{ | ||
"name": "smart-fs", | ||
"version": "1.11.21", | ||
"version": "1.12.0", | ||
"description": "Abstraction Layer for File Management.", | ||
@@ -50,18 +50,18 @@ "main": "lib/index.js", | ||
"@babel/register": "7.11.5", | ||
"@blackflux/eslint-plugin-rules": "1.3.38", | ||
"@blackflux/robo-config-plugin": "3.10.2", | ||
"@blackflux/eslint-plugin-rules": "1.3.40", | ||
"@blackflux/robo-config-plugin": "3.10.7", | ||
"babel-eslint": "10.1.0", | ||
"babel-preset-latest-node": "5.0.0", | ||
"chai": "4.2.0", | ||
"coveralls": "3.1.0", | ||
"eslint": "7.9.0", | ||
"eslint": "7.10.0", | ||
"eslint-config-airbnb-base": "14.2.0", | ||
"eslint-plugin-import": "2.22.0", | ||
"eslint-plugin-import": "2.22.1", | ||
"eslint-plugin-json": "2.1.2", | ||
"eslint-plugin-markdown": "1.0.2", | ||
"eslint-plugin-mocha": "8.0.0", | ||
"js-gardener": "2.0.172", | ||
"node-tdd": "2.18.8", | ||
"js-gardener": "2.0.176", | ||
"node-tdd": "2.18.10", | ||
"nyc": "15.1.0", | ||
"semantic-release": "17.1.1", | ||
"babel-preset-latest-node": "4.1.0" | ||
"semantic-release": "17.1.2" | ||
}, | ||
@@ -118,4 +118,4 @@ "nyc": { | ||
"xml-js": "1.6.11", | ||
"yaml-boost": "1.9.25" | ||
"yaml-boost": "1.10.1" | ||
} | ||
} |
@@ -43,2 +43,6 @@ # smart-fs | ||
### smartParse(content, options = { treatAs = null, resolve = true, refPath = process.cwd() }) | ||
Core logic of `smartRead` but takes content and refPath. | ||
### smartRead(filepath, options = { treatAs = null, resolve = true }) | ||
@@ -53,3 +57,3 @@ | ||
- `.yml` and `.yaml`: Loads file using [yaml-boost](https://github.com/blackflux/yaml-boost). | ||
- `.js`: Loads file using [require](https://nodejs.org/api/modules.html#modules_require_id). | ||
- `.js`: Loads file using "hacked" [require](https://nodejs.org/api/modules.html#modules_require_id). | ||
- `.*`: Treats file as text file and loads as array of lines. | ||
@@ -69,3 +73,3 @@ | ||
The file is only actually written if the content has changed. | ||
The file is only actually written if the content has changed. | ||
Returns true if the file was written, false otherwise. | ||
@@ -89,3 +93,3 @@ | ||
When `keepOrder` is set to `true` and a file is overwritten, | ||
When `keepOrder` is set to `true` and a file is overwritten, | ||
the new content is ordered according to the existing content (e.g. for `json` and `yml`) | ||
@@ -92,0 +96,0 @@ |
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
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
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
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
17303
13
239
98
9
+ Addedyaml-boost@1.10.1(transitive)
- Removedyaml-boost@1.9.25(transitive)
Updatedyaml-boost@1.10.1