diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b6ddbb7 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/align-text-1.0.2.tgz diff --git a/README.md b/README.md deleted file mode 100644 index 6b894d5..0000000 --- a/README.md +++ /dev/null @@ -1,3 +0,0 @@ -# nodejs-align-text - -'Align the text in a string' \ No newline at end of file diff --git a/nodejs-align-text.spec b/nodejs-align-text.spec new file mode 100644 index 0000000..9c51723 --- /dev/null +++ b/nodejs-align-text.spec @@ -0,0 +1,70 @@ +%{?nodejs_find_provides_and_requires} + +%global packagename align-text +%global enable_tests 1 + +Name: nodejs-align-text +Version: 1.0.2 +Release: 1%{?dist} +Summary: Align the text in a string + +License: MIT +URL: https://github.com/jonschlinkert/align-text +Source0: https://registry.npmjs.org/%{packagename}/-/%{packagename}-%{version}.tgz +# The test files are not included in the npm tarball. +Source1: https://raw.githubusercontent.com/jonschlinkert/align-text/%{version}/test.js + + +ExclusiveArch: %{nodejs_arches} noarch +BuildArch: noarch + +BuildRequires: nodejs-packaging +%if 0%{?enable_tests} +BuildRequires: mocha +BuildRequires: npm(kind-of) +BuildRequires: npm(longest) +BuildRequires: npm(repeat-string) +BuildRequires: npm(should) +%endif + +%description +Align the text in a string. + + +%prep +%autosetup -n package +# setup the tests +cp -p %{SOURCE1} . + +%nodejs_fixdep kind-of + +%build +# nothing to do! + +%install +mkdir -p %{buildroot}%{nodejs_sitelib}/%{packagename} +cp -pr package.json index.js \ + %{buildroot}%{nodejs_sitelib}/%{packagename} + +%nodejs_symlink_deps + +%check +%nodejs_symlink_deps --check +%{__nodejs} -e 'require("./")' +%if 0%{?enable_tests} +%{_bindir}/mocha -R spec +%else +%{_bindir}/echo -e "\e[101m -=#=- Tests disabled -=#=- \e[0m" +%endif + +%files +%doc README.md +%license LICENSE +%{nodejs_sitelib}/%{packagename} + +%changelog +* Mon Sep 25 2017 Jared Smith - 1.0.2-1 +- Update to upstream 1.0.2 + +* Thu Apr 13 2017 Jared Smith - 0.1.4-1 +- Initial packaging diff --git a/sources b/sources new file mode 100644 index 0000000..ea6075c --- /dev/null +++ b/sources @@ -0,0 +1 @@ +SHA512 (align-text-1.0.2.tgz) = b813c3b3bdb3ad14dd893058d188c16ee04e757b51c93e2ab0a3dbe1b2f83bbbc7e2eb73ffb2a3c13255b156dd4e1c4c6d5ce444601f93c325df1a0cbd748463 diff --git a/test.js b/test.js new file mode 100644 index 0000000..8ba7ae3 --- /dev/null +++ b/test.js @@ -0,0 +1,114 @@ +/*! + * align-text + * + * Copyright (c) 2015-2017, Jon Schlinkert. + * Released under the MIT License. + */ + +'use strict'; + +var assert = require('assert'); +var align = require('./'); + +var fixture = [ + 'Lorem ipsum dolor sit amet,', + 'consectetur adipiscing', + 'elit, sed do eiusmod tempor incididunt', + 'ut labore et dolore', + 'magna aliqua. Ut enim ad minim', + 'veniam, quis' +]; + +var expected = [ + ' Lorem ipsum dolor sit amet,', + ' consectetur adipiscing', + 'elit, sed do eiusmod tempor incididunt', + ' ut labore et dolore', + ' magna aliqua. Ut enim ad minim', + ' veniam, quis' +]; + +var integer = [ + ' Lorem ipsum dolor sit amet,', + ' consectetur adipiscing', + ' elit, sed do eiusmod tempor incididunt', + ' ut labore et dolore', + ' magna aliqua. Ut enim ad minim', + ' veniam, quis' +]; + +var prefixed = [ + '- Lorem ipsum dolor sit amet,', + '- consectetur adipiscing', + '- elit, sed do eiusmod tempor incididunt', + '- ut labore et dolore', + '- magna aliqua. Ut enim ad minim', + '- veniam, quis' +]; + +var character = [ + '~~~~~Lorem ipsum dolor sit amet,', + '~~~~~~~~consectetur adipiscing', + 'elit, sed do eiusmod tempor incididunt', + '~~~~~~~~~ut labore et dolore', + '~~~~magna aliqua. Ut enim ad minim', + '~~~~~~~~~~~~~veniam, quis' +]; + +describe('align', function() { + describe('indent', function() { + it('should indent lines to the given value', function() { + assert.deepEqual(align(fixture, 5), integer); + }); + + it('should indent values to the longest length in an array', function() { + assert.deepEqual(align([7, 8, 9, 10]), [' 7', ' 8', ' 9', '10']); + assert.deepEqual(align(['a', ' b']), [' a', ' b']); + }); + }); + + describe('function', function() { + it('should indent a string to the returned number', function() { + var actual = align(fixture, function(len, max, line, lines) { + return Math.floor((max - len) / 2); + }); + assert.deepEqual(actual, expected); + }); + + it('should indent lines in an array to the returned number', function() { + var actual = align(fixture.join('\n'), function(len, max, line, lines) { + return Math.floor((max - len) / 2); + }); + assert.deepEqual(actual, expected.join('\n')); + }); + }); + + describe('object', function() { + it('should use the `indent` property', function() { + var actual = align(fixture, function(len, max, line, lines) { + return { indent: Math.floor((max - len) / 2) }; + }); + assert.deepEqual(actual, expected); + }); + + it('should use the `prefix` property', function() { + var actual = align(fixture, function(len, max, line, lines) { + return { prefix: '- ' }; + }); + assert.deepEqual(actual, prefixed); + }); + + it('should use the `character` property', function() { + var actual = align(fixture, function(len, max, line, lines) { + return { indent: Math.floor((max - len) / 2), character: '~', }; + }); + assert.deepEqual(actual, character); + }); + }); + + it('should throw an error on invalid args', function() { + assert.throws(function() { + align(); + }); + }); +});