pad

2018-12-07 admin

pad是什么

什么是pad,Left and right string padding

pad使用教程帮助文档

Node.js pad

Build Status

Node Pad is a simple and elegant function to pad strings in both left and right directions.

Usage

The API is quite simple:

const pad = require('pad')
pad('pad', 5)      // "pad  "
pad(5, 'pad')      // "  pad"
pad('pad', 5, '+') // "pad++"
pad(5, 'pad', '+') // "++pad"

For TypeScript users, the type definition file is located in “./lib/index.d.ts” and declared inside the “package.json” file.

This package is written for ES6 supported by Node.js version 7.5 and above. For older browsers or older versions of Node.js, use the modules inside “./lib/es5”.

const pad = require('pad/lib/es5')
pad('pad', 5)      // "pad  "

Options

Options are provided as a third argument and are all optional. A string argument it is interpreted as the “char” option. Accepted options include:

  • char (string) The character used to fill the gap.
  • colors (boolean) Ajust to hidden terminal color characters, you may also use require 'pad/lib/colors' to avoid passing this option.
  • strip (boolean) Remove characters from text if length smaller than text length, default to “false”.
  • fixed_width (boolean) An optimization option to disable the usage of the wcwdith package to handle the discovery of characters using more than one column for display. one column to display
  • wcwidth_options (object) Options passed to the wcwidth package used to calculate the display width of characters using more than one column.

Left padding: pad(length, text, [options])

Left padding occurs when the first argument is a number and the second argument is a string.

var pad = require('pad');
pad(5, 'pad', '-').should.eql('--pad');

Right padding: pad(text, length, [options])

Right padding occurs when the first argument is a string and the second argument is a number.

var pad = require('pad');
pad('pad', 6).should.eql('pad   ');

Installing

Starting with version 1.1.0, Node pad rely on Node.js 4.0.0 or more recent. Stick to version 1.0.x if using an older version of Node.js.

Via npm:

npm install pad

Via git (or downloaded tarball), copy or link the project from a discoverable Node.js directory:

git clone http://github.com/wdavidw/node-pad.git

Testing

Clone the repo, install the development dependencies and run the suite:

git clone http://github.com/wdavidw/node-pad.git .
npm install
make test

本站文章除注明转载外,均为本站原创或编译。欢迎任何形式的转载,但请务必注明出处。

转载请注明:文章转载自 JavaScript中文网 [https://www.javascriptcn.com]

本文地址:https://www.javascriptcn.com/read-47499.html

文章标题:pad

相关文章
Detect iPad orientation change
Communitylolalola提出了一个问题:Detect iPad orientation change,或许与您遇到的问题类似。 回答者Karl-Bjørnar Øie给出了该问题的处理方式: Try $(window).bind(...
2018-04-24
iPad doesn't trigger resize event going from vertical to horizontal?
dclowd9901提出了一个问题:iPad doesn’t trigger resize event going from vertical to horizontal?,或许与您遇到的问题类似。 回答者Drew GaynorVincen...
2018-04-15
检测iPad / iPhone的WebView通过JavaScript
sod提出了一个问题:detect ipad/iphone webview via javascript,或许与您遇到的问题类似。 回答者ThinkingStiff给出了该问题的处理方式: This uses a combination o...
2018-03-19
trackpad-scroll-emulator
trackpad-scroll-emulator是什么 什么是trackpad-scroll-emulator,A jQuery plugin that emulates OSX trackpad-style scrollbars in a...
2018-08-12
jQuery .on() and .delegate() doesn't work on iPad
Simon ArnoldMartin.提出了一个问题:jQuery .on() and .delegate() doesn’t work on iPad,或许与您遇到的问题类似。 回答者mddw给出了该问题的处理方式: It’s a Saf...
2018-04-23
使用jQuery检测iPad用户?
SeanWM提出了一个问题:Detect iPad users using jQuery?,或许与您遇到的问题类似。 回答者CommunityRion Williams给出了该问题的处理方式: iPad Detection You shou...
2018-03-09
left-pad
left-pad是什么 什么是left-pad,String left pad left-pad官网:官网 left-pad源码仓库:源码仓库 left-pad下载地址:点此下载 点此下载2 left-pad使用教程帮助文档 left-...
2018-09-06
pad-right
pad-right是什么 什么是pad-right,Right pad a string with zeros or a specified string. Fastest implementation. pad-right官网:官网 p...
2018-09-27
Any way to make div scroll in ipad?
cat提出了一个问题:Any way to make div scroll in ipad?,或许与您遇到的问题类似。 回答者edtechdev给出了该问题的处理方式: See if this helps, the guy says the...
2018-04-13
回到顶部