Comparing version 1.13.2 to 1.16.0
@@ -1,1 +0,1 @@ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module&&"function"==typeof require?t(require("../sffjs")):"function"==typeof define&&define.amd?define(["../sffjs"],t):t(e.sffjs)}(this,function(e){"use strict";e.registerCulture({name:"de-CH",d:"dd.MM.yyyy",D:"dddd, d. MMMM yyyy",M:"dd MMMM",Y:"MMMM yyyy",_am:"vorm.",_pm:"nachm.",_t:"'",_c:"#,0.00 ''",_d:["So","Mo","Di","Mi","Do","Fr","Sa"],_D:["Sonntag","Montag","Dienstag","Mittwoch","Donnerstag","Freitag","Samstag"],_m:["Jan","Feb","Mär","Apr","Mai","Jun","Jul","Aug","Sep","Okt","Nov","Dez"],_M:["Januar","Februar","März","April","Mai","Juni","Juli","August","September","Oktober","November","Dezember"]})}); | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module&&"function"==typeof require?t(require("../sffjs")):"function"==typeof define&&define.amd?define(["../sffjs"],t):t(e.sffjs)}(this,function(e){"use strict";e.registerCulture({name:"de-CH",d:"dd.MM.yyyy",D:"dddd, d. MMMM yyyy",M:"dd MMMM",Y:"MMMM yyyy",_am:"vorm.",_pm:"nachm.",_t:"'",_c:"#,0.00 'CHF'",_d:["So","Mo","Di","Mi","Do","Fr","Sa"],_D:["Sonntag","Montag","Dienstag","Mittwoch","Donnerstag","Freitag","Samstag"],_m:["Jan","Feb","Mär","Apr","Mai","Jun","Jul","Aug","Sep","Okt","Nov","Dez"],_M:["Januar","Februar","März","April","Mai","Juni","Juli","August","September","Oktober","November","Dezember"]})}); |
@@ -1,37 +0,1 @@ | ||
{ | ||
"name": "sffjs", | ||
"version": "1.13.2", | ||
"description": "String.Format for JavaScript", | ||
"main": "sffjs.js", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/thorn0/sffjs.git" | ||
}, | ||
"keywords": [ | ||
"dotnet", | ||
".net", | ||
"string.format" | ||
], | ||
"contributors": [ | ||
"Daniel Mester Pirttijarvi (http://www.masterdata.se)", | ||
"Georgii Dolzhykov <georgii.dolzhykov@gmail.com>" | ||
], | ||
"license": "Zlib", | ||
"bugs": { | ||
"url": "https://github.com/thorn0/sffjs/issues" | ||
}, | ||
"homepage": "https://github.com/thorn0/sffjs", | ||
"devDependencies": { | ||
"grunt": "^1.0.1", | ||
"grunt-build-control": "^0.7.1", | ||
"grunt-contrib-clean": "^1.0.0", | ||
"grunt-contrib-copy": "^1.0.0", | ||
"grunt-contrib-uglify": "^3.0.0", | ||
"load-grunt-tasks": "^3.5.2", | ||
"timezoned-date": "^3.0.2" | ||
}, | ||
"scripts": { | ||
"test": "node src/stringformat.tests", | ||
"dotnet": "node src/stringformat.tests dotnet" | ||
} | ||
} | ||
{"name":"sffjs","version":"1.16.0","description":"String.Format for JavaScript","main":"sffjs.js","repository":{"type":"git","url":"https://github.com/thorn0/sffjs.git"},"keywords":["dotnet",".net","string.format"],"contributors":["Daniel Mester Pirttijarvi (http://www.masterdata.se)","Georgii Dolzhykov <georgii.dolzhykov@gmail.com>"],"license":"Zlib","bugs":{"url":"https://github.com/thorn0/sffjs/issues"},"homepage":"https://github.com/thorn0/sffjs"} |
@@ -89,2 +89,3 @@ # String.format for JavaScript | ||
* Number format specifier `c` ignores specified precision | ||
* Number format specifier `G` formats the number according to how a double is formatted in .NET. Other numeric data type are formatted differently in .NET. | ||
@@ -91,0 +92,0 @@ Other types don't have a format implementation, and are thus serialized to a |
351
sffjs.js
/** | ||
* String.format for JavaScript, version 1.13.2 | ||
* String.format for JavaScript, version 1.16.0 | ||
* | ||
* Copyright (c) 2009-2017 Daniel Mester Pirttijärvi | ||
* http://mstr.se/sffjs | ||
* Copyright (c) 2009-2019 Daniel Mester Pirttijärvi | ||
* https://github.com/dmester/sffjs | ||
* | ||
@@ -35,3 +35,3 @@ * Fork by Georgii Dolzhykov | ||
// CommonJS | ||
module.exports = factory(); | ||
module.exports = factory(true); | ||
} else if (typeof define === "function" && define.amd) { | ||
@@ -46,3 +46,3 @@ // AMD | ||
})(this, function() { | ||
})(this, function(isCommonJsEnv) { | ||
"use strict"; | ||
@@ -91,18 +91,26 @@ | ||
function numberPair(n) { | ||
/// <summary>Converts a number to a string that is at least 2 digit in length. A leading zero is inserted as padding if necessary.</summary> | ||
return n < 10 ? "0" + n : n; | ||
/** | ||
* Pads the specified value with zeroes to the left until it reaches the specified length. | ||
* @param {*} value Value to zeropad. | ||
* @param {number} len Minimum length of result. | ||
* @returns {string} | ||
*/ | ||
function zeroPad(value, len) { | ||
var s = "" + value; | ||
while (s.length < len) s = "0" + s; | ||
return s; | ||
} | ||
function numberTriple(n) { | ||
return n < 10 ? "00" + n : n < 100 ? "0" + n : n; | ||
} | ||
/** | ||
* Returns `true` if `value` is not null or undefined. | ||
* @param {*} value | ||
*/ | ||
function hasValue(value) { | ||
/// <summary>Returns true if <paramref name="value"/> is not null or undefined.</summary> | ||
return value != null; | ||
} | ||
/** | ||
* Returns the first of the two values that is not NaN. | ||
*/ | ||
function numberCoalesce(value1, value2) { | ||
/// <summary>Returns the first of the two values that is not NaN.</summary> | ||
return isNaN(value1) ? value2 : value1; | ||
@@ -117,5 +125,6 @@ } | ||
/** | ||
* This method will fill gaps in the specified culture with information from the invariant culture. | ||
*/ | ||
function fillGapsInCulture(culture) { | ||
/// <summary>This method will fill gaps in the specified culture with information from the invariant culture.</summary> | ||
if (culture._cr == null) { | ||
@@ -162,3 +171,3 @@ culture._cr = culture._r; | ||
var ensureCultureLoaded; | ||
if (typeof module !== 'undefined' && module.exports) { | ||
if (isCommonJsEnv) { | ||
ensureCultureLoaded = function(key) { | ||
@@ -174,4 +183,6 @@ if (!(key in cultures)) { | ||
/** | ||
* This method will update the currently selected culture object to reflect the currently set LCID (as far as possible). | ||
*/ | ||
function updateCulture() { | ||
/// <summary>This method will update the currently selected culture object to reflect the currently set LCID (as far as possible).</summary> | ||
var result; | ||
@@ -193,13 +204,57 @@ if (currentCultureId) { | ||
function ensureFixedPoint(numberString) { | ||
var parts = numberString.split("e"); | ||
var result = parts[0]; | ||
if (parts.length > 1) { | ||
// Convert exponential to fixed-point number | ||
var exponent = Number(parts[1]); | ||
result = result.replace(".", ""); | ||
if (exponent < 0) { | ||
while (++exponent < 0) { | ||
result = "0" + result; | ||
} | ||
result = "0." + result; | ||
} | ||
else { | ||
while (exponent >= result.length) { | ||
result += "0"; | ||
} | ||
} | ||
} | ||
return result; | ||
} | ||
/** | ||
* Generates a string representation of the specified number with the specified number of digits. | ||
* @param {number} number The value to be processed. | ||
* @param {number} [decimals] The maximum number of decimals. If not specified, the value is not rounded. | ||
* @returns {string} The rounded absolute value as a string. | ||
*/ | ||
function numberToString(number, decimals) { | ||
/// <summary>Generates a string representation of the specified number with the specified number of digits.</summary> | ||
/// <param name="number" type="Number">The value to be processed.</param> | ||
/// <param name="decimals" type="Number" integer="true" optional="true">The maximum number of decimals. If not specified, the value is not rounded.</param> | ||
/// <returns>The rounded absolute value as a string.</returns> | ||
var roundingFactor = Math.pow(10, decimals || 0); | ||
return "" + (Math.round(Math.abs(number) * roundingFactor) / roundingFactor); | ||
var result = ensureFixedPoint(Math.abs(number).toString()); | ||
var radixIndex = result.indexOf("."); | ||
if (radixIndex > 0 && result.length - radixIndex - 1 > decimals) { | ||
// Rounding required | ||
// Add 1 to string representation of the number to improve | ||
// the chance that toFixed rounds correctly. | ||
result = ensureFixedPoint(Number(result + "1").toFixed(decimals)); | ||
// Trim excessive decimal zeroes | ||
result = result.replace(/\.?0+$/, ""); | ||
} | ||
return result; | ||
} | ||
/** | ||
* Counts the number of integral digits in a number converted to a string by the JavaScript runtime. | ||
* @param {string} numberString | ||
* @returns {number} | ||
*/ | ||
function numberOfIntegralDigits(numberString) { | ||
/// <summary>Counts the number of integral digits in a number converted to a string by the JavaScript runtime.</summary> | ||
var point = numberString.indexOf("."); | ||
@@ -209,4 +264,8 @@ return point < 0 ? numberString.length : point; | ||
/** | ||
* Counts the number of decimal digits in a number converted to a string by the JavaScript runtime | ||
* @param {string} numberString | ||
* @returns {number} | ||
*/ | ||
function numberOfDecimalDigits(numberString) { | ||
/// <summary>Counts the number of decimal digits in a number converted to a string by the JavaScript runtime</summary> | ||
var point = numberString.indexOf("."); | ||
@@ -218,10 +277,9 @@ return point < 0 ? 0 : numberString.length - point - 1; | ||
/** | ||
* This function resolves a path on the format `<membername>(.<membername>|[<index>])*` | ||
* and evaluates the value. | ||
* @param {string} path A series of path components separated by points. Each component is either an index in square brackets. | ||
* @param {*} value An object on which the path is evaluated. | ||
*/ | ||
function resolvePath(path, value) { | ||
/// <summary> | ||
/// This function resolves a path on the format <membername>(.<membername>|[<index>])* | ||
/// and evaluates the value. | ||
/// </summary> | ||
/// <param name="path">A series of path components separated by points. Each component is either an index in square brackets.</param> | ||
/// <param name="value">An object on which the path is evaluated.</param> | ||
// Parse and evaluate path | ||
@@ -243,18 +301,17 @@ if (hasValue(value)) { | ||
/** | ||
* Writes a value to an array in groups of three digits. | ||
* @param {string[]} out An array used as string builder to which the grouped output will be appended. The array | ||
* may have to properties that affect the output: | ||
* | ||
* * `g`: the number of integral digits left to write. | ||
* * `t`: the thousand separator. | ||
* | ||
* If any of those properties are missing, the output is not grouped. | ||
* @param {string} value The value that will be written to `out`. | ||
*/ | ||
function groupedAppend(out, value) { | ||
/// <summary>Writes a value to an array in groups of three digits.</summary> | ||
/// <param name="out" type="Array"> | ||
/// An array used as string builder to which the grouped output will be appended. The array | ||
/// may have to properties that affect the output: | ||
/// | ||
/// g: the number of integral digits left to write. | ||
/// t: the thousand separator. | ||
/// | ||
// If any of those properties are missing, the output is not grouped. | ||
/// </param> | ||
/// <param name="value" type="String">The value that will be written to <paramref name="out"/>.</param> | ||
for (var i = 0, length = value.length; i < length; i++) { | ||
// Write number | ||
out.push(value.charAt(i)); | ||
out.push(value[i]); | ||
@@ -268,10 +325,11 @@ // Begin a new group? | ||
/** | ||
* Process a single format item in a composite format string. | ||
* @param {string} pathOrIndex The raw argument index or path component of the format item. | ||
* @param {string} align The raw alignment component of the format item. | ||
* @param {string} formatString The raw format string of the format item. | ||
* @param {Array} args The arguments that were passed to String.format, where index 0 is the full composite format string. | ||
* @returns {string} The formatted value as a string. | ||
*/ | ||
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> | ||
/// <param name="align" type="String">The raw alignment component of the format item.</param> | ||
/// <param name="formatString" type="String">The raw format string of the format item.</param> | ||
/// <param name="args" type="Array">The arguments that were passed to String.format, where index 0 is the full composite format string.</param> | ||
/// <returns>The formatted value as a string.</returns> | ||
var value, | ||
@@ -323,12 +381,15 @@ index = parseInt(pathOrIndex, 10), | ||
/** | ||
* Handles basic formatting used for standard numeric format strings. | ||
* @param {number} number The number to format. | ||
* @param {number} minIntegralDigits The minimum number of integral digits. The number is padded with leading | ||
* zeroes if necessary. | ||
* @param {number} minDecimalDigits The minimum number of decimal digits. The decimal part is padded with trailing | ||
* zeroes if necessary. | ||
* @param {number} maxDecimalDigits The maximum number of decimal digits. The number is rounded if necessary. | ||
* @param {string} radixPoint The string that will be appended to the output as a radix point. | ||
* @param {string} thousandSeparator The string that will be used as a thousand separator of the integral digits. | ||
* @returns {string} The formatted value as a string. | ||
*/ | ||
function basicNumberFormatter(number, minIntegralDigits, minDecimalDigits, maxDecimalDigits, radixPoint, thousandSeparator) { | ||
/// <summary>Handles basic formatting used for standard numeric format strings.</summary> | ||
/// <param name="number" type="Number">The number to format.</param> | ||
/// <param name="minIntegralDigits" type="Number" integer="true">The minimum number of integral digits. The number is padded with leading zeroes if necessary.</param> | ||
/// <param name="minDecimals" type="Number" integer="true">The minimum number of decimal digits. The decimal part is padded with trailing zeroes if necessary.</param> | ||
/// <param name="maxDecimals" type="Number" integer="true">The maximum number of decimal digits. The number is rounded if necessary.</param> | ||
/// <param name="radixPoint" type="String">The string that will be appended to the output as a radix point.</param> | ||
/// <param name="thousandSeparator" type="String">The string that will be used as a thousand separator of the integral digits.</param> | ||
/// <returns>The formatted value as a string.</returns> | ||
var integralDigits, decimalDigits, out = []; | ||
@@ -373,10 +434,11 @@ out.t = thousandSeparator; | ||
/** | ||
* Handles formatting of custom numeric format strings. | ||
* @param {number} number The number to format. | ||
* @param {string} format A string specifying the format of the output. | ||
* @param {string} radixPoint The string that will be appended to the output as a radix point. | ||
* @param {string} thousandSeparator The string that will be used as a thousand separator of the integral digits. | ||
* @returns {string} The formatted value as a string. | ||
*/ | ||
function customNumberFormatter(number, format, radixPoint, thousandSeparator) { | ||
/// <summary>Handles formatting of custom numeric format strings.</summary> | ||
/// <param name="number" type="Number">The number to format.</param> | ||
/// <param name="format" type="String">A string specifying the format of the output.</param> | ||
/// <param name="radixPoint" type="String">The string that will be appended to the output as a radix point.</param> | ||
/// <param name="thousandSeparator" type="String">The string that will be used as a thousand separator of the integral digits.</param> | ||
/// <returns>The formatted value as a string.</returns> | ||
var digits = 0, | ||
@@ -407,3 +469,3 @@ forcedDigits = -1, | ||
for (formatIndex = 0; formatIndex < format.length; formatIndex++) { | ||
currentToken = format.charAt(formatIndex); | ||
currentToken = format[formatIndex]; | ||
@@ -432,3 +494,3 @@ // Check if we have reached a literal | ||
// String instances are used to represent constants | ||
tokens.push(new String(format.charAt(++formatIndex))); | ||
tokens.push(new String(format[++formatIndex])); | ||
@@ -534,3 +596,3 @@ } else if (currentToken === ";") { | ||
} | ||
groupedAppend(out, number.charAt(numberIndex)); | ||
groupedAppend(out, number[numberIndex]); | ||
@@ -546,3 +608,3 @@ // Not yet inside the number number, force a zero? | ||
// In the fractional part | ||
groupedAppend(out, numberIndex >= number.length ? "0" : number.charAt(numberIndex)); | ||
groupedAppend(out, numberIndex >= number.length ? "0" : number[numberIndex]); | ||
} | ||
@@ -569,8 +631,9 @@ | ||
// ***** Number Formatting ***** | ||
/** | ||
* Formats this number according the specified format string. | ||
* @param {string} format The formatting string used to format this number. | ||
* @returns {string} | ||
*/ | ||
function mainNumberFormatter(number, format) { | ||
/// <summary> | ||
/// Formats this number according the specified format string. | ||
/// </summary> | ||
/// <param name="format">The formatting string used to format this number.</param> | ||
var radixPoint = currentCulture._r, | ||
@@ -588,3 +651,3 @@ thousandSeparator = currentCulture._t; | ||
if (!format && format !== "0") { | ||
return basicNumberFormatter(number, 0, 0, 10, radixPoint); | ||
format = "G"; | ||
} | ||
@@ -596,3 +659,3 @@ | ||
var standardFormatStringMatch = format.match(/^([a-zA-Z])(\d*)$/); | ||
var standardFormatStringMatch = format.match(/^([a-zA-Z])(\d{0,2})$/); | ||
if (standardFormatStringMatch) { | ||
@@ -602,5 +665,2 @@ var standardFormatStringMatch_UpperCase = standardFormatStringMatch[1].toUpperCase(), | ||
// Limit precision to max 15 | ||
precision = precision > 15 ? 15 : precision; | ||
// Standard numeric format string | ||
@@ -643,3 +703,3 @@ switch (standardFormatStringMatch_UpperCase) { | ||
// Determine coefficient and exponent for normalized notation | ||
// Determine coefficient and exponent for exponential notation | ||
var exponent = 0, | ||
@@ -663,7 +723,16 @@ coefficient = Math.abs(number); | ||
if (standardFormatStringMatch_UpperCase === "G") { | ||
if (exponent > -5 && (!precision || exponent < precision)) { | ||
minDecimals = precision ? precision - (exponent > 0 ? exponent + 1 : 1) : 0; | ||
maxDecimals = precision ? precision - (exponent > 0 ? exponent + 1 : 1) : 10; | ||
// Default precision in .NET is dependent on the data type. | ||
// For double the default precision is 15. | ||
precision = precision || 15; | ||
return basicNumberFormatter(number, 1, minDecimals, maxDecimals, radixPoint); | ||
// When (exponent <= -5) the exponential notation is always more compact. | ||
// e.g. 0.0000123 vs 1.23E-05 | ||
// When (exponent >= precision) the number cannot be represented | ||
// with the right number of significant digits without using | ||
// exponential notation. | ||
// e.g. 123 (1.23E+02) cannot be represented using fixed-point | ||
// notation with less than 3 significant digits. | ||
if (exponent > -5 && exponent < precision) { | ||
// Use fixed-point notation | ||
return basicNumberFormatter(number, 1, 0, precision - exponent - 1, radixPoint); | ||
} | ||
@@ -674,6 +743,7 @@ | ||
// The precision of G is number of significant digits, not the number of decimals. | ||
minDecimals = (precision || 1) - 1; | ||
maxDecimals = (precision || 11) - 1; | ||
// The precision of G is the number of significant digits | ||
minDecimals = 0; | ||
maxDecimals = precision - 1; | ||
} else { | ||
// The precision of E is the number of decimal digits | ||
minDecimals = maxDecimals = numberCoalesce(precision, 6); | ||
@@ -694,3 +764,7 @@ } | ||
return basicNumberFormatter("" + coefficient, 1, minDecimals, maxDecimals, radixPoint, thousandSeparator) + exponentPrefix + basicNumberFormatter(exponent, exponentPrecision, 0); | ||
return ( | ||
basicNumberFormatter(coefficient, 1, minDecimals, maxDecimals, radixPoint, thousandSeparator) + | ||
exponentPrefix + | ||
basicNumberFormatter(exponent, exponentPrecision, 0, 0) | ||
); | ||
@@ -752,2 +826,8 @@ case "P": | ||
// ***** Date Formatting ***** | ||
/** | ||
* Formats this date according the specified format string. | ||
* @param {string} format The formatting string used to format this date. | ||
* @returns {string} | ||
*/ | ||
function mainDateFormatter(date, format) { | ||
@@ -771,3 +851,3 @@ var year = date.getFullYear(), | ||
// Using single custom format specifiers | ||
format = format.replace(/%([a-z])/i, '$1'); | ||
format = format.replace(/%([a-z])/i, '""$1""'); | ||
@@ -777,12 +857,13 @@ // If the pattern contains 'd' or 'dd', genitive form is used for MMMM | ||
return format.replace(/(\\.|'[^']*'|"[^"]*"|d{1,4}|M{1,4}|yyyy|yy|HH?|hh?|mm?|ss?|\.?[fF]{1,7}|z{1,3}|tt?)/g, | ||
return format.replace(/(\\.|'[^']*'|"[^"]*"|d{1,4}|M{1,4}|y+|HH?|hh?|mm?|ss?|\.?[fF]{1,7}|z{1,3}|tt?)/g, | ||
function(match) { | ||
var char0 = match[0]; | ||
var matchLastChar = match.charAt(match.length - 1); | ||
var matchLastChar = match[match.length - 1]; | ||
// Millisecond | ||
if (matchLastChar === 'f' || matchLastChar == 'F') { | ||
var dot = match.charAt(0) === '.'; | ||
var dot = match[0] === '.'; | ||
var ms = date.getMilliseconds(); | ||
var msStr = (numberTriple(ms) + '0000').slice(0, match.length - (dot ? 1 : 0)); | ||
var msStr = (zeroPad(ms, 3) + '0000').slice(0, match.length - (dot ? 1 : 0)); | ||
if (matchLastChar === 'F') { | ||
@@ -806,5 +887,5 @@ msStr = msStr.replace(/0+$/, ''); | ||
var absOffsetHours = Math.floor(absOffsetMinutes / 60); | ||
var offsetStr = sign + (match === 'z' ? absOffsetHours : numberPair(absOffsetHours)); | ||
var offsetStr = sign + (match === 'z' ? absOffsetHours : zeroPad(absOffsetHours, 2)); | ||
if (match === 'zzz') { | ||
offsetStr += ':' + numberPair(absOffsetMinutes - absOffsetHours * 60); | ||
offsetStr += ':' + zeroPad(absOffsetMinutes - absOffsetHours * 60, 2); | ||
} | ||
@@ -817,5 +898,4 @@ return offsetStr; | ||
// 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 : | ||
match === "ddd" ? (currentCulture._d ? currentCulture._d[dayOfWeek] : currentCulture._D[dayOfWeek].substr(0, 3)) : | ||
char0 === "d" ? zeroPad(dayOfMonth, match.length) : | ||
@@ -825,30 +905,26 @@ // 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 : | ||
match === "MMM" ? (currentCulture._m ? currentCulture._m[month] : currentCulture._M[month].substr(0, 3)) : | ||
char0 === "M" ? zeroPad(month + 1, match.length) : | ||
// Year | ||
match === "yyyy" ? year : | ||
match === "yy" ? ("" + year).substr(2) : | ||
match === "yy" ? zeroPad(year % 100, 2) : | ||
match === "y" ? year % 100 : | ||
char0 === "y" ? zeroPad(year, match.length) : | ||
// Hour | ||
match === "HH" ? numberPair(hour) : | ||
match === "H" ? hour : | ||
match === "hh" ? numberPair(hour % 12 || 12) : | ||
match === "h" ? hour % 12 || 12 : | ||
char0 === "H" ? zeroPad(hour, match.length) : | ||
char0 === "h" ? zeroPad(hour % 12 || 12, match.length) : | ||
// Minute | ||
match === "mm" ? numberPair(minute) : | ||
match === "m" ? minute : | ||
char0 === "m" ? zeroPad(minute, match.length) : | ||
// Second | ||
match === "ss" ? numberPair(second) : | ||
match === "s" ? second : | ||
char0 === "s" ? zeroPad(second, match.length) : | ||
// AM/PM | ||
match === "tt" ? (hour < 12 ? currentCulture._am : currentCulture._pm) : | ||
match === "t" ? (hour < 12 ? currentCulture._am : currentCulture._pm).charAt(0) : | ||
match === "tt" ? (hour < 12 ? currentCulture._am : currentCulture._pm) : | ||
char0 === "t" ? (hour < 12 ? currentCulture._am : currentCulture._pm)[0] : | ||
// String literal => strip quotation marks | ||
match.substr(1, match.length - 1 - (match.charAt(0) !== "\\")); | ||
match.substr(1, match.length - 1 - (match[0] != "\\")); | ||
} | ||
@@ -859,10 +935,9 @@ ); | ||
// ***** Public Interface ***** | ||
/** | ||
* Formats a string according to a specified formatting string. | ||
* @param {string} str The formatting string used to format the additional arguments. | ||
* @param {...*} args | ||
*/ | ||
function sffjs(str, obj0, obj1, obj2) { | ||
/// <summary> | ||
/// Formats a string according to a specified formatting string. | ||
/// </summary> | ||
/// <param name="str">The formatting string used to format the additional arguments.</param> | ||
/// <param name="obj0">Object 1</param> | ||
/// <param name="obj1">Object 2 [optional]</param> | ||
/// <param name="obj2">Object 3 [optional]</param> | ||
/*jshint unused:false*/ | ||
@@ -912,11 +987,13 @@ | ||
/// <field name="version" type="String">The version of the library String.Format for JavaScript.</field> | ||
sffjs.version = "1.13.2"; | ||
/** | ||
* The version of the library String.Format for JavaScript. | ||
* @type string | ||
*/ | ||
sffjs.version = "1.16.0"; | ||
/** | ||
* Sets the current culture, used for culture specific formatting. | ||
* @param {string} languageCode The IETF language code of the culture, e.g. en-US or en. | ||
*/ | ||
sffjs.setCulture = function(languageCode) { | ||
/// <summary> | ||
/// Sets the current culture, used for culture specific formatting. | ||
/// </summary> | ||
/// <param name="LCID">The IETF language code of the culture, e.g. en-US or en.</param> | ||
currentCultureId = normalizeCulture(languageCode); | ||
@@ -926,10 +1003,10 @@ updateCulture(); | ||
/** | ||
* Registers an object containing information about a culture. | ||
* @param {*} culture Culture object. | ||
*/ | ||
sffjs.registerCulture = function(culture) { | ||
/// <summary> | ||
/// Registers an object containing information about a culture. | ||
/// </summary> | ||
cultures[normalizeCulture(culture.name)] = fillGapsInCulture(culture); | ||
// ...and reevaulate current culture | ||
// ...and reevaluate current culture | ||
updateCulture(); | ||
@@ -936,0 +1013,0 @@ }; |
@@ -1,1 +0,1 @@ | ||
!function(t,r){"undefined"!=typeof module&&module.exports?module.exports=r():"function"==typeof define&&define.amd?define(r):(t.sffjs=r(),t.sffjs.unsafe())}(this,function(){"use strict";var t,r,e={name:"",d:"MM/dd/yyyy",D:"dddd, dd MMMM yyyy",t:"HH:mm",T:"HH:mm:ss",M:"MMMM dd",Y:"yyyy MMMM",s:"yyyy-MM-ddTHH:mm:ss",_M:["January","February","March","April","May","June","July","August","September","October","November","December"],_D:["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],_r:".",_t:",",_c:"¤#,0.00",_ct:",",_cr:".",_am:"AM",_pm:"PM"},n=f({}),a="undefined"!=typeof navigator&&c(navigator.systemLanguage||navigator.language)||"",u={};function o(t){return t<10?"0"+t:t}function s(t){return null!=t}function i(t,r){return isNaN(t)?r:t}function f(t){for(var r in null==t._cr&&(t._cr=t._r),null==t._ct&&(t._ct=t._t),e)null==t[r]&&(t[r]=e[r]);return t.f=t.f||t.D+" "+t.t,t.F=t.F||t.D+" "+t.T,t.g=t.g||t.d+" "+t.t,t.G=t.G||t.d+" "+t.T,t.m=t.M,t.y=t.Y,t}function c(t){return t?t.toLowerCase().replace(/_/g,"-"):""}function d(){var e;if(a)for(var o=function(t){for(var r=[t],e=t.split("-");--e.length;)r.push(e.join("-"));return r}(a),s=0;!e&&s<o.length;s++){var i=o[s];r&&r(i),e=u[i]}p.LC=t=e||n}function h(t,r){var e=Math.pow(10,r||0);return""+Math.round(Math.abs(t)*e)/e}function g(t){var r=t.indexOf(".");return r<0?t.length:r}function l(t,r){for(var e=0,n=r.length;e<n;e++)t.push(r.charAt(e)),t.g>1&&t.g--%3==1&&t.push(t.t)}function y(t,r,e,n){var a,u,o,i=parseInt(t,10),f="";if(isNaN(i))a=function(t,r){if(s(r)){var e=/(\.([a-zA-Z_$]\w*)|\[(\d+)\])/g,n=/^[a-zA-Z_$]\w*/.exec(t);for(r=r[n[0]];s(r)&&(n=e.exec(t));)r=r[n[2]||Number(n[3])]}return r}(t,n[1]);else{if(i>n.length-2)throw new Error("Missing argument");a=n[i+1]}for(s(a)?a.__Format?a=a.__Format(e):"number"==typeof a?a=m(a,e):(o=a,a="[object Date]"===Object.prototype.toString.call(o)||o instanceof Date?_(a,e):""+a):a="",r=Number(r)||0,u=Math.abs(r)-a.length;u-- >0;)f+=" ";return r<0?a+f:f+a}function M(t,r,e,n,a,u){var o,s,i,f,c=[];for(c.t=u,t<0&&c.push("-"),t=h(t,n),o=c.g=g(t),s=(f=(i=t).indexOf("."))<0?0:i.length-f-1,r-=o;r-- >0;)l(c,"0");if(l(c,t.substr(0,o)),e||s)for(c.push(a),l(c,t.substr(o+1)),e-=s;e-- >0;)l(c,"0");return c.join("")}function m(r,e){var n=t._r,a=t._t;if(r=Number(r),!isFinite(r))return""+r;if(!e&&"0"!==e)return M(r,0,0,10,n);var u=e.match(/^([a-zA-Z])(\d*)$/);if(u){var o=u[1].toUpperCase(),s=parseInt(u[2],10);switch(s=s>15?15:s,o){case"D":return M(r,i(s,1),0,0);case"F":a="";case"N":return M(r,1,i(s,2),i(s,2),n,a);case"G":case"E":for(var f=0,c=Math.abs(r);c>=10;)c/=10,f++;for(;c>0&&c<1;)c*=10,f--;var d,y,m=u[1],_=3;if("G"===o){if(f>-5&&(!s||f<s))return M(r,1,d=s?s-(f>0?f+1:1):0,y=s?s-(f>0?f+1:1):10,n);m="G"===m?"E":"e",_=2,d=(s||1)-1,y=(s||11)-1}else d=y=i(s,6);return f>=0&&(m+="+"),r<0&&(c*=-1),M(""+c,1,d,y,n,a)+m+M(f,_,0);case"P":return M(100*r,1,i(s,2),i(s,2),n,a)+" %";case"X":var p=Math.round(r).toString(16);for("X"===u[1]&&(p=p.toUpperCase()),s-=p.length;s-- >0;)p="0"+p;return p;case"C":e=t._c,n=t._cr,a=t._ct;break;case"R":return""+r}}return function(t,r,e,n){var a,u,o,s,i,f=0,c=-1,d=0,y=-1,M=1,m=0,_=1,p=[],v=[p],b=[];for(s=0;s<r.length;s++)if("'"===(u=r.charAt(s))||'"'===u){if(i=r.indexOf(u,s+1),p.push(new String(r.substring(s+1,i<0?void 0:i))),i<0)break;s=i}else if("\\"===u)p.push(new String(r.charAt(++s)));else if(";"===u){if(t>0||t<0&&v.length>1)break;v.push(p=[])}else p.push(u);for(t<0&&v.length>1?(t*=-1,r=v[1]):r=v[!t&&v.length>2?2:0],s=0;s<r.length;s++)"0"===(u=r[s])||"#"===u?(d+=m,"0"===u&&(m?y=d:c<0&&(c=f)),1===M||m||(b.t=n,M=1),f+=!m):"."===u?m=1:","===u&&!m&&f>0?M*=.001:"%"===u&&(t*=100);for(c=c<0?1:f-c,t<0&&b.push("-"),o=(a=g(t=h(t*M,d)))-f,b.g=Math.max(a,c),s=0;s<r.length;s++)"#"===(u=r[s])||"0"===u?(o<a?(o>=0?(_&&l(b,t.substr(0,o)),l(b,t.charAt(o))):o>=a-c&&l(b,"0"),_=0):(y-- >0||o<t.length)&&l(b,o>=t.length?"0":t.charAt(o)),o++):"."===u?(t.length>++o||y>0)&&b.push(e):","!==u&&b.push(u);return b.join("")}(r,e,n,a)}function _(r,e){var n=r.getFullYear(),a=r.getMonth(),u=r.getDate(),s=r.getDay(),i=r.getHours(),f=r.getMinutes(),c=r.getSeconds();1===(e=e||"G").length&&(e=t[e]||e),e=e.replace(/%([a-z])/i,"$1");var d=t._Mg&&/(^|[^d])d(?!dd)/.test(e)?t._Mg:t._M;return e.replace(/(\\.|'[^']*'|"[^"]*"|d{1,4}|M{1,4}|yyyy|yy|HH?|hh?|mm?|ss?|\.?[fF]{1,7}|z{1,3}|tt?)/g,function(e){var h,g=e.charAt(e.length-1);if("f"===g||"F"==g){var l="."===e.charAt(0),y=r.getMilliseconds(),M=(h=y,(h<10?"00"+h:h<100?"0"+h:h)+"0000").slice(0,e.length-(l?1:0));return"F"===g&&(M=M.replace(/0+$/,"")),l&&M&&(M="."+M),M}if("z"===g){var m=-r.getTimezoneOffset(),_=m>=0?"+":"-",p=Math.abs(m),v=Math.floor(p/60),b=_+("z"===e?v:o(v));return"zzz"===e&&(b+=":"+o(p-60*v)),b}return"dddd"===e?t._D[s]:"ddd"===e?t._d?t._d[s]:t._D[s].substr(0,3):"dd"===e?o(u):"d"===e?u:"MMMM"===e?d[a]:"MMM"===e?t._m?t._m[a]:t._M[a].substr(0,3):"MM"===e?o(a+1):"M"===e?a+1:"yyyy"===e?n:"yy"===e?(""+n).substr(2):"HH"===e?o(i):"H"===e?i:"hh"===e?o(i%12||12):"h"===e?i%12||12:"mm"===e?o(f):"m"===e?f:"ss"===e?o(c):"s"===e?c:"tt"===e?i<12?t._am:t._pm:"t"===e?(i<12?t._am:t._pm).charAt(0):e.substr(1,e.length-1-("\\"!==e.charAt(0)))})}function p(t,r,e,n){var a=arguments;return t.replace(/\{((\d+|[a-zA-Z_$]\w*(?:\.[a-zA-Z_$]\w*|\[\d+\])*)(?:\,(-?\d*))?(?:\:([^\}]*(?:(?:\}\})+[^\}]+)*))?)\}|(\{\{)|(\}\})/g,function(){var t=arguments;return t[5]?"{":t[6]?"}":y(t[2],t[3],t[4]&&t[4].replace(/\}\}/g,"}").replace(/\{\{/g,"{"),a)})}return"undefined"!=typeof module&&module.exports&&(r=function(t){if(!(t in u)){u[t]=!1;try{require("./cultures/stringformat."+t)}catch(t){}}}),p.unsafe=function(){Number.prototype.__Format=function(t){return m(this,t)},Date.prototype.__Format=function(t){return _(this,t)},String.__Format=p;for(var t=[Date.prototype,Number.prototype,String],r=0;r<t.length;r++)t[r].format=t[r].format||t[r].__Format},p.version="1.13.2",p.setCulture=function(t){a=c(t),d()},p.registerCulture=function(t){u[c(t.name)]=f(t),d()},d(),p}); | ||
!function(e,t){"undefined"!=typeof module&&module.exports?module.exports=t(!0):"function"==typeof define&&define.amd?define(t):(e.sffjs=t(),e.sffjs.unsafe())}(this,function(e){"use strict";var y,a,r={name:"",d:"MM/dd/yyyy",D:"dddd, dd MMMM yyyy",t:"HH:mm",T:"HH:mm:ss",M:"MMMM dd",Y:"yyyy MMMM",s:"yyyy-MM-ddTHH:mm:ss",_M:["January","February","March","April","May","June","July","August","September","October","November","December"],_D:["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],_r:".",_t:",",_c:"¤#,0.00",_ct:",",_cr:".",_am:"AM",_pm:"PM"},u=t({}),o="undefined"!=typeof navigator&&n(navigator.systemLanguage||navigator.language)||"",i={};function v(e,t){for(var r=""+e;r.length<t;)r="0"+r;return r}function f(e){return null!=e}function d(e,t){return isNaN(e)?t:e}function t(e){for(var t in null==e._cr&&(e._cr=e._r),null==e._ct&&(e._ct=e._t),r)null==e[t]&&(e[t]=r[t]);return e.f=e.f||e.D+" "+e.t,e.F=e.F||e.D+" "+e.T,e.g=e.g||e.d+" "+e.t,e.G=e.G||e.d+" "+e.T,e.m=e.M,e.y=e.Y,e}function n(e){return e?e.toLowerCase().replace(/_/g,"-"):""}function s(){var e;if(o)for(var t=function(){for(var e=[o],t=o.split("-");--t.length;)e.push(t.join("-"));return e}(),r=0;!e&&r<t.length;r++){var n=t[r];a&&a(n),e=i[n]}h.LC=y=e||u}function g(e){var t=e.split("e"),r=t[0];if(1<t.length){var n=Number(t[1]);if(r=r.replace(".",""),n<0){for(;++n<0;)r="0"+r;r="0."+r}else for(;r.length<=n;)r+="0"}return r}function b(e,t){var r=g(Math.abs(e).toString()),n=r.indexOf(".");return 0<n&&t<r.length-n-1&&(r=(r=g(Number(r+"1").toFixed(t))).replace(/\.?0+$/,"")),r}function F(e){var t=e.indexOf(".");return t<0?e.length:t}function D(e,t){for(var r=0,n=t.length;r<n;r++)e.push(t[r]),1<e.g&&e.g--%3==1&&e.push(e.t)}function _(e,t,r,n,a,u){var o,i,s,f,g=[];for(g.t=u,e<0&&g.push("-"),e=b(e,n),o=g.g=F(e),i=(f=(s=e).indexOf("."))<0?0:s.length-f-1,t-=o;0<t--;)D(g,"0");if(D(g,e.substr(0,o)),r||i)for(g.push(a),D(g,e.substr(o+1)),r-=i;0<r--;)D(g,"0");return g.join("")}function c(e,t){var r=y._r,n=y._t;if(e=Number(e),!isFinite(e))return""+e;t||"0"===t||(t="G");var a=t.match(/^([a-zA-Z])(\d{0,2})$/);if(a){var u=a[1].toUpperCase(),o=parseInt(a[2],10);switch(u){case"D":return _(e,d(o,1),0,0);case"F":n="";case"N":return _(e,1,d(o,2),d(o,2),r,n);case"G":case"E":for(var i=0,s=Math.abs(e);10<=s;)s/=10,i++;for(;0<s&&s<1;)s*=10,i--;var f,g,c=a[1],l=3;if("G"===u){if(o=o||15,-5<i&&i<o)return _(e,1,0,o-i-1,r);c="G"===c?"E":"e",l=2,f=0,g=o-1}else f=g=d(o,6);return 0<=i&&(c+="+"),e<0&&(s*=-1),_(s,1,f,g,r,n)+c+_(i,l,0,0);case"P":return _(100*e,1,d(o,2),d(o,2),r,n)+" %";case"X":var h=Math.round(e).toString(16);for("X"===a[1]&&(h=h.toUpperCase()),o-=h.length;0<o--;)h="0"+h;return h;case"C":t=y._c,r=y._cr,n=y._ct;break;case"R":return""+e}}return function(e,t,r,n){var a,u,o,i,s,f=0,g=-1,c=0,l=-1,h=1,d=0,_=1,p=[],m=[p],M=[];for(i=0;i<t.length;i++)if("'"===(u=t[i])||'"'===u){if(s=t.indexOf(u,i+1),p.push(new String(t.substring(i+1,s<0?void 0:s))),s<0)break;i=s}else if("\\"===u)p.push(new String(t[++i]));else if(";"===u){if(0<e||e<0&&1<m.length)break;m.push(p=[])}else p.push(u);for(t=e<0&&1<m.length?(e*=-1,m[1]):m[!e&&2<m.length?2:0],i=0;i<t.length;i++)"0"===(u=t[i])||"#"===u?(c+=d,"0"===u&&(d?l=c:g<0&&(g=f)),1===h||d||(M.t=n,h=1),f+=!d):"."===u?d=1:","===u&&!d&&0<f?h*=.001:"%"===u&&(e*=100);for(g=g<0?1:f-g,e<0&&M.push("-"),o=(a=F(e=b(e*h,c)))-f,M.g=Math.max(a,g),i=0;i<t.length;i++)"#"===(u=t[i])||"0"===u?(o<a?(0<=o?(_&&D(M,e.substr(0,o)),D(M,e[o])):a-g<=o&&D(M,"0"),_=0):(0<l--||o<e.length)&&D(M,e.length<=o?"0":e[o]),o++):"."===u?(e.length>++o||0<l)&&M.push(r):","!==u&&M.push(u);return M.join("")}(e,t,r,n)}function l(g,e){var c=g.getFullYear(),l=g.getMonth(),h=g.getDate(),d=g.getDay(),_=g.getHours(),p=g.getMinutes(),m=g.getSeconds();1===(e=e||"G").length&&(e=y[e]||e),e=e.replace(/%([a-z])/i,'""$1""');var M=y._Mg&&/(^|[^d])d(?!dd)/.test(e)?y._Mg:y._M;return e.replace(/(\\.|'[^']*'|"[^"]*"|d{1,4}|M{1,4}|y+|HH?|hh?|mm?|ss?|\.?[fF]{1,7}|z{1,3}|tt?)/g,function(e){var t=e[0],r=e[e.length-1];if("f"===r||"F"==r){var n="."===e[0],a=(v(g.getMilliseconds(),3)+"0000").slice(0,e.length-(n?1:0));return"F"===r&&(a=a.replace(/0+$/,"")),n&&a&&(a="."+a),a}if("z"!==r)return"dddd"===e?y._D[d]:"ddd"===e?y._d?y._d[d]:y._D[d].substr(0,3):"d"===t?v(h,e.length):"MMMM"===e?M[l]:"MMM"===e?y._m?y._m[l]:y._M[l].substr(0,3):"M"===t?v(l+1,e.length):"yy"===e?v(c%100,2):"y"===e?c%100:"y"===t?v(c,e.length):"H"===t?v(_,e.length):"h"===t?v(_%12||12,e.length):"m"===t?v(p,e.length):"s"===t?v(m,e.length):"tt"===e?_<12?y._am:y._pm:"t"===t?(_<12?y._am:y._pm)[0]:e.substr(1,e.length-1-("\\"!=e[0]));var u=-g.getTimezoneOffset(),o=0<=u?"+":"-",i=Math.abs(u),s=Math.floor(i/60),f=o+("z"===e?s:v(s,2));return"zzz"===e&&(f+=":"+v(i-60*s,2)),f})}function h(e,t,r,n){var a=arguments;return e.replace(/\{((\d+|[a-zA-Z_$]\w*(?:\.[a-zA-Z_$]\w*|\[\d+\])*)(?:\,(-?\d*))?(?:\:([^\}]*(?:(?:\}\})+[^\}]+)*))?)\}|(\{\{)|(\}\})/g,function(){var e=arguments;return e[5]?"{":e[6]?"}":function(e,t,r,n){var a,u,o,i=parseInt(e,10),s="";if(isNaN(i))a=function(e,t){if(f(t)){var r=/(\.([a-zA-Z_$]\w*)|\[(\d+)\])/g,n=/^[a-zA-Z_$]\w*/.exec(e);for(t=t[n[0]];f(t)&&(n=r.exec(e));)t=t[n[2]||Number(n[3])]}return t}(e,n[1]);else{if(n.length-2<i)throw new Error("Missing argument");a=n[i+1]}for(a=f(a)?a.__Format?a.__Format(r):"number"==typeof a?c(a,r):(o=a,"[object Date]"===Object.prototype.toString.call(o)||o instanceof Date?l(a,r):""+a):"",t=Number(t)||0,u=Math.abs(t)-a.length;0<u--;)s+=" ";return t<0?a+s:s+a}(e[2],e[3],e[4]&&e[4].replace(/\}\}/g,"}").replace(/\{\{/g,"{"),a)})}return e&&(a=function(e){if(!(e in i)){i[e]=!1;try{require("./cultures/stringformat."+e)}catch(e){}}}),h.unsafe=function(){Number.prototype.__Format=function(e){return c(this,e)},Date.prototype.__Format=function(e){return l(this,e)},String.__Format=h;for(var e=[Date.prototype,Number.prototype,String],t=0;t<e.length;t++)e[t].format=e[t].format||e[t].__Format},h.version="1.16.0",h.setCulture=function(e){o=n(e),s()},h.registerCulture=function(e){i[n(e.name)]=t(e),s()},s(),h}); |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
193306
0
834
97