diff options
Diffstat (limited to 'node_modules/montage/core/extras/string.js')
-rwxr-xr-x | node_modules/montage/core/extras/string.js | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/node_modules/montage/core/extras/string.js b/node_modules/montage/core/extras/string.js new file mode 100755 index 00000000..10b69e88 --- /dev/null +++ b/node_modules/montage/core/extras/string.js | |||
@@ -0,0 +1,79 @@ | |||
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 | Defines extensions to native String object. | ||
8 | @see [String class]{@link external:String} | ||
9 | @module montage/core/shim/string | ||
10 | */ | ||
11 | |||
12 | /** | ||
13 | @external String | ||
14 | */ | ||
15 | Object.defineProperties(String.prototype, /** @lends external:String.prototype#*/{ | ||
16 | /** | ||
17 | @function external:String.addEventListener | ||
18 | @param {Listener} type The type of event listener. | ||
19 | @param {Listener} listener The event listener. | ||
20 | @param {Function} useCapture The capturing function. | ||
21 | */ | ||
22 | addEventListener: { | ||
23 | value: function(type, listener, useCapture) { | ||
24 | //NO OP, on purpose | ||
25 | } | ||
26 | |||
27 | }, | ||
28 | /** | ||
29 | Capitalizes the first letter in the string. | ||
30 | @function external:String.toCapitalized | ||
31 | @returns {String} The original string with its first letter capitalized. | ||
32 | @example | ||
33 | var fname = "abe"; | ||
34 | var lname = "lincoln"; | ||
35 | var name = fname.toCapitalized() + " " + lname.toCapitalized(); | ||
36 | // name == "Abe Lincoln" | ||
37 | */ | ||
38 | toCapitalized: { | ||
39 | value: function() { | ||
40 | return this.charAt(0).toUpperCase() + this.slice(1); | ||
41 | } | ||
42 | }, | ||
43 | |||
44 | /** | ||
45 | Returns true if the two strings are equal, otherwise returns false. | ||
46 | @function external:String.equals | ||
47 | @param {Object} anObject The object to compare to the string. | ||
48 | @returns {Boolean} Returns true if the string is equal to <code>anObject</code>. | ||
49 | */ | ||
50 | equals: { | ||
51 | value: function(anObject) { | ||
52 | if (this.toString() === anObject) { | ||
53 | return true; | ||
54 | } | ||
55 | |||
56 | if (!anObject || !(anObject instanceof String)) { | ||
57 | return false; | ||
58 | } | ||
59 | |||
60 | return (this == anObject); | ||
61 | } | ||
62 | } | ||
63 | |||
64 | }); | ||
65 | |||
66 | /** | ||
67 | Shim implementation of String.isString() for browsers that don't yet support it. | ||
68 | @function external:String.isString() | ||
69 | @param {object} obj The object to determine if its a String. | ||
70 | @returns {boolean} Object.prototype.toString.call(obj) === "[object String]" | ||
71 | */ | ||
72 | if (!String.isString) { | ||
73 | Object.defineProperty(String, "isString", { | ||
74 | value: function(obj) { | ||
75 | return Object.prototype.toString.call(obj) === "[object String]"; | ||
76 | } | ||
77 | }); | ||
78 | } | ||
79 | |||