aboutsummaryrefslogtreecommitdiff
path: root/node_modules/montage-user/core/converter/trim-converter.js
diff options
context:
space:
mode:
Diffstat (limited to 'node_modules/montage-user/core/converter/trim-converter.js')
-rwxr-xr-xnode_modules/montage-user/core/converter/trim-converter.js73
1 files changed, 73 insertions, 0 deletions
diff --git a/node_modules/montage-user/core/converter/trim-converter.js b/node_modules/montage-user/core/converter/trim-converter.js
new file mode 100755
index 00000000..2675b3e7
--- /dev/null
+++ b/node_modules/montage-user/core/converter/trim-converter.js
@@ -0,0 +1,73 @@
1/* <copyright>
2 This file contains proprietary software owned by Motorola Mobility, Inc.<br/>
3 No rights, expressed or implied, whatsoever to this software are provided by Motorola Mobility, Inc. hereunder.<br/>
4 (c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved.
5 </copyright> */
6/**
7 @module montage/core/converter/trim-converter
8 @requires montage/core/core
9 @requires montage/core/converter/converter
10*/
11var Montage = require("montage").Montage;
12var Converter = require('core/converter/converter').Converter;
13
14
15/**
16 Trims a string of any leading or trailing white space.
17 @memberof module:montage/core/converter#
18 @function
19 @param {String} str String to be trimmed.
20 @returns {String} The trimmed string.
21 */
22var trim = exports.trim = function(str) {
23 // from Google Closure library
24 // Since IE doesn't include non-breaking-space (0xa0) in their \s character
25 // class (as required by section 7.2 of the ECMAScript spec), we explicitly
26 // include it in the regexp to enforce consistent cross-browser behavior.
27 return str.replace(/^[\s\xa0]+|[\s\xa0]+$/g, '');
28};
29/**
30 @class module:montage/core/converter/trim-converter.TrimConverter
31 @classdesc Trims a string of white space.
32 @example
33 <caption>Removes leading and trailing white space from a string.</caption>
34 var Converter= require("core/converter/converter").Converter,
35 TrimConverter = require("core/converter/converter").TrimConverter;
36 var str = " Hello World ";
37 var trimConverter = TrimConverter.create();
38 console.log("After trim: " + trimConverter.convert(str));
39 // After trim: Hello World
40*/
41exports.TrimConverter = Montage.create(Converter, /** @lends module:montage/core/converter/trim-converter.TrimConverter# */ {
42 /**
43 @private
44 */
45 _convert: {
46 value: function(v) {
47 if (v && typeof v === 'string') {
48 return trim(v);
49 }
50 }
51 },
52
53 /**
54 Trims the provided string and returns the new string.
55 @function
56 @param {String} v The string to trim.
57 @returns this._convert(v)
58 */
59 convert: {value: function(v) {
60 return this._convert(v);
61 }},
62 /**
63 Reverts the conversion.
64 @function
65 @param {String} v The string to revert.
66 @returns this._convert(v)
67 */
68 revert: {value: function(v) {
69 return this._convert(v);
70 }}
71});
72
73