Sha256: 666ff9149de8e93ed016840929e4c183206e834f7b20c40a8eac812bf645f2fe

Contents?: true

Size: 1.79 KB

Versions: 62

Compression:

Stored size: 1.79 KB

Contents

/**
 * @namespace WORKAREA.string
 */
WORKAREA.registerModule('string', (function () {
    'use strict';

    var

        /**
         * Converts a string to lowercase and replaces all spaces width dashes.
         *
         * @param  {String} string
         * @return {String} the dasherized string
         */
        dasherize = function (string) {
            return string.replace(/\s+/g, '-').toLowerCase();
        },

        /**
         * Pluralizes a string, based on a given count.
         *
         * @param  {Integer} count - The number that determines pluralization
         * @param  {String} string - string to pluralized
         * @param  {String} pluralizedString - optional, overrides pluralized
         *                  result of the function
         * @return {String} the pluralized string
         */
        pluralize = function (count, string, pluralizedString) {
            if (count > 1 && ! _.isUndefined(pluralizedString)) {
                return pluralizedString;
            } else if (count > 1) {
                return string + 's';
            } else {
                return string;
            }
        },

        /**
         * @method
         * @name titleize
         * @memberof WORKAREA.string
         */
        titleize = function (string) {
            if ( ! _.isString(string)) {
                throw new Error('WORKAREA.string.titleize: expecting string');
            }

            return _.map(
               $.trim(string).toLowerCase().split(' '),
               function (subString) {
                   return subString.charAt(0).toUpperCase() +
                          subString.slice(1);
               }
           ).join(' ');
        };

    return {
        titleize: titleize,
        pluralize: pluralize,
        dasherize: dasherize
    };
}()));

Version data entries

62 entries across 62 versions & 1 rubygems

Version Path
workarea-core-3.5.27 app/assets/javascripts/workarea/core/modules/string.js
workarea-core-3.5.26 app/assets/javascripts/workarea/core/modules/string.js
workarea-core-3.4.45 app/assets/javascripts/workarea/core/modules/string.js
workarea-core-3.5.25 app/assets/javascripts/workarea/core/modules/string.js
workarea-core-3.5.23 app/assets/javascripts/workarea/core/modules/string.js
workarea-core-3.4.44 app/assets/javascripts/workarea/core/modules/string.js
workarea-core-3.5.22 app/assets/javascripts/workarea/core/modules/string.js
workarea-core-3.4.43 app/assets/javascripts/workarea/core/modules/string.js
workarea-core-3.5.21 app/assets/javascripts/workarea/core/modules/string.js
workarea-core-3.4.42 app/assets/javascripts/workarea/core/modules/string.js
workarea-core-3.5.20 app/assets/javascripts/workarea/core/modules/string.js
workarea-core-3.4.41 app/assets/javascripts/workarea/core/modules/string.js
workarea-core-3.5.19 app/assets/javascripts/workarea/core/modules/string.js
workarea-core-3.4.40 app/assets/javascripts/workarea/core/modules/string.js
workarea-core-3.5.18 app/assets/javascripts/workarea/core/modules/string.js
workarea-core-3.4.39 app/assets/javascripts/workarea/core/modules/string.js
workarea-core-3.5.17 app/assets/javascripts/workarea/core/modules/string.js
workarea-core-3.4.38 app/assets/javascripts/workarea/core/modules/string.js
workarea-core-3.5.16 app/assets/javascripts/workarea/core/modules/string.js
workarea-core-3.4.37 app/assets/javascripts/workarea/core/modules/string.js