Skip to content

Commit

Permalink
Built sffjs from commit 6bd9eff on branch master
Browse files Browse the repository at this point in the history
  • Loading branch information
thorn0 committed Oct 16, 2015
1 parent 24dbcf1 commit 501d4d2
Show file tree
Hide file tree
Showing 4 changed files with 121 additions and 118 deletions.
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "sffjs",
"version": "1.10.0-alpha.8",
"version": "1.10.0",
"description": "String.Format for JavaScript",
"main": "sffjs.js",
"repository": {
Expand All @@ -16,17 +16,17 @@
"Daniel Mester Pirttijarvi (http://www.masterdata.se)",
"Georgii Dolzhykov <[email protected]>"
],
"license": "zlib",
"license": "Zlib",
"bugs": {
"url": "https://github.com/thorn0/sffjs/issues"
},
"homepage": "https://github.com/thorn0/sffjs",
"devDependencies": {
"grunt": "^0.4.5",
"grunt-build-control": "^0.1.3",
"grunt-build-control": "^0.6.1",
"grunt-contrib-clean": "^0.6.0",
"grunt-contrib-copy": "^0.7.0",
"grunt-contrib-uglify": "^0.6.0",
"load-grunt-tasks": "^1.0.0"
"grunt-contrib-uglify": "^0.9.2",
"load-grunt-tasks": "^3.3.0"
}
}
164 changes: 75 additions & 89 deletions sffjs.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* String.format for JavaScript, version 1.10.0-alpha.8
* String.format for JavaScript, version 1.10.0
*
* Copyright (c) 2009-2014 Daniel Mester Pirttijärvi
* http://mstr.se/sffjs
Expand Down Expand Up @@ -46,8 +46,8 @@

// ***** Private Variables *****

// This is the default values of a culture. Any missing format will default to the format in CULTURE_TEMPLATE.
// The invariant culture is generated from these default values.
// This is the default values of a culture. Any missing format will default to the format in CULTURE_TEMPLATE.
// The invariant culture is generated from these default values.
var CULTURE_TEMPLATE = {
name: "", // Empty on invariant culture
d: "MM/dd/yyyy",
Expand All @@ -63,7 +63,7 @@
_t: ",", // Thounsands separator
_c: "¤#,0.00", // Currency format string
_ct: ",", // Currency thounsands separator
_cr: ".", // Currency radix point
_cr: ".", // Currency radix point
_am: "AM",
_pm: "PM"
},
Expand All @@ -81,7 +81,6 @@
// Holds all registered external cultures, i.e. not the invariant culture
cultures = {};


// ***** Private Methods *****

// General helpers
Expand Down Expand Up @@ -140,7 +139,6 @@
sffjs.LC = currentCulture = result || INVARIANT_CULTURE;
}


// Maths

function numberToString(number, decimals) {
Expand All @@ -164,7 +162,6 @@
return point < 0 ? 0 : numberString.length - point - 1;
}


// Formatting helpers

function resolvePath(path, value) {
Expand All @@ -177,8 +174,8 @@

// Parse and evaluate path
if (hasValue(value)) {
var followingMembers = /(\.([a-zA-Z_$]\w+)|\[(\d+)\])/g,
match = /^[a-zA-Z_$]\w+/.exec(path);
var followingMembers = /(\.([a-zA-Z_$]\w*)|\[(\d+)\])/g,
match = /^[a-zA-Z_$]\w*/.exec(path);

value = value[match[0]];

Expand Down Expand Up @@ -215,14 +212,6 @@
}
}

function unescapeBraces(braces, consumedBraces) {
/// <summary>Replaces escaped brackets ({ and }) with their unescaped representation.</summary>
/// <param name="braces">A string containing braces of a single type only.</param>
/// <param name="consumedBraces">The number of braces that should be ignored when unescaping.</param>
/// <returns>A string of the unescaped braces.</returns>
return braces.substr(0, (braces.length + 1 - (consumedBraces || 0)) / 2);
}

function processFormatItem(pathOrIndex, align, formatString, args) {
/// <summary>Process a single format item in a composite format string</summary>
/// <param name="pathOrIndex" type="String">The raw argument index or path component of the format item.</param>
Expand Down Expand Up @@ -361,7 +350,7 @@
// This is the way .NET handles things.
if (i < 0) break;

// Check for single escaped character
// Check for single escaped character
} else if (c === "\\") {
i++;

Expand Down Expand Up @@ -425,12 +414,12 @@
if (endIndex < 0) break;
f = endIndex;

// Single escaped character
// Single escaped character
} else if (c === "\\") {
out.push(format.charAt(f + 1));
f++;

// Digit placeholder
// Digit placeholder
} else if (c === "#" || c === "0") {
if (i < integralDigits) {
// In the integral part
Expand All @@ -454,13 +443,13 @@

i++;

// Radix point character according to current culture.
// Radix point character according to current culture.
} else if (c === ".") {
if (number.length > ++i || forcedDecimals > 0) {
out.push(radixPoint);
}

// Other characters are written as they are, except from commas
// Other characters are written as they are, except from commas
} else if (c !== ",") {
out.push(c);
}
Expand Down Expand Up @@ -497,8 +486,7 @@
// http://msdn.microsoft.com/en-us/library/dwhawy9k.aspx

var standardFormatStringMatch = format.match(/^([a-zA-Z])(\d*)$/);
if (standardFormatStringMatch)
{
if (standardFormatStringMatch) {
var standardFormatStringMatch_UpperCase = standardFormatStringMatch[1].toUpperCase(),
precision = parseInt(standardFormatStringMatch[2], 10); // parseInt used to ensure empty string is aprsed to NaN

Expand Down Expand Up @@ -543,7 +531,8 @@
// Note that we might have fell through from G above!

// Determine coefficient and exponent for normalized notation
var exponent = 0, coefficient = Math.abs(number);
var exponent = 0,
coefficient = Math.abs(number);

while (coefficient >= 10) {
coefficient /= 10;
Expand Down Expand Up @@ -667,13 +656,13 @@

// ***** Date Formatting *****
function mainDateFormatter(date, format) {
var year = date.getFullYear(),
month = date.getMonth(),
dayOfMonth = date.getDate(),
dayOfWeek = date.getDay(),
hour = date.getHours(),
minute = date.getMinutes(),
second = date.getSeconds();
var year = date.getFullYear(),
month = date.getMonth(),
dayOfMonth = date.getDate(),
dayOfWeek = date.getDay(),
hour = date.getHours(),
minute = date.getMinutes(),
second = date.getSeconds();

// If no format is specified, default to G format
format = format || "G";
Expand All @@ -686,48 +675,48 @@
// If the pattern contains 'd' or 'dd', genitive form is used for MMMM
var monthNames = currentCulture._Mg && /(^|[^d])d(?!dd)/.test(format) ? currentCulture._Mg : currentCulture._M;

return format.replace(/(\\.|'[^']*'|"[^"]*"|d{1,4}|M{1,4}|yyyy|yy|HH?|hh?|mm?|ss?|tt?)/g,
function (match) {
return format.replace(/(\\.|'[^']*'|"[^"]*"|d{1,4}|M{1,4}|yyyy|yy|HH?|hh?|mm?|ss?|tt?)/g,
function(match) {

// Day
// Day
return match === "dddd" ? currentCulture._D[dayOfWeek] :
// Use three first characters from long day name if abbreviations are not specifed
match === "ddd" ? (currentCulture._d ? currentCulture._d[dayOfWeek] : currentCulture._D[dayOfWeek].substr(0, 3)) :
match === "dd" ? numberPair(dayOfMonth) :
match === "d" ? dayOfMonth :

// Month
match === "MMMM" ? monthNames[month] :
// Use three first characters from long month name if abbreviations are not specifed
match === "MMM" ? (currentCulture._m ? currentCulture._m[month] : currentCulture._M[month].substr(0, 3)) :
match === "MM" ? numberPair(month + 1) :
match === "M" ? month + 1 :

// Year
match === "yyyy" ? year :
match === "yy" ? ("" + year).substr(2) :

// Hour
match === "HH" ? numberPair(hour) :
match === "H" ? hour :
match === "hh" ? numberPair((hour - 1) % 12 + 1) :
match === "h" ? (hour - 1) % 12 + 1 :

// Minute
match === "mm" ? numberPair(minute) :
match === "m" ? minute :

// Second
match === "ss" ? numberPair(second) :
match === "s" ? second :

// AM/PM
match === "tt" ? (hour < 12 ? currentCulture._am : currentCulture._pm) :
match === "t" ? (hour < 12 ? currentCulture._am : currentCulture._pm).charAt(0) :

// String literal => strip quotation marks
match.substr(1, match.length - 1 - (match.charAt(0) !== "\\"));
}
// Use three first characters from long day name if abbreviations are not specifed
match === "ddd" ? (currentCulture._d ? currentCulture._d[dayOfWeek] : currentCulture._D[dayOfWeek].substr(0, 3)) :
match === "dd" ? numberPair(dayOfMonth) :
match === "d" ? dayOfMonth :

// Month
match === "MMMM" ? monthNames[month] :
// Use three first characters from long month name if abbreviations are not specifed
match === "MMM" ? (currentCulture._m ? currentCulture._m[month] : currentCulture._M[month].substr(0, 3)) :
match === "MM" ? numberPair(month + 1) :
match === "M" ? month + 1 :

// Year
match === "yyyy" ? year :
match === "yy" ? ("" + year).substr(2) :

// Hour
match === "HH" ? numberPair(hour) :
match === "H" ? hour :
match === "hh" ? numberPair((hour - 1) % 12 + 1) :
match === "h" ? (hour - 1) % 12 + 1 :

// Minute
match === "mm" ? numberPair(minute) :
match === "m" ? minute :

// Second
match === "ss" ? numberPair(second) :
match === "s" ? second :

// AM/PM
match === "tt" ? (hour < 12 ? currentCulture._am : currentCulture._pm) :
match === "t" ? (hour < 12 ? currentCulture._am : currentCulture._pm).charAt(0) :

// String literal => strip quotation marks
match.substr(1, match.length - 1 - (match.charAt(0) !== "\\"));
}
);
}

Expand All @@ -744,25 +733,22 @@

var outerArgs = arguments;

return str.replace(/(\{+)((\d+|[a-zA-Z_$]\w+(?:\.[a-zA-Z_$]\w+|\[\d+\])*)(?:\,(-?\d*))?(?:\:([^\}]*))?)(\}+)|(\{+)|(\}+)/g, function () {
return str.replace(/\{((\d+|[a-zA-Z_$]\w*(?:\.[a-zA-Z_$]\w*|\[\d+\])*)(?:\,(-?\d*))?(?:\:([^\}]*(?:(?:\}\})+[^\}]+)*))?)\}|(\{\{)|(\}\})/g, function() {
var innerArgs = arguments;

// Handle escaped {
return innerArgs[7] ? unescapeBraces(innerArgs[7]) :

// Handle escaped }
innerArgs[8] ? unescapeBraces(innerArgs[8]) :

// Handle case when both { and } are present, but one or both of them are escaped
!(innerArgs[1].length % 2 && innerArgs[6].length % 2) ?
unescapeBraces(innerArgs[1]) +
innerArgs[2] +
unescapeBraces(innerArgs[6]) :

// Valid format item
unescapeBraces(innerArgs[1], 1) +
processFormatItem(innerArgs[3], innerArgs[4], innerArgs[5], outerArgs) +
unescapeBraces(innerArgs[6], 1);
return innerArgs[5] ? "{" :

// Handle escaped }
innerArgs[6] ? "}" :

// Valid format item
processFormatItem(
innerArgs[2],
innerArgs[3],
// Format string might contain escaped braces
innerArgs[4] && innerArgs[4].replace(/\}\}/g, "}").replace(/\{\{/g, "{"),
outerArgs);
});
}

Expand All @@ -788,7 +774,7 @@
};

/// <field name="version" type="String">The version of the library String.Format for JavaScript.</field>
sffjs.version = "1.10.0-alpha.8";
sffjs.version = "1.10.0";

sffjs.setCulture = function(languageCode) {
/// <summary>
Expand Down
Loading

0 comments on commit 501d4d2

Please sign in to comment.