From b89a7ee8b956c96a1dcee995ea840feddc5d4b27 Mon Sep 17 00:00:00 2001 From: Pierre Frisch Date: Thu, 22 Dec 2011 07:25:50 -0800 Subject: First commit of Ninja to ninja-internal Signed-off-by: Valerio Virgillito --- js/helper-classes/Utils.js | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 js/helper-classes/Utils.js (limited to 'js/helper-classes/Utils.js') diff --git a/js/helper-classes/Utils.js b/js/helper-classes/Utils.js new file mode 100644 index 00000000..1cfc390e --- /dev/null +++ b/js/helper-classes/Utils.js @@ -0,0 +1,33 @@ +/* +This file contains proprietary software owned by Motorola Mobility, Inc.
+No rights, expressed or implied, whatsoever to this software are provided by Motorola Mobility, Inc. hereunder.
+(c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved. +
*/ + +// Adding to the String Prototype little utility function to capitalize the first Char of a String. +String.prototype.capitalizeFirstChar = function() { + return this.charAt(0).toUpperCase() + this.slice(1); +}; + +exports.utils = Object.create(Object.prototype, { + + getValueAndUnits: { + value: function(str) + { + var numberValue = parseFloat(str); + // Ignore all whitespace, digits, negative sign and "." when looking for units label + // The units must come after one or more digits + var objRegExp = /(\-*\d+\.*\d*)(\s*)(\w*\%*)/; + var unitsString = str.replace(objRegExp, "$3"); + if(unitsString) + { + var noSpaces = /(\s*)(\S*)(\s*)/; + // strip out spaces and convert to lower case + var match = (unitsString.replace(noSpaces, "$2")).toLowerCase(); + } + + return [numberValue, match]; + } + } + +}); \ No newline at end of file -- cgit v1.2.3