File tree Expand file tree Collapse file tree 2 files changed +17
-3
lines changed Expand file tree Collapse file tree 2 files changed +17
-3
lines changed Original file line number Diff line number Diff line change @@ -22,13 +22,13 @@ Template.toIdentifier = function(str) {
2222
2323var A_CODE = "a" . charCodeAt ( 0 ) ;
2424var Z_CODE = "z" . charCodeAt ( 0 ) ;
25- var AZ_COUNT = Z_CODE - A_CODE ;
25+ var AZ_COUNT = Z_CODE - A_CODE + 1 ;
2626var A2_CODE = "A" . charCodeAt ( 0 ) ;
2727var Z2_CODE = "Z" . charCodeAt ( 0 ) ;
28- var AZ2_COUNT = Z2_CODE - A2_CODE ;
28+ var AZ2_COUNT = Z2_CODE - A2_CODE + 1 ;
2929Template . numberToIdentifer = function numberToIdentifer ( n ) {
3030 if ( n < AZ_COUNT ) return String . fromCharCode ( A_CODE + n ) ;
31- if ( n < AZ_COUNT + AZ2_COUNT ) return String . fromCharCode ( A2_CODE + n + AZ_COUNT ) ;
31+ if ( n < AZ_COUNT + AZ2_COUNT ) return String . fromCharCode ( A2_CODE + n - AZ_COUNT ) ;
3232 return "_" + ( n - AZ_COUNT - AZ2_COUNT ) ;
3333} ;
3434
Original file line number Diff line number Diff line change @@ -7,4 +7,18 @@ describe("Template", function() {
77 it ( "should generate valid identifiers" , function ( ) {
88 template . toIdentifier ( "0abc-def9" ) . should . equal ( "_abc_def9" ) ;
99 } ) ;
10+ it ( "should generate valid number identifiers" , function ( ) {
11+ var items = [ ] ;
12+ var item ;
13+ for ( var i = 0 ; i < 80 ; i += 1 ) {
14+ item = template . numberToIdentifer ( i ) ;
15+ if ( item === '' ) {
16+ throw new Error ( 'empty number identifier' ) ;
17+ } else if ( items . indexOf ( item ) > - 1 ) {
18+ throw new Error ( 'duplicate number identifier' ) ;
19+ } else {
20+ items . push ( item ) ;
21+ }
22+ }
23+ } ) ;
1024} ) ;
You can’t perform that action at this time.
0 commit comments