├── .editorconfig ├── .gitattributes ├── .gitignore ├── .jshintrc ├── .travis.yml ├── .verb.md ├── LICENSE ├── README.md ├── index.js ├── package.json └── test.js /.editorconfig: -------------------------------------------------------------------------------- 1 | # http://editorconfig.org 2 | root = true 3 | 4 | [*] 5 | indent_style = space 6 | end_of_line = lf 7 | charset = utf-8 8 | indent_size = 2 9 | trim_trailing_whitespace = true 10 | insert_final_newline = true 11 | 12 | [*.json] 13 | indent_style = space 14 | indent_size = 2 15 | 16 | [*.yml] 17 | indent_style = space 18 | indent_size = 2 19 | 20 | [*.md] 21 | indent_style = space 22 | indent_size = 2 23 | trim_trailing_whitespace = false 24 | 25 | [test/fixtures/*] 26 | trim_trailing_whitespace = false 27 | insert_final_newline = false 28 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Enforce Unix newlines 2 | * text eol=lf 3 | 4 | # binaries 5 | *.ai binary 6 | *.psd binary 7 | *.jpg binary 8 | *.gif binary 9 | *.png binary 10 | *.jpeg binary 11 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.DS_Store 2 | *.sublime-* 3 | _gh_pages 4 | bower_components 5 | node_modules 6 | npm-debug.log 7 | actual 8 | test/actual 9 | temp 10 | tmp 11 | TODO.md 12 | vendor 13 | -------------------------------------------------------------------------------- /.jshintrc: -------------------------------------------------------------------------------- 1 | { 2 | "asi": false, 3 | "boss": true, 4 | "curly": true, 5 | "eqeqeq": true, 6 | "eqnull": true, 7 | "esnext": true, 8 | "immed": true, 9 | "latedef": false, 10 | "laxcomma": false, 11 | "mocha": true, 12 | "newcap": true, 13 | "noarg": true, 14 | "node": true, 15 | "sub": true, 16 | "undef": true, 17 | "unused": true 18 | } 19 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: false 2 | language: node_js 3 | node_js: 4 | - "0.10" 5 | - "0.12" 6 | - "iojs" 7 | git: 8 | depth: 10 9 | -------------------------------------------------------------------------------- /.verb.md: -------------------------------------------------------------------------------- 1 | # {%= name %} {%= badge("fury") %} 2 | 3 | > {%= description %} 4 | 5 | {%= include("install-npm", {save: true}) %} 6 | 7 | ## Usage 8 | 9 | ```js 10 | var rightAlign = require('{%= name %}'); 11 | rightAlign(string); 12 | ``` 13 | 14 | **Example** 15 | 16 | If used on the following: 17 | 18 | ``` 19 | Lorem ipsum dolor sit amet, 20 | consectetur adipiscing 21 | elit, sed do eiusmod tempor incididunt 22 | ut labore et dolore 23 | magna aliqua. Ut enim ad minim 24 | veniam, quis 25 | ``` 26 | 27 | The result would be: 28 | 29 | ``` 30 | Lorem ipsum dolor sit amet, 31 | consectetur adipiscing 32 | elit, sed do eiusmod tempor incididunt 33 | ut labore et dolore 34 | magna aliqua. Ut enim ad minim 35 | veniam, quis 36 | ``` 37 | 38 | 39 | ## Related projects 40 | {%= related(['center-align', 'align-text', 'justify', 'word-wrap', 'repeat-string', 'repeat-element']) %} 41 | 42 | ## Running tests 43 | {%= include("tests") %} 44 | 45 | ## Contributing 46 | {%= include("contributing") %} 47 | 48 | ## Author 49 | {%= include("author") %} 50 | 51 | ## License 52 | {%= copyright() %} 53 | {%= license() %} 54 | 55 | *** 56 | 57 | {%= include("footer") %} 58 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015, Jon Schlinkert. 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # right-align [![NPM version](https://badge.fury.io/js/right-align.svg)](http://badge.fury.io/js/right-align) 2 | 3 | > Right-align the text in a string. 4 | 5 | Install with [npm](https://www.npmjs.com/) 6 | 7 | ```sh 8 | $ npm i right-align --save 9 | ``` 10 | 11 | ## Usage 12 | 13 | ```js 14 | var rightAlign = require('right-align'); 15 | rightAlign(string); 16 | ``` 17 | 18 | **Example** 19 | 20 | If used on the following: 21 | 22 | ``` 23 | Lorem ipsum dolor sit amet, 24 | consectetur adipiscing 25 | elit, sed do eiusmod tempor incididunt 26 | ut labore et dolore 27 | magna aliqua. Ut enim ad minim 28 | veniam, quis 29 | ``` 30 | 31 | The result would be: 32 | 33 | ``` 34 | Lorem ipsum dolor sit amet, 35 | consectetur adipiscing 36 | elit, sed do eiusmod tempor incididunt 37 | ut labore et dolore 38 | magna aliqua. Ut enim ad minim 39 | veniam, quis 40 | ``` 41 | 42 | ## Related projects 43 | 44 | * [align-text](https://github.com/jonschlinkert/align-text): Align the text in a string. 45 | * [center-align](https://github.com/jonschlinkert/center-align): Center-align the text in a string. 46 | * [justify](https://github.com/bahamas10/node-justify): Left or right (or both) justify text using a custom width and character 47 | * [repeat-string](https://github.com/jonschlinkert/repeat-string): Repeat the given string n times. Fastest implementation for repeating a string. 48 | * [repeat-element](https://github.com/jonschlinkert/repeat-element): Create an array by repeating the given value n times. 49 | * [word-wrap](https://github.com/jonschlinkert/word-wrap): Wrap words to a specified length. 50 | 51 | ## Running tests 52 | 53 | Install dev dependencies: 54 | 55 | ```sh 56 | $ npm i -d && npm test 57 | ``` 58 | 59 | ## Contributing 60 | 61 | Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](https://github.com/jonschlinkert/right-align/issues/new) 62 | 63 | ## Author 64 | 65 | **Jon Schlinkert** 66 | 67 | + [github/jonschlinkert](https://github.com/jonschlinkert) 68 | + [twitter/jonschlinkert](http://twitter.com/jonschlinkert) 69 | 70 | ## License 71 | 72 | Copyright © 2015 Jon Schlinkert 73 | Released under the MIT license. 74 | 75 | *** 76 | 77 | _This file was generated by [verb-cli](https://github.com/assemble/verb-cli) on June 09, 2015._ 78 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | /*! 2 | * right-align 3 | * 4 | * Copyright (c) 2015, Jon Schlinkert. 5 | * Licensed under the MIT License. 6 | */ 7 | 8 | 'use strict'; 9 | 10 | var align = require('align-text'); 11 | 12 | module.exports = function rightAlign(val) { 13 | return align(val, function (len, longest) { 14 | return longest - len; 15 | }); 16 | }; 17 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "right-align", 3 | "description": "Right-align the text in a string.", 4 | "version": "0.1.3", 5 | "homepage": "https://github.com/jonschlinkert/right-align", 6 | "author": { 7 | "name": "Jon Schlinkert", 8 | "url": "https://github.com/jonschlinkert" 9 | }, 10 | "repository": { 11 | "type": "git", 12 | "url": "git://github.com/jonschlinkert/right-align.git" 13 | }, 14 | "bugs": { 15 | "url": "https://github.com/jonschlinkert/right-align/issues" 16 | }, 17 | "license": "MIT", 18 | "files": [ 19 | "index.js" 20 | ], 21 | "main": "index.js", 22 | "engines": { 23 | "node": ">=0.10.0" 24 | }, 25 | "scripts": { 26 | "test": "mocha" 27 | }, 28 | "dependencies": { 29 | "align-text": "^0.1.1" 30 | }, 31 | "devDependencies": { 32 | "mocha": "*", 33 | "should": "*" 34 | }, 35 | "keywords": [ 36 | "align", 37 | "align-center", 38 | "center", 39 | "center-align", 40 | "right", 41 | "right-align", 42 | "text", 43 | "typography" 44 | ] 45 | } 46 | -------------------------------------------------------------------------------- /test.js: -------------------------------------------------------------------------------- 1 | /*! 2 | * right-align 3 | * 4 | * Copyright (c) 2015 Jon Schlinkert. 5 | * Licensed under the MIT license. 6 | */ 7 | 8 | 'use strict'; 9 | 10 | var assert = require('assert'); 11 | var should = require('should'); 12 | var rightAlign = require('./'); 13 | 14 | var fixture = [ 15 | 'Lorem ipsum dolor sit amet,', 16 | 'consectetur adipiscing', 17 | 'elit, sed do eiusmod tempor incididunt', 18 | 'ut labore et dolore', 19 | 'magna aliqua. Ut enim ad minim', 20 | 'veniam, quis' 21 | ]; 22 | 23 | var expected = [ 24 | ' Lorem ipsum dolor sit amet,', 25 | ' consectetur adipiscing', 26 | 'elit, sed do eiusmod tempor incididunt', 27 | ' ut labore et dolore', 28 | ' magna aliqua. Ut enim ad minim', 29 | ' veniam, quis' 30 | ]; 31 | 32 | describe('rightAlign', function () { 33 | it('should right align the strings in an array of strings:', function () { 34 | rightAlign(fixture).should.eql(expected); 35 | }); 36 | 37 | it('should right align the lines in a string:', function () { 38 | rightAlign(fixture.join('\n')).should.eql(expected.join('\n')); 39 | }); 40 | }); 41 | --------------------------------------------------------------------------------