| OLD | NEW |
| 1 library angular.util; | 1 library angular.util; |
| 2 | 2 |
| 3 bool toBool(x) { | 3 toBool(x) { |
| 4 if (x is bool) return x; | 4 if (x is bool) return x; |
| 5 if (x is num) return x != 0; | 5 if (x is num) return x != 0; |
| 6 return false; | 6 return false; |
| 7 } | 7 } |
| 8 | 8 |
| 9 typedef FnWith0Args(); | 9 typedef FnWith0Args(); |
| 10 typedef FnWith1Args(a0); | 10 typedef FnWith1Args(a0); |
| 11 typedef FnWith2Args(a0, a1); | 11 typedef FnWith2Args(a0, a1); |
| 12 typedef FnWith3Args(a0, a1, a2); | 12 typedef FnWith3Args(a0, a1, a2); |
| 13 typedef FnWith4Args(a0, a1, a2, a3); | 13 typedef FnWith4Args(a0, a1, a2, a3); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 37 } | 37 } |
| 38 } | 38 } |
| 39 | 39 |
| 40 relaxFnArgs1(Function fn) { | 40 relaxFnArgs1(Function fn) { |
| 41 if (fn is FnWith3Args) return (_1) => fn(_1, null, null); | 41 if (fn is FnWith3Args) return (_1) => fn(_1, null, null); |
| 42 if (fn is FnWith2Args) return (_1) => fn(_1, null); | 42 if (fn is FnWith2Args) return (_1) => fn(_1, null); |
| 43 if (fn is FnWith1Args) return fn; | 43 if (fn is FnWith1Args) return fn; |
| 44 if (fn is FnWith0Args) return (_1) => fn(); | 44 if (fn is FnWith0Args) return (_1) => fn(); |
| 45 } | 45 } |
| 46 | 46 |
| 47 relaxFnArgs2(Function fn) { | |
| 48 if (fn is FnWith2Args) return fn; | |
| 49 if (fn is FnWith1Args) return (_1, _2) => fn(_1); | |
| 50 if (fn is FnWith0Args) return (_1, _2) => fn(); | |
| 51 } | |
| 52 | |
| 53 relaxFnArgs3(Function fn) { | 47 relaxFnArgs3(Function fn) { |
| 54 if (fn is FnWith3Args) return fn; | 48 if (fn is FnWith3Args) return fn; |
| 55 if (fn is FnWith2Args) return (_1, _2, _3) => fn(_1, null); | 49 if (fn is FnWith2Args) return (_1, _2, _3) => fn(_1, null); |
| 56 if (fn is FnWith1Args) return (_1, _2, _3) => fn(_1); | 50 if (fn is FnWith1Args) return (_1, _2, _3) => fn(_1); |
| 57 if (fn is FnWith0Args) return (_1, _2, _3) => fn(); | 51 if (fn is FnWith0Args) return (_1, _2, _3) => fn(); |
| 58 } | 52 } |
| 59 | 53 |
| 60 relaxFnArgs(Function fn) { | 54 relaxFnArgs(Function fn) { |
| 61 if (fn is FnWith5Args) { | 55 if (fn is FnWith5Args) { |
| 62 return ([a0, a1, a2, a3, a4]) => fn(a0, a1, a2, a3, a4); | 56 return ([a0, a1, a2, a3, a4]) => fn(a0, a1, a2, a3, a4); |
| 63 } else if (fn is FnWith4Args) { | 57 } else if (fn is FnWith4Args) { |
| 64 return ([a0, a1, a2, a3, a4]) => fn(a0, a1, a2, a3); | 58 return ([a0, a1, a2, a3, a4]) => fn(a0, a1, a2, a3); |
| 65 } else if (fn is FnWith3Args) { | 59 } else if (fn is FnWith3Args) { |
| 66 return ([a0, a1, a2, a3, a4]) => fn(a0, a1, a2); | 60 return ([a0, a1, a2, a3, a4]) => fn(a0, a1, a2); |
| 67 } else if (fn is FnWith2Args) { | 61 } else if (fn is FnWith2Args) { |
| 68 return ([a0, a1, a2, a3, a4]) => fn(a0, a1); | 62 return ([a0, a1, a2, a3, a4]) => fn(a0, a1); |
| 69 } else if (fn is FnWith1Args) { | 63 } else if (fn is FnWith1Args) { |
| 70 return ([a0, a1, a2, a3, a4]) => fn(a0); | 64 return ([a0, a1, a2, a3, a4]) => fn(a0); |
| 71 } else if (fn is FnWith0Args) { | 65 } else if (fn is FnWith0Args) { |
| 72 return ([a0, a1, a2, a3, a4]) => fn(); | 66 return ([a0, a1, a2, a3, a4]) => fn(); |
| 73 } else { | 67 } else { |
| 74 return ([a0, a1, a2, a3, a4]) { | 68 return ([a0, a1, a2, a3, a4]) { |
| 75 throw "Unknown function type, expecting 0 to 5 args."; | 69 throw "Unknown function type, expecting 0 to 5 args."; |
| 76 }; | 70 }; |
| 77 } | 71 } |
| 78 } | 72 } |
| 79 | 73 |
| 74 camelcase(String s) { |
| 75 var part = s.split('-').map((s) => s.toLowerCase()); |
| 76 if (part.length <= 1) { |
| 77 return part.join(); |
| 78 } |
| 79 return part.first + part.skip(1).map(capitalize).join(); |
| 80 } |
| 81 |
| 80 capitalize(String s) => s.substring(0, 1).toUpperCase() + s.substring(1); | 82 capitalize(String s) => s.substring(0, 1).toUpperCase() + s.substring(1); |
| 81 | 83 |
| 84 var SNAKE_CASE_REGEXP = new RegExp("[A-Z]"); |
| 82 | 85 |
| 83 /// Returns whether or not the given identifier is a reserved word in Dart. | 86 snakecase(String name, [separator = '-']) => |
| 84 bool isReservedWord(String identifier) => RESERVED_WORDS.contains(identifier); | 87 name.replaceAllMapped(SNAKE_CASE_REGEXP, (Match match) => |
| 85 | 88 (match.start != 0 ? separator : '') + match.group(0).toLowerCase()); |
| 86 final Set<String> RESERVED_WORDS = new Set<String>.from(const [ | |
| 87 "assert", | |
| 88 "break", | |
| 89 "case", | |
| 90 "catch", | |
| 91 "class", | |
| 92 "const", | |
| 93 "continue", | |
| 94 "default", | |
| 95 "do", | |
| 96 "else", | |
| 97 "enum", | |
| 98 "extends", | |
| 99 "false", | |
| 100 "final", | |
| 101 "finally", | |
| 102 "for", | |
| 103 "if", | |
| 104 "in", | |
| 105 "is", | |
| 106 "new", | |
| 107 "null", | |
| 108 "rethrow", | |
| 109 "return", | |
| 110 "super", | |
| 111 "switch", | |
| 112 "this", | |
| 113 "throw", | |
| 114 "true", | |
| 115 "try", | |
| 116 "var", | |
| 117 "void", | |
| 118 "while", | |
| 119 "with" | |
| 120 ]); | |
| OLD | NEW |