当前位置:网站首页>Use ramda parsing yarnrc/. Example of npmrc configuration file
Use ramda parsing yarnrc/. Example of npmrc configuration file
2022-07-16 05:35:00 【zq. xc】
Use Pure function tools (ramda.js) analysis .yarnrc/.npmrc Example of configuration file
Source code , rely on ramda.js
./utils/parseConfig
((root, factory) => {
if (typeof define === 'function' && define.amd) {
define(['ramda'], factory);
} else if (typeof exports === 'object') {
var R = require('ramda');
module.exports = factory(R);
} else {
root.parseConfig = factory(root.R);
}
})(this, (R) => {
let regs = {
trimzy:R.replace(/\\\\/g,"\\"), // Remove redundant escape characters
trims:R.replace(/^(\s|\"|\'|\ )+|(\s|\"|\'|\ )+$/g,'')// Remove end quotes and spaces
}
return function creteConverter(annotator,spliter){
return R.compose(
R.fromPairs,// Turn it into a two-dimensional array and an object
R.filter(arr=>arr[0] !=""),// To filter out key Empty
R.map(R.compose(
R.map(regs.trims), // Remove excess at both ends Double quotes / Single quotation marks / blank
R.split(spliter), // Use key value Separator
regs.trimzy // Remove the path token
)), // Turn it into a two-dimensional array , And go to key Empty data
R.filter(s=>R.both(
str=>str[0]!=annotator, // Remove # Comment row
str=>R.trim(str)!="" // Remove the blank lines
)(s)),
R.map(R.trim),// Remove two blanks
R.split(/\r\n|\r|\n/) // branch
)
}
});
node Examples of use
const parseConfig = require("./utils/parseConfig");
const os = require("os");
const path = require("path");
const fs = require("fs");
const homedir = os.homedir();
let parseYarnConfig = parseConfig("#"," ")
let parseNpmConfig = parseConfig(";","=")
var str = fs.readFileSync(path.join(homedir,".yarnrc")).toString();
var str2 = fs.readFileSync(path.join(homedir,".npmrc")).toString();
var config = parseYarnConfig(str);
var config2 = parseNpmConfig(str2);
console.log(config);
console.log(config2);
Browser side usage examples
require([”./utils/parseConfig“],function(parseConfig){
var parser = parseConfig("#"," ")
var teststr=` # Sample configuration file # This is a comment cache "D:\\yarn\\cache" global "D:\\yarn\\global" `
console.log(parser(teststr))
})
边栏推荐
- [tensorflow2] attributeerror: 'tensor' object has no attribute 'numpy' solution (tf.py_function)
- Flask 开发 & Get/Post 请求
- :class修改样式
- 【黄啊码】MySQL的这些小知识点,初入门的你必须得学会
- 迷茫的我要开始奔【测试】这个方向啦
- 第一次放生,感觉很奇妙
- 【黄啊码】MySQL入门—1、SQL 的执行流程
- sql_ Server2014 download and installation
- 41.js--闭包
- handsontable pro 授权码 key 生成器(JS函数)(仅供学习交流)
猜你喜欢

ES6--类(class)

【prettier】通过prettier自动格式化代码不生效
![[Huang ah code] getting started with MySQL - 1. SQL execution process](/img/e5/8541f9a9e260b431a4da800036ae2d.png)
[Huang ah code] getting started with MySQL - 1. SQL execution process

window系统盘瘦身(开发)

Kubernetes into the pit

ES6--let与const

Blue Bridge Cup: the second game of the 13th provincial competition of single chip microcomputer group

Flask 开发 & Get/Post 请求

Le 13ème concours provincial de Blue Bridge Cup MCU

【黄啊码】PHP配合xlswriter实现无限表头层级Excel导出
随机推荐
Call GPU completely through torch on pycharm (the most detailed)
ES6--let与const
【黄啊码】MySQL入门—2、使用数据定义语言(DDL)操作数据库
Automatically generate a model (egg.js, which is generated by connecting with the database)
藍橋杯單片機第13届省賽題
[Huang ah code] Why do I suggest you choose go instead of PHP?
Svelte official introductory tutorial (4) -- template logic
C语言:结构体中链表的添加与删除
【vue】keep-alive清除缓存最简单暴力的方法
JS closing notes
Find the ID of the parent node according to the child node ID in the tree data
[Huang ah code] today, someone actually asked me: what does where 1=1 mean?
【黄啊码】redis实现模糊查询并删除|redis根据前缀获取key
自动生成model(egg.js,与数据库连接来生成)
对象成员检测
Secondary development tutorial of fastadmin [simple construction, multi table problems, API development]
ES6--箭头函数
ES6的高级赋值方法——解构赋值
网络基础知识
ThreadLocal造成的内存泄漏