Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge branch 'master' of github.com:mde/utilities

  • Loading branch information...
commit 2addf6699f5c349866297b4b111d3daeaf3e216a 2 parents d14be8a + f248d44
mde authored
View
12 lib/date.js
@@ -202,7 +202,7 @@ date = new (function () {
@public
@function
@return {String} The `dt` formated with the given `format`
- @description Formats the given date with the strftime format
+ @description Formats the given date with the strftime formated
@param {Date} dt the date object to format
@param {String} format the format to convert the date to
*/
@@ -242,7 +242,7 @@ date = new (function () {
@function
@return {String} The century for the given date
@description Find the century for the given `year`
- @param {String} year The year to find the century for
+ @param {Number} year The year to find the century for
*/
this.calcCentury = function (year) {
if(!year) {
@@ -335,7 +335,7 @@ date = new (function () {
@return {String} Return a 24 hour version of the given time
@description Convert a 12-hour formatted hour with meridian flag to 24-hour format
@param {String} hour The hour to convert
- @param {Boolean} If hour is PM then this should be true
+ @param {Boolean} pm hour is PM then this should be true
*/
this.hrStd2Mil = function (hour, pm) {
var h = typeof hour == 'number' ? hour : parseInt(hour);
@@ -378,7 +378,7 @@ date = new (function () {
@function
@return {Date} Incremented date
@description Add to a Date in intervals of different size, from
- milliseconds to years
+ milliseconds to years
@param {Date} dt Date (or timestamp Number), date to increment
@param {String} interv a constant representing the interval,
e.g. YEAR, MONTH, DAY. See this.dateParts
@@ -484,7 +484,7 @@ date = new (function () {
@return {Number} number of (interv) units apart that
the two dates are
@description Get the difference in a specific unit of time (e.g., number
- of months, weeks, days, etc.) between two dates.
+ of months, weeks, days, etc.) between two dates.
@param {Date} date1 First date to check
@param {Date} date2 Date to compate `date1` with
@param {String} interv a constant representing the interval,
@@ -649,7 +649,7 @@ date = new (function () {
@function
@return {Date} a JavaScript Date object
@description Convert various sorts of strings to JavaScript
- Date objects
+ Date objects
@param {String} val The string to convert to a Date
*/
this.parse = function (val) {
View
2  lib/event_buffer.js
@@ -60,7 +60,7 @@ EventBuffer.prototype = new (function () {
@public
@function
@description Emit an event by name and arguments or add it to the buffer if
- no outlet is set
+ no outlet is set
@param {String} name The name to use for the event
@param {Array} args An array of arguments to emit
*/
View
1  lib/request.js
@@ -49,6 +49,7 @@ var formatters = {
@param {Object} [opts.headers] Headers to send on requests
@param {String} [opts.data] Data to send on POST and PUT requests
@param {String} [opts.dataType] The type of data to send
+ @param {Function} callback the function to call after, args are `error, data`
*/
var request = function (opts, callback) {
var client
View
6 lib/string.js
@@ -108,7 +108,7 @@ string = new (function () {
@function
@return {String} A string of escaped characters
@description Escapes regex control-characters in strings
- used to build regexes dynamically
+ used to build regexes dynamically
@param {String} string The string of chars to escape
*/
this.escapeRegExpChars = (function () {
@@ -219,8 +219,8 @@ string = new (function () {
@public
@function
@description Returns a new String with the last character removed. If the
- string ends with \r\n, both characters are removed. Applying chop to an
- empty string returns an empty string.
+ string ends with \r\n, both characters are removed. Applying chop to an
+ empty string returns an empty string.
@param {String} string to return with the last character removed.
*/
this.chop = function (string) {
View
2  lib/uri.js
@@ -37,7 +37,7 @@ uri = new (function () {
@public
@function
@return {String} Returns the file extension for a given path
- @description Gets the file extension fir a path and returns it
+ @description Gets the file extension for a path and returns it
@param {String} path The path to get the extension for
*/
this.getFileExtension = function (path) {
View
41 test/string.js
@@ -238,8 +238,45 @@ tests = {
assert.equal(expected, data);
}
- // We could test truncate and truncateHTML here, but helper tests already
- // include tests for them
+, 'test single tags in truncateHTML': function () {
+ var str = string.truncateHTML('<p>Once upon a time in a world</p>', { length: 10 });
+ assert.equal(str, '<p>Once up...</p>');
+ }
+
+, 'test multiple tags in truncateHTML': function () {
+ var str = string.truncateHTML('<p>Once upon a time <small>in a world</small></p>', { length: 10 });
+ assert.equal(str, '<p>Once up...<small>in a wo...</small></p>');
+ }
+
+, 'test multiple tags but only truncate once in truncateHTML': function () {
+ var str = string.truncateHTML('<p>Once upon a time <small>in a world</small></p>', { length: 10, once: true });
+ assert.equal(str, '<p>Once up...<small>in a world</small></p>');
+ }
+
+, 'test standard truncate': function () {
+ var str = string.truncate('Once upon a time in a world', { length: 10 });
+ assert.equal(str, 'Once up...');
+ }
+
+, 'test custom omission in truncate': function () {
+ var str = string.truncate('Once upon a time in a world', { length: 10, omission: '///' });
+ assert.equal(str, 'Once up///');
+ }
+
+, 'test regex seperator in truncate': function () {
+ var str = string.truncate('Once upon a time in a world', { length: 15, seperator: /\s/ });
+ assert.equal(str, 'Once upon a...');
+ }
+
+, 'test string seperator in truncate': function () {
+ var str = string.truncate('Once upon a time in a world', { length: 15, seperator: ' ' });
+ assert.equal(str, 'Once upon a...');
+ }
+
+, 'test unsafe html in truncate': function () {
+ var str = string.truncate('<p>Once upon a time in a world</p>', { length: 20 });
+ assert.equal(str, '<p>Once upon a ti...');
+ }
, 'test nl2br for string': function () {
var data = string.nl2br("geddy\n")
Please sign in to comment.
Something went wrong with that request. Please try again.