Changeset 12862

Show
Ignore:
Timestamp:
03/03/08 18:09:37 (10 months ago)
Author:
peller
Message:

Improve docs and markdown. Refs #5962

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • dojo/trunk/number.js

    r11695 r12862  
    1212} 
    1313 
    14 dojo.number.__formatOptions = function(kwArgs){ 
     14dojo.number.__FormatOptions = function(){ 
    1515        //      pattern: String? 
    1616        //              override formatting pattern with this string (see 
     
    2222        //              fixed number of decimal places to show.  This overrides any 
    2323        //              information in the provided pattern. 
    24         //      round: NUmber? 
     24        //      round: Number? 
    2525        //              5 rounds to nearest .5; 0 rounds to nearest whole (default). -1 
    2626        //              means don't round. 
     
    3131        //      locale: String? 
    3232        //              override the locale used to determine formatting rules 
     33        this.pattern = pattern; 
     34        this.type = type; 
     35        this.places = places; 
     36        this.round = round; 
     37        this.currency = currency; 
     38        this.symbol = symbol; 
     39        this.locale = locale; 
    3340} 
    3441=====*/ 
    3542 
    36 dojo.number.format = function(/*Number*/value, /*dojo.number.__formatOptions?*/options){ 
     43dojo.number.format = function(/*Number*/value, /*dojo.number.__FormatOptions?*/options){ 
    3744        // summary: 
    3845        //              Format a Number as a String, using locale-specific settings 
     
    4047        //              Create a string from a Number using a known localized pattern. 
    4148        //              Formatting patterns appropriate to the locale are chosen from the 
    42         //              CLDR http://unicode.org/cldr as well as the appropriate symbols and 
    43         //              delimiters.  See http://www.unicode.org/reports/tr35/#Number_Elements 
     49        //              [CLDR](http://unicode.org/cldr) as well as the appropriate symbols and 
     50        //              delimiters.  See <http://www.unicode.org/reports/tr35/#Number_Elements> 
    4451        // value: 
    4552        //              the number to be formatted.  If not a valid JavaScript number, 
     
    5865dojo.number._numberPatternRE = /[#0,]*[#0](?:\.0*#*)?/; // not precise, but good enough 
    5966 
    60 dojo.number._applyPattern = function(/*Number*/value, /*String*/pattern, /*dojo.number.__formatOptions?*/options){ 
     67dojo.number._applyPattern = function(/*Number*/value, /*String*/pattern, /*dojo.number.__FormatOptions?*/options){ 
    6168        // summary: 
    6269        //              Apply pattern to format value as a string using options. Gives no 
     
    6572        //              the number to be formatted. 
    6673        // pattern: 
    67         //              a pattern string as described in 
    68         //              http://www.unicode.org/reports/tr35/#Number_Format_Patterns 
    69         // options: dojo.number.__formatOptions? 
    70         //              _applyPattern is usually called via dojo.number.format() which 
     74        //              a pattern string as described by 
     75        //              [unicode.org TR35](http://www.unicode.org/reports/tr35/#Number_Format_Patterns) 
     76        // options: dojo.number.__FormatOptions? 
     77        //              _applyPattern is usually called via `dojo.number.format()` which 
    7178        //              populates an extra property in the options parameter, "customs". 
    7279        //              The customs object specifies group and decimal parameters if set. 
     
    136143 
    137144/*===== 
    138 dojo.number.__formatAbsoluteOptions = function(kwArgs){ 
     145dojo.number.__FormatAbsoluteOptions = function(){ 
    139146        //      decimal: String? 
    140147        //              the decimal separator 
     
    146153        //              5 rounds to nearest .5; 0 rounds to nearest whole (default). -1 
    147154        //              means don't round. 
     155        this.decimal = decimal; 
     156        this.group = group; 
     157        this.places = places; 
     158        this.round = round; 
    148159} 
    149160=====*/ 
    150161 
    151 dojo.number._formatAbsolute = function(/*Number*/value, /*String*/pattern, /*dojo.number.__formatAbsoluteOptions?*/options){ 
     162dojo.number._formatAbsolute = function(/*Number*/value, /*String*/pattern, /*dojo.number.__FormatAbsoluteOptions?*/options){ 
    152163        // summary:  
    153164        //              Apply numeric pattern to absolute value using options. Gives no 
     
    156167        //              the number to be formatted, ignores sign 
    157168        // pattern: 
    158         //              the number portion of a pattern (e.g. #,##0.00) 
     169        //              the number portion of a pattern (e.g. `#,##0.00`) 
    159170        options = options || {}; 
    160171        if(options.places === true){options.places=0;} 
     
    229240 
    230241/*===== 
    231 dojo.number.__regexpOptions = function(kwArgs){ 
     242dojo.number.__RegexpOptions = function(){ 
    232243        //      pattern: String? 
    233244        //              override pattern with this string.  Default is provided based on 
     
    243254        //              number of decimal places to accept: Infinity, a positive number, or 
    244255        //              a range "n,m".  By default, defined by pattern. 
     256        this.pattern = pattern; 
     257        this.type = type; 
     258        this.locale = locale; 
     259        this.strict = strict; 
     260        this.places = places; 
    245261} 
    246262=====*/ 
    247 dojo.number.regexp = function(/*dojo.number.__regexpOptions?*/options){ 
     263dojo.number.regexp = function(/*dojo.number.__RegexpOptions?*/options){ 
    248264        //      summary: 
    249265        //              Builds the regular needed to parse a number 
     
    295311                        if(parts.length == 1 || places === 0){flags.fractional = false;} 
    296312                        else{ 
    297                                 if(typeof places == "undefined"){ places = parts[1].lastIndexOf('0')+1; } 
     313                                if(places === undefined){ places = parts[1].lastIndexOf('0')+1; } 
    298314                                if(places && options.fractional == undefined){flags.fractional = true;} // required fractional, unless otherwise specified 
    299315                                if(!options.places && (places < parts[1].length)){ places += "," + parts[1].length; } 
     
    334350 
    335351/*===== 
    336 dojo.number.__parseOptions = function(kwArgs){ 
     352dojo.number.__ParseOptions = function(){ 
    337353        //      pattern: String 
    338354        //              override pattern with this string.  Default is provided based on 
     
    347363        //      currency: Object 
    348364        //              object with currency information 
     365        this.pattern = pattern; 
     366        this.type = type; 
     367        this.locale = locale; 
     368        this.strict = strict; 
     369        this.currency = currency; 
    349370} 
    350371=====*/ 
    351 dojo.number.parse = function(/*String*/expression, /*dojo.number.__parseOptions?*/options){ 
     372dojo.number.parse = function(/*String*/expression, /*dojo.number.__ParseOptions?*/options){ 
    352373        // summary: 
    353374        //              Convert a properly formatted string to a primitive Number, using 
     
    355376        // description: 
    356377        //              Create a Number from a string using a known localized pattern. 
    357         //              Formatting patterns are chosen appropriate to the locale. 
    358         //              Formatting patterns are implemented using the syntax described at 
    359         //              *URL* 
     378        //              Formatting patterns are chosen appropriate to the locale 
     379        //              and follow the syntax described by 
     380        //              [unicode.org TR35](http://www.unicode.org/reports/tr35/#Number_Format_Patterns) 
    360381        // expression: 
    361382        //              A string representation of a Number 
     
    385406 
    386407/*===== 
    387 dojo.number.__realNumberRegexpFlags = function(kwArgs){ 
     408dojo.number.__RealNumberRegexpFlags = function(){ 
    388409        //      places: Number? 
    389410        //              The integer number of decimal places or a range given as "n,m".  If 
     
    405426        //              match if it is signed or unsigned).  flags in regexp.integer can be 
    406427        //              applied. 
     428        this.places = places; 
     429        this.decimal = decimal; 
     430        this.fractional = fractional; 
     431        this.exponent = exponent; 
     432        this.eSigned = eSigned; 
    407433} 
    408434=====*/ 
    409435 
    410 dojo.number._realNumberRegexp = function(/*dojo.number.__realNumberRegexpFlags?*/flags){ 
     436dojo.number._realNumberRegexp = function(/*dojo.number.__RealNumberRegexpFlags?*/flags){ 
    411437        // summary: 
    412438        //              Builds a regular expression to match a real number in exponential 
    413439        //              notation 
    414         // flags: 
    415         //              An object 
    416440 
    417441        // assign default values to missing paramters 
    418442        flags = flags || {}; 
    419         if(typeof flags.places == "undefined"){ flags.places = Infinity; } 
     443        //TODO: use mixin instead? 
     444        if(!("places" in flags)){ flags.places = Infinity; } 
    420445        if(typeof flags.decimal != "string"){ flags.decimal = "."; } 
    421         if(typeof flags.fractional == "undefined" || /^0/.test(flags.places)){ flags.fractional = [true, false]; } 
    422         if(typeof flags.exponent == "undefined"){ flags.exponent = [true, false]; } 
    423         if(typeof flags.eSigned == "undefined"){ flags.eSigned = [true, false]; } 
     446        if(!("fractional" in flags) || /^0/.test(flags.places)){ flags.fractional = [true, false]; } 
     447        if(!("exponent" in flags)){ flags.exponent = [true, false]; } 
     448        if(!("eSigned" in flags)){ flags.eSigned = [true, false]; } 
    424449 
    425450        // integer RE 
     
    459484 
    460485/*===== 
    461 dojo.number.__integerRegexpFlags = function(kwArgs){ 
     486dojo.number.__IntegerRegexpFlags = function(){ 
    462487        //      signed: Boolean? 
    463         //              The leading plus-or-minus sign. Can be true, false, or [true, 
    464         //              false]. Default is [true, false], (i.e. will match if it is signed 
     488        //              The leading plus-or-minus sign. Can be true, false, or `[true,false]`. 
     489        //              Default is `[true, false]`, (i.e. will match if it is signed 
    465490        //              or unsigned). 
    466491        //      separator: String? 
    467492        //              The character used as the thousands separator. Default is no 
    468         //              separator. For more than one symbol use an array, e.g. [",", ""], 
     493        //              separator. For more than one symbol use an array, e.g. `[",", ""]`, 
    469494        //              makes ',' optional. 
    470495        //      groupSize: Number? 
    471496        //              group size between separators 
    472         //      flags.groupSize2: Number? 
    473         //              second grouping (for India) 
     497        //      groupSize2: Number? 
     498        //              second grouping, where separators 2..n have a different interval than the first separator (for India) 
     499        this.signed = signed; 
     500        this.separator = separator; 
     501        this.groupSize = groupSize; 
     502        this.groupSize2 = groupSize2; 
    474503} 
    475504=====*/ 
    476505 
    477 dojo.number._integerRegexp = function(/*dojo.number.__integerRegexpFlags?*/flags){ 
     506dojo.number._integerRegexp = function(/*dojo.number.__IntegerRegexpFlags?*/flags){ 
    478507        // summary:  
    479508        //              Builds a regular expression that matches an integer 
    480         // flags:  
    481         //              An object 
    482509 
    483510        // assign default values to missing paramters 
    484511        flags = flags || {}; 
    485         if(typeof flags.signed == "undefined"){ flags.signed = [true, false]; } 
    486         if(typeof flags.separator == "undefined"){ 
     512        if(!("signed" in flags)){ flags.signed = [true, false]; } 
     513        if(!("separator" in flags)){ 
    487514                flags.separator = ""; 
    488         }else if(typeof flags.groupSize == "undefined"){ 
     515        }else if(!("groupSize" in flags)){ 
    489516                flags.groupSize = 3; 
    490517        }