npmString相关

1.pad-left

左侧填充零或指定字符串的字符串

npm install pad-left --save

var pad = require('pad-left');
pad(  '4', 4, '0') // 0004
pad( '35', 4, '0') // 0035
pad('459', 4, '0') // 0459

2. decamelize

大写驼峰式转小写

npm install decamelize

const decamelize = require('decamelize');

decamelize('unicornRainbow');
//=> 'unicorn_rainbow'

decamelize('unicornRainbow', '-');
//=> 'unicorn-rainbow'

input

Type: string

separator

Type: string
Default: _

3.to-camel-case

将字符串装换为驼峰式

npm install to-camel-case

var toCamelCase = require('to-camel-case')

toCamelCase('space case')  // "spaceCase"
toCamelCase('snake_case')  // "snakeCase"
toCamelCase('dot.case')    // "dotCase"
toCamelCase('weird[case')  // "weirdCase"

4.to-capital-case

将字符串所有单词转换为首字母大写

npm install to-capital-case

var toCapitalCase = require('to-capital-case')

toCapitalCase('camelCase')        // "Camel Case"
toCapitalCase('space case')       // "Space Case"
toCapitalCase('snake_case')       // "Snake Case"
toCapitalCase('dot.case')         // "Dot Case"
toCapitalCase('some*weird[case')  // "Some Weird Case"

5.to-dot-case

将单词用 . 连接

npm install to-dot-case

var toDotCase = require('to-dot-case')

toDotCase('camelCase')   // "camel.case"
toDotCase('space case')  // "snake.case"
toDotCase('slug-case')   // "slug.case"
toDotCase('weird[case')  // "weird.case"

6.slice.js

将字符串或者数组剪切

npm install slice.js

// for array
const arr = slice([1, '2', 3, '4', 5, '6', 7, '8', 9, '0']);

arr[-2];        // 9
arr['2:5'];         // [3, '4', 5]
arr[':-2'];         // [1, '2', 3, '4', 5, '6', 7, '8']
arr['-2:'];         // [9, '0']
arr['1:5:2'];       // ['2', '4']
arr['5:1:-2'];      // ['6', '4']

// for string
const str = slice('1234567890');

str[-2];        // '9'
str['2:5'];         // '345'
str[':-2'];         // '12345678'
str['-2:'];         // '90'
str['1:5:2'];       // '24'
str['5:1:-2'];      // '64'
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • rljs by sennchi Timeline of History Part One The Cognitiv...
    sennchi阅读 7,448评论 0 10
  • 前言 最先接触编程的知识是在大学里面,大学里面学了一些基础的知识,c语言,java语言,单片机的汇编语言等;大学毕...
    oceanfive阅读 3,130评论 0 7
  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 134,933评论 18 139
  • 标签(空格分隔): 编程 Go官方文档 Using the tour 1.1 Hello, 世界 Welcome...
    uangianlap阅读 1,542评论 0 5
  • 我们都是渺小星辰,但聚在一起就汇成了巨大的力量。
    Y_5458阅读 311评论 0 0