Comparing version 1.10.0-alpha.8 to 1.10.0
@@ -1,2 +0,2 @@ | ||
| ||
CHANGELOG | ||
@@ -3,0 +3,0 @@ String.format for JavaScript |
{ | ||
"name": "sffjs", | ||
"version": "1.10.0-alpha.8", | ||
"version": "1.10.0", | ||
"description": "String.Format for JavaScript", | ||
@@ -19,3 +19,3 @@ "main": "sffjs.js", | ||
], | ||
"license": "zlib", | ||
"license": "Zlib", | ||
"bugs": { | ||
@@ -27,8 +27,8 @@ "url": "https://github.com/thorn0/sffjs/issues" | ||
"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.6.0", | ||
"grunt-contrib-uglify": "^0.6.0", | ||
"load-grunt-tasks": "^0.6.0" | ||
"grunt-contrib-copy": "^0.7.0", | ||
"grunt-contrib-uglify": "^0.9.2", | ||
"load-grunt-tasks": "^3.3.0" | ||
} | ||
} |
@@ -1,2 +0,2 @@ | ||
String.format for JavaScript | ||
String.format for JavaScript | ||
============================ | ||
@@ -3,0 +3,0 @@ |
@@ -31,3 +31,3 @@ /** | ||
/*global sffjs,require*/ | ||
(function () { | ||
(function() { | ||
/// <summary> | ||
@@ -37,3 +37,2 @@ /// Performs a series of unit tests and writes the output to the page. | ||
function runTests(test) { | ||
@@ -43,12 +42,14 @@ sffjs.setCulture("en"); | ||
var testObject = { | ||
a: "b", | ||
authors: [ | ||
{ | ||
firstname: "John", | ||
lastname: "Doe", | ||
firstname: "John", | ||
lastname: "Doe", | ||
phonenumbers: [ | ||
{ | ||
home: "345" | ||
home: "012", | ||
home: "345" | ||
} | ||
], | ||
age: 27 | ||
age: 27 | ||
} | ||
@@ -64,3 +65,3 @@ ] | ||
assert.formatsTo("{{dblbrackets}} in args", "{0} in args", "{{dblbrackets}}"); | ||
assert.formatsTo("Mismatch {{0}", "Mismatch {{{0}}", "{{brackets}"); | ||
assert.formatsTo("Mismatch {{{brackets}}", "Mismatch {{{0}}", "{{brackets}"); | ||
assert.formatsTo("Double outer {{{brackets}}", "Double outer {{{0}}}", "{{brackets}"); | ||
@@ -74,6 +75,5 @@ | ||
assert.formatsTo("undefined:!!", "undefined:!{0}!", undefined); | ||
assert.doesThrow(function () { String.format("{1}", 42); }, "Missing argument", "Index out of range"); | ||
assert.doesThrow(function () { String.format("{1}", 42) }, "Missing argument", "Index out of range"); | ||
assert.formatsTo("Negative index:!{-1}!", "Negative index:!{-1}!", 42); | ||
test.section("Path"); | ||
@@ -90,2 +90,3 @@ assert.formatsTo("Hi, John!", "Hi, {authors[0].firstname}!", testObject); | ||
assert.formatsTo("1.00", "{authors.length:0.00}", testObject); | ||
assert.formatsTo("After a comes b.", "After a comes {a}.", testObject); | ||
@@ -100,2 +101,17 @@ test.section("Invalid paths"); | ||
test.section("Escaped braces"); | ||
assert.formatsTo("a { b", "a {{ b", testObject); | ||
assert.formatsTo("a } b", "a }} b", testObject); | ||
assert.formatsTo("a{{a}}", "a{{{{a}}}", testObject); // * | ||
assert.formatsTo("a{{b}", "a{{{{{a}}}", testObject); | ||
assert.formatsTo("a{aba}a", "a{{a{a}a}}a", testObject); | ||
assert.formatsTo("a{{aba", "a{{{a{a}a", testObject); // * | ||
assert.formatsTo("a{bbb{}a", "a{{b{a}{a}{}a", testObject); // * | ||
assert.formatsTo("4}.2", "{0:0}}.0}", 4.2); | ||
assert.formatsTo("4{.2", "{0:0{{.0}", 4.2); | ||
assert.formatsTo("4}{{}.2", "{0:0}}{{{{}}.0}", 4.2); | ||
// * These tests do not produce the same output as in .NET. In .NET these format strings will | ||
// generate a FormatException while the JS implementation makes a best effort to finish processing | ||
// the format string. | ||
var dtam = new Date(1989, 3, 2, 6, 20, 33); | ||
@@ -366,4 +382,2 @@ var dtpm = new Date(1989, 3, 2, 18, 20, 33); | ||
assert.formatsTo("{{dblbrackets}} in args", "{0} in args", "{{dblbrackets}}"); | ||
assert.formatsTo("Mismatch {{0}", "Mismatch {{{0}}", "{{brackets}"); | ||
assert.formatsTo("Double outer {{{brackets}}", "Double outer {{{0}}}", "{{brackets}"); | ||
@@ -400,3 +414,3 @@ test.section("setCulture"); | ||
function Test() { | ||
@@ -408,3 +422,3 @@ var t = this; | ||
this.section = function (name) { | ||
this.section = function(name) { | ||
t.sections.push({ | ||
@@ -416,3 +430,3 @@ name: name, | ||
this.result = function (result) { | ||
this.result = function(result) { | ||
if (t.sections.length === 0) { | ||
@@ -425,3 +439,3 @@ t.section("Untitled test section"); | ||
this.print = function () { | ||
this.print = function() { | ||
var container = document.createElement("div"); | ||
@@ -458,3 +472,2 @@ | ||
var table = document.createElement("table"); | ||
@@ -526,8 +539,12 @@ var tr, td; | ||
switch (typeof value) { | ||
case "number": return value.toString(); | ||
case "number": | ||
return value.toString(); | ||
case "string": | ||
if (value.length > 40) { value = value.substr(0, 40) + "..."; } | ||
if (value.length > 40) { | ||
value = value.substr(0, 40) + "..."; | ||
} | ||
return "\"" + value + "\""; | ||
case "undefined": return "[undefined]"; | ||
case "undefined": | ||
return "[undefined]"; | ||
case "object": | ||
@@ -560,3 +577,3 @@ | ||
var assert = { | ||
areEqual: function (expected, actual, message) { | ||
areEqual: function(expected, actual, message) { | ||
var result = actual === expected; | ||
@@ -570,3 +587,3 @@ | ||
doesThrow: function (fn, expectedError, message) { | ||
doesThrow: function(fn, expectedError, message) { | ||
var actualError = "[No exception thrown]"; | ||
@@ -583,3 +600,3 @@ | ||
formatsTo: function (expected, formatString, obj0) { | ||
formatsTo: function(expected, formatString, obj0) { | ||
var args = Array.prototype.slice.call(arguments, 1); | ||
@@ -610,3 +627,3 @@ var actual; | ||
var formats = 0; | ||
String.format = function () { | ||
String.format = function() { | ||
formats++; | ||
@@ -613,0 +630,0 @@ return s.apply(null, arguments); |
Sorry, the diff of this file is not supported yet
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
0
243592
283
1175