UNPKG

app-lib-trans-storage

Version:

文本文件进行转换JSON存储,常用于exec执行文件场景

160 lines (115 loc) 6.2 kB
# app-lib-trans-storage 文本文件转换存储 <!-------------------------------common start flag-------------------------> <center> <div align="center"> <h1>文本文件进行转换JSON存储,常用于exec执行文件场景</h1> <a href="https://img.shields.io/badge/success: https local reason - goback refresh you brower can show badge image now-brightgree" title="click can show badge"> <img src="https://appbir.github.io/appbir-resource-statics/image/logo.png" height="60" /> </a> <h1>app-lib-trans-storage</h1> <a href="https://appbir/library"> <img src="https://img.shields.io/badge/appbir-library-blue"/> </a> <a href="https://appbir/library/-/web/detail/app-lib-trans-storage"> <img src="https://img.shields.io/badge/npm-v1.0.7-green"> </a> <a href="https://appbir"> <img src="https://img.shields.io/badge/license-ISC-brightgree"/> </a> <div> </center> <!-------------------------------common end flag---------------------------> <!-------------------------------background start flag---------------------> # 一、背景介绍 1. 使用exec执行文件的时候 文件往往是静态文件 然而在上方使用的时候 就会丢失静态文件 1. 针对一些静态文件的组件 在使用该组件的工程或者组件中,由于动态加载(require(var))等方式进行加载后 在webpack不能在打包范围,导致使用的组件进行bundle打包的时候,该文件已经不存在了,导致异常情况。 2. 期望转换可编译的文本进行统一的打包处理。 <!-------------------------------background end flag-----------------------> <!-------------------------------functions start flag----------------------> # 二、功能描述 1. 将文件转换为json文件进行存储。 2. 第一次使用的时候 自动转换为文件,便捷使用。 3. 后续直接requireJSON引用JSON进行操作文件即可 <!-------------------------------functions end flag------------------------> <!-------------------------------attention start flag----------------------> # 三、注意事项 <!-------------------------------attention end flag------------------------> <!-------------------------------examples start flag-----------------------> # 四、使用案列 代码逻辑 1. 开发阶段编译 2. 使用首次阶段引入生成文件 3. 直接使用或者获取路 <!-------------------------------examples end flag-------------------------> <!-------------------------------todo start flag---------------------------> # 五、todo列表 <!-------------------------------todo end flag-----------------------------> <!-------------------------------api start flag----------------------------> # 六、API ## Functions <dl> <dt><a href="#filesToJson">filesToJson(filePaths, [storagePath])</a><code>array</code></dt> <dd><p>将文件转换为JSON进行存储</p> </dd> <dt><a href="#pathToFile">pathToFile([storagePath], [basePath])</a><code>array</code></dt> <dd><p>存储文件转换为文件</p> </dd> <dt><a href="#jsonToFile">jsonToFile([fileDatas], [basePath], [isForce])</a><code>array</code></dt> <dd><p>存储文件转换为文件</p> </dd> <dt><a href="#buildDirFiles">buildDirFiles(buildDirPath, [storagePath])</a></dt> <dd><p>构建文件夹 </p> <ul> <li>注意 所有文件路径是平级 不支持嵌套</li> </ul> </dd> </dl> <a name="filesToJson"></a> ## filesToJson(filePaths, [storagePath]) ⇒ <code>array</code> 将文件转换为JSON进行存储 **Kind**: global function **Returns**: <code>array</code> - 返回文件读取的JSON内容 * example ``` filesToJson([path.resolve(__dirname,`./b.ps1`),path.resolve(__dirname,`./a.ps1`)] ``` | Param | Type | Default | Description | | --- | --- | --- | --- | | filePaths | <code>array</code> | | 多个文件转换了路径 | | [storagePath] | <code>string</code> | <code>&quot;&#x27;./static/store.json&#x27;&quot;</code> | 存储的文件路径名称 一般为json 便捷处理 | <a name="pathToFile"></a> ## pathToFile([storagePath], [basePath]) ⇒ <code>array</code> 存储文件转换为文件 **Kind**: global function **Returns**: <code>array</code> - 所有存储的文件路径 | Param | Type | Default | Description | | --- | --- | --- | --- | | [storagePath] | <code>string</code> | <code>&quot;&#x27;./static/store.json&#x27;&quot;</code> | 存储文件位置 | | [basePath] | <code>string</code> | <code>&quot;&#x27;./static/&#x27;&quot;</code> | 每个文件存储路径 | <a name="jsonToFile"></a> ## jsonToFile([fileDatas], [basePath], [isForce]) ⇒ <code>array</code> 存储文件转换为文件 **Kind**: global function **Returns**: <code>array</code> - 所有存储的文件路径 | Param | Type | Default | Description | | --- | --- | --- | --- | | [fileDatas] | <code>array</code> | <code>&#x27;[]&#x27;</code> | 存储数据 | | [basePath] | <code>string</code> | <code>&quot;&#x27;./static/&#x27;&quot;</code> | 每个文件存储路径 | | [isForce] | <code>boolean</code> | <code>false</code> | 是否强制写入 默认false | <a name="buildDirFiles"></a> ## buildDirFiles(buildDirPath, [storagePath]) 构建文件夹 * 注意 所有文件路径是平级 不支持嵌套 **Kind**: global function | Param | Type | Default | Description | | --- | --- | --- | --- | | buildDirPath | <code>string</code> | <code>&quot;src/trans-static&quot;</code> | 构建的文件夹路径 | | [storagePath] | <code>string</code> | <code>&quot;./static/store.json&quot;</code> | 存储路径 | <!-------------------------------api end flag------------------------------> <!-------------------------------change logs begin flag---------------------> # 七、发布日志 * [2023-11-03 11-42-34]-发布组件 * [2023-11-03 09-08-49]-日志调整 * [2023-11-02 09-07-57]-升级nodejs * [2023-11-01 08-12-34]-去掉日志 * [2023-10-31 11-53-21]-添加目录文件自动扫描到json * [2023-10-31 11-07-40]-添加文本转换组件 * [2023-10-31 11-04-31]-添加文本转换组件 <!-------------------------------change logs end flag----------------------->