3.0.1 • Published 3 years ago

ansi-align v3.0.1

Weekly downloads
10,011,069
License
ISC
Repository
github
Last release
3 years ago

ansi-align

align-text with ANSI support for CLIs

Build Status Coverage Status Standard Version Greenkeeper badge

Easily center- or right- align a block of text, carefully ignoring ANSI escape codes.

E.g. turn this:

Into this:

Install

npm install --save ansi-align
var ansiAlign = require('ansi-align')

API

ansiAlign(text, [opts])

Align the given text per the line with the greatest string-width, returning a new string (or array).

Arguments

  • text: required, string or array

    The text to align. If a string is given, it will be split using either the opts.split value or '\n' by default. If an array is given, a different array of modified strings will be returned.

  • opts: optional, object

    Options to change behavior, see below.

Options

  • opts.align: string, default 'center'

    The alignment mode. Use 'center' for center-alignment, 'right' for right-alignment, or 'left' for left-alignment. Note that the given text is assumed to be left-aligned already, so specifying align: 'left' just returns the text as is (no-op).

  • opts.split: string or RegExp, default '\n'

    The separator to use when splitting the text. Only used if text is given as a string.

  • opts.pad: string, default ' '

    The value used to left-pad (prepend to) lines of lesser width. Will be repeated as necessary to adjust alignment to the line with the greatest width.

ansiAlign.center(text)

Alias for ansiAlign(text, { align: 'center' }).

ansiAlign.right(text)

Alias for ansiAlign(text, { align: 'right' }).

ansiAlign.left(text)

Alias for ansiAlign(text, { align: 'left' }), which is a no-op.

Similar Packages

  • center-align: Very close to this package, except it doesn't support ANSI codes.
  • left-pad: Great for left-padding but does not support center alignment or ANSI codes.
  • Pretty much anything by the chalk team

License

ISC © Contributors

boxenarchetype-libraryeasy-select-rnreact-native-bluetooth2killi8n-react-native-fast-image@cashremit/cr-streamline-iconsairscanairscan-examplereact-native-esc-pos-sahaab@borisovart/atol-kkt-moduledeneme323112@ntt_app/react-native-custom-notificationdiscord-music-botsreact-native-covid-sdk@saeon/ol-react@saeon/quick-formmysql-formatreact-native-printer-brothersreact-native-shekhar-bridge-testcogoportutilsdyx-react@oiti/documentoscopy-react-nativequoc-testunblock-block-save-variables@infinitebrahmanuniverse/nolb-ans@saaspe/componentsluminos-ui-core@everything-registry/sub-chunk-1142jawwy-sdkjawwy_gamification_releasereact-native-sphereuisphereuijawwy_libraryreact-native-credit-card-pkgreact-native-jawwy_samplewaxmiguelzeo-collect@geeky-apo/react-native-advanced-clipboardwifi_configuration_packagewangyaling-1au-libraryuimoyangtao-jsvue-v3-yandex-metrikavite_vue3_ts_ssssdddddyyyyvsnthdev@hemith/react-native-tnkfluent.adflow.reactnativesdk-alphafluent.adflow.reactnativesdkfmslfn-lib-example3.0.0jawwy_library_newjawy_library_v1gamification-jawwy-libraryframework_test_library_sixdee_new_jawwytest_lib_module_aarreact-native-create-video-thumbnailreact-native-android-video-player-viewreact-native-animate-textreact-native-additionreact-native-pulsator-nativereact-native-plugpag-wrapperreact-native-rom-componentsreact-native-rtn-ips-poslin-testreact-native-savczuk-feature-libraryreact-native-sandycomponentreact-native-shared-gesturereact-native-recent-framework-updatereact-native-reanimated-sortable-listreact-native-omental-frameworkreact-native-onrampreact-native-screen-idle-timerreact-native-scroll-tab-to-indexreact-native-progress-arrowreact-native-simple-timelinereact-native-sixdee_test_libreact-native-sp-test-commonreact-native-tilt-blereact-native-ticker-tapereact-native-ytximkitreact-native-volume-phisicalreact-native-ui-components-libraryreact-native-teads-sdk-modulereact-native-tejab41097-sample-libraryreact-native-teknoctrl-componentsreact-native-syan-photo-pickerreact-native-transtracker-libraryreact-native-tone-frameworkreact-native-test-viewreact-native-test-comlibraryreact-native-test-module-hhhreact-native-wtfreact-native-xprinter-thermal-blereact-native-uvc-camera-androidreact-native-version-appreact-native-withframework-checkreactnativelyresponsive-image-builderrn_unique_device_id
3.0.1

3 years ago

3.0.0

5 years ago

2.0.0

7 years ago

1.1.0

8 years ago

1.0.0

8 years ago