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

相关文章
left-pad
left-pad是什么 什么是left-pad,String left pad left-pad官网:官网 left-pad源码仓库:源码仓库 left-pad下载地址:点此下载 点此下载2 left-pad使用教程帮助文档 left-...
2018-09-06
How can I request an increase to the HTML5 localstorage size on iPad, like the FT web app does?
Paul D. WaiteFrancescoR提出了一个问题:How can I request an increase to the HTML5 localstorage size on iPad, like the FT web app...
2018-04-21
Is there a way to use Webkit Inspector Remote Debugging in iPad?
undefinedTower提出了一个问题:Is there a way to use Webkit Inspector Remote Debugging in iPad?,或许与您遇到的问题类似。 回答者TomPaul Beusterie...
2018-04-27
行内元素的padding和margin是否有效
行内元素的纵向padding和margin都是不考虑的,这是css规范定义的。inline元素确实可以设置垂直方向的padding和margin值,但是inline元素的margin和padding的垂直方向上不产生边距效果,即不影响布局。...
2018-05-22
pad-right
pad-right是什么 什么是pad-right,Right pad a string with zeros or a specified string. Fastest implementation. pad-right官网:官网 p...
2018-09-27
Detect iPad orientation change
Communitylolalola提出了一个问题:Detect iPad orientation change,或许与您遇到的问题类似。 回答者Karl-Bjørnar Øie给出了该问题的处理方式: Try $(window).bind(...
2018-04-24
检测iPad / iPhone的WebView通过JavaScript
sod提出了一个问题:detect ipad/iphone webview via javascript,或许与您遇到的问题类似。 回答者ThinkingStiff给出了该问题的处理方式: This uses a combination o...
2018-03-19
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
pad-stream
pad-stream是什么 什么是pad-stream,Pad each line in a stream pad-stream官网:官网 pad-stream源码仓库:源码仓库 pad-stream下载地址:点此下载 点此下载2 pa...
2018-11-04
html+css面试题 行内元素padding和margin
看到一个面试题 关于行内元素span的 <style> * { padding: 0; margin: 0; } spa...
2019-01-05
回到顶部