Closed hkouns closed 8 years ago
JS version of Math: Handlebars.registerHelper("math", function(lvalue, operator, rvalue, options) { lvalue = parseFloat(lvalue); rvalue = parseFloat(rvalue);
return {
"+": lvalue + rvalue,
"-": lvalue - rvalue,
"*": lvalue * rvalue,
"/": lvalue / rvalue,
"%": lvalue % rvalue
}[operator];
});
Every Nth: Handlebars.registerHelper('everyNth', function(context, every, options) { var fn = options.fn, inverse = options.inverse; var ret = ""; if(context && context.length > 0) { for(var i=0, j=context.length; i<j; i++) { var modZero = i % every === 0; ret = ret + fn(_.extend({}, context[i], { isModZero: modZero, isModZeroNotFirst: modZero && i > 0, isLast: i === context.length - 1 })); } } else { ret = inverse(this); } return ret; });
Currency ... take Type of Currency... and number of digits. e.g.: convert: 34.3478 to: $34.35 {{currency "$" 2 val}}
UPDATE: use FmtNum instead
FmtNum
Standard formats, with their related outputs,
String s = String.Format("(C) Currency: . . . . . . . . {0:C}\n" + "(D) Decimal:. . . . . . . . . {0:D}\n" + "(E) Scientific: . . . . . . . {1:E}\n" + "(F) Fixed point:. . . . . . . {1:F}\n" + "(G) General:. . . . . . . . . {0:G}\n" + " (default):. . . . . . . . {0} (default = 'G')\n" + "(N) Number: . . . . . . . . . {0:N}\n" + "(P) Percent:. . . . . . . . . {1:P}\n" + "(R) Round-trip: . . . . . . . {1:R}\n" + "(X) Hexadecimal:. . . . . . . {0:X}\n",
{{FmtAddress PID "type" lines}}
type = F or P Lines = 1, 2, 3
Date Time:
{{Now}}
{{FmtDT date "fmt"}} (NEED TO LOOK AT EXISTING FmtDate Helper...
date being passed to helper fmt string complying with https://msdn.microsoft.com/en-us/library/8kb3ddd4(v=vs.110).aspx#
returns a string thisDate1 = new DateTime(2011, 6, 10); Console.WriteLine("Today is " + thisDate1.ToString("MMMM dd, yyyy")
{{DateOffset date value "type"}}
type is d for day, m for month, y for year
FmtPhone(string s, string prefix)
InOrg InSubGroup
int WeekNumber(object dt) SundayForDate(object dt) SundayForWeek(int year, int week) MostRecentAttendedSunday(int progid)
Submitted PR https://github.com/bvcms/bvcms/pull/81
Math Every nth