js camelCase formatter
2024-09-25 13:51:57
js camelCase formatter
驼峰命名 转换器
'A'.charCodeAt();
// 65
'Z'.charCodeAt();
// 90
'a'.charCodeAt();
// 97
'z'.charCodeAt();
// 122
Number.isNaN(+`x`)
// true
Number.isNaN(+`2`)
// false
'tools_finance_costInV2'
=> '/tool/finance/cost-in-v2'
'costInV2'
=> 'cost-in-v2'
solution
const log = console.log;
const camelCaseFormatter = (str = ``, debug = false) => {
let result = '';
for(let item of [...str]) {
if(item.charCodeAt() > 'a'.charCodeAt() || !Number.isNaN(+item)) {
result += item;
} else {
result += `-${item.toLocaleLowerCase()}`;
}
}
if(debug) {
log(`result = `, result);
}
return result;
}
const str = 'costInV2';
// "costInV2"
camelCaseFormatter(str, true);
/*
// node ./camelCase.js
// result = cost-in-v2
*/
demo
id to URL
'tools_finance_costInV2'
=> '/tool/finance/cost-in-v2'
const url = window.location.origin;
// https://app.xgqfrms.xyz
const config = {
key: 'costInV2',
level: 3,
id: 'tools_finance_costInV2',
name: '工具库-财务-消耗录入',
url: '/tool/finance/cost-in-v2',
// url: 'https://app.xgqfrms.xyz/tool/finance/cost-in-v2',
};
regex
refs
https://app.xgqfrms.xyz/index.html
xgqfrms 2012-2020
www.cnblogs.com 发布文章使用:只允许注册用户才可以访问!
原创文章,版权所有️xgqfrms, 禁止转载 ️,侵权必究️!
最新文章
- (原) 2.2 ZkClient使用
- Jquery——简单的视差滚动效果,兼容PC移动端
- spark学习笔记总结-spark入门资料精化
- 在eclipse中使用maven创建springMVC项目
- 踩的python列表及for循环一个坑儿
- hdu 3006 枚举集合能够产生的全部并集的集合
- python发送各类邮件的主要方法
- 在线API大全
- java静态方法之线程安全问题
- Android开源库loopj的android-async-http的 JsonHttpResponseHandler 存在死循环GC_CONCURRENT
- seajs简记
- 拍照、本地图片工具类(兼容至Android7.0)
- 怎样在Spark、Flink应用中使用Protobuf 3的包
- css实现椭圆、半椭圆
- Java求最大公约数和最小公倍数
- react-native导航器 react navigation 介绍
- 我用 tensorflow 实现的“一个神经聊天模型”:一个基于深度学习的聊天机器人
- Matlab imshow, image, imagesc 三者详细分析
- NAT(Network Address Translation)
- OSG 改变窗口大小
热门文章
- 基于Redo Log和Undo Log的MySQL崩溃恢复流程
- : cannot validate certificate for 127.0.0.1 because it doesn't contain any IP SANs
- LOJ10077
- eclipse项目放到github
- SANGFOR AC配置AD域单点登录(一)----AC侧配置
- PHP-数组相关知识总结
- DolphinScheduler源码分析之EntityTestUtils类
- TypeScript中 typeof ArrayInstance[number] 剖析
- 2017-2018 ACM-ICPC Latin American Regional Programming Contest PART (11/13)
- int和longlong的范围