Comparing version 0.1.2 to 0.1.3
@@ -206,28 +206,63 @@ 'use strict'; | ||
var formats = [ | ||
'sd', | ||
'fdt', | ||
'md', | ||
'dddd', | ||
'ddd', | ||
'dd', | ||
'd', | ||
'D', | ||
'fff', | ||
'ff', | ||
'f', | ||
'F', | ||
'g', | ||
'G', | ||
'hh', | ||
'h', | ||
'HH', | ||
'H', | ||
'mm', | ||
'MMMM', | ||
'MMM', | ||
'MM', | ||
'M', | ||
'r', | ||
'ss', | ||
's', | ||
'tt', | ||
't', | ||
'T', | ||
'yyyy', | ||
'yy', | ||
'+zzzz', | ||
'+zz', | ||
'zzzz', | ||
'zzz', | ||
'zz' | ||
]; | ||
var result = ''; | ||
var part = ''; | ||
for (var i = 0; i < format.length; i++) { | ||
var char = format[i]; | ||
if ((char >= 'a' && char <= 'z') | ||
|| (char >= 'A' && char <= 'Z') | ||
|| char == '+') { | ||
part += char; | ||
var i; | ||
while (format.length > 0) { | ||
if (format[0] === "'") { | ||
var nextTick = format.indexOf("'", 1); | ||
result += format.substring(1, nextTick); | ||
format = format.substring(nextTick + 1); | ||
continue; | ||
} | ||
if (part.length > 0) { | ||
result += formatDatePart(date, part); | ||
part = ''; | ||
for (i = 0; i < formats.length; i++) { | ||
if (format.indexOf(formats[i]) === 0) { | ||
result += formatDatePart(date, formats[i]); | ||
format = format.substring(formats[i].length); | ||
break; | ||
} | ||
} | ||
if (char === "'") { | ||
i++; | ||
for (; i < format.length && format[i] !== "'"; i++) { | ||
result += format[i]; | ||
} | ||
if (i < formats.length) { | ||
continue; | ||
} | ||
result += char; | ||
result += format[0]; | ||
format = format.substring(1); | ||
} | ||
if (part.length > 0) { | ||
result += formatDatePart(date, part); | ||
} | ||
return result; | ||
@@ -330,3 +365,2 @@ } | ||
var fieldIndex = parseInt(fieldName); | ||
var val; | ||
if (fieldIndex.toString() === fieldName) { | ||
@@ -350,3 +384,7 @@ return args[fieldIndex + 1]; | ||
part = part.substr(1, part.length - 2); | ||
if (part < 0) { | ||
var strMatch = part.match(/^['"](.*)['"]$/); | ||
if (strMatch) { | ||
root = root[strMatch[1]]; | ||
} | ||
else if (part < 0) { | ||
part = -part; | ||
@@ -353,0 +391,0 @@ root = root[root.length - part]; |
@@ -6,4 +6,3 @@ { | ||
"keywords": ["string", "format", "template"], | ||
"homepage": "https://github.com/nearinfinity/node-sf", | ||
"version": "0.1.2", | ||
"version": "0.1.3", | ||
"engines": { "node" : ">=0.6.0" }, | ||
@@ -14,8 +13,11 @@ "maintainers": [ | ||
"bugs": { "url": "https://github.com/nearinfinity/node-sf/issues" }, | ||
"licenses": [ { "type" : "MIT" } ], | ||
"repositories": { "type": "git", "url": "https://github.com/nearinfinity/node-sf.git" }, | ||
"license": "MIT", | ||
"repository": { "type": "git", "url": "https://github.com/nearinfinity/node-sf.git" }, | ||
"devDependencies": { | ||
"nodeunit": "~0.7.3" | ||
}, | ||
"scripts": { | ||
"test": "nodeunit test" | ||
}, | ||
"main": "./index.js" | ||
} |
@@ -22,2 +22,8 @@ var sf = require('../'); | ||
'nested location using brackets': function (test) { | ||
var result = sf("a{a['b']['c']}b", {a: {b: {c: 'test'}}}); | ||
test.equals(result, 'atestb'); | ||
test.done(); | ||
}, | ||
'nested location (undefined)': function (test) { | ||
@@ -97,2 +103,8 @@ try { | ||
'bunched together date formatting': function (test) { | ||
var result = sf("a{0:yyyyMMddHHmmss}b", new Date(2012, 1, 2, 3, 4, 5)); | ||
test.equals(result, 'a20120202030405b'); | ||
test.done(); | ||
}, | ||
'number format (comma)': function (test) { | ||
@@ -393,7 +405,4 @@ var result = sf("a{0:#,###}b", 5000); | ||
'date format (bad format)': function (test) { | ||
try { | ||
sf("a{0:aaa}b", new Date(2012, 1, 2, 3, 4, 5, 6)); | ||
test.fail("should throw"); | ||
} catch (ex) { | ||
} | ||
var result = sf("a{0:aaa}b", new Date(2012, 1, 2, 3, 4, 5, 6)); | ||
test.equals(result, 'aaaab'); | ||
test.done(); | ||
@@ -400,0 +409,0 @@ }, |
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
No website
QualityPackage does not have a website.
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
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
1019
0
36836
8
2