@flourish/interpreter
Advanced tools
Comparing version 0.0.1 to 0.0.2
@@ -952,7 +952,14 @@ (function (global, factory) { | ||
function createDatetimeInterpreter(format_string) { | ||
function createDatetimeInterpreter(format_string, secondaryTest) { | ||
var parser = timeParse(format_string); | ||
var formatter = timeFormat(format_string); | ||
var test; | ||
if (typeof secondaryTest === "function") { | ||
test = function(str) { return parser(str) !== null && secondaryTest(str); }; | ||
} | ||
else { | ||
test = function(str) { return parser(str) !== null; }; | ||
} | ||
return Object.freeze({ | ||
test: function(str) { return parser(str) !== null; }, | ||
test: test, | ||
parse: function(str) { return parser(str); }, | ||
@@ -971,2 +978,3 @@ type: "datetime", | ||
createDatetimeInterpreter("%m/%d/%Y"), | ||
createDatetimeInterpreter("%d/%m/%Y"), | ||
createDatetimeInterpreter("%d-%b-%y"), | ||
@@ -977,3 +985,6 @@ createDatetimeInterpreter("%m/%Y"), | ||
createDatetimeInterpreter("%d %b"), | ||
createDatetimeInterpreter("%Y"), | ||
createDatetimeInterpreter("%Y", function(str) { | ||
var val = parseFloat(str); | ||
return val > 1499 && val < 2200; | ||
}), | ||
createDatetimeInterpreter("%B"), | ||
@@ -984,3 +995,3 @@ createDatetimeInterpreter("%b"), | ||
createDatetimeInterpreter("%X"), | ||
createDatetimeInterpreter("%H:%M %p"), | ||
createDatetimeInterpreter("%I:%M %p"), | ||
createDatetimeInterpreter("%H:%M") | ||
@@ -992,3 +1003,3 @@ ]); | ||
test: function(str) { return /^(\+|-)?\d{1,3}(,\d{3})*(\.\d+)?((e|E)(\+|-)?\d+)?$/.test(str); }, | ||
parse: function(str) { return parseFloat(str.replace(",", "")); }, | ||
parse: function(str) { return parseFloat(str.replace(/,/g, "")); }, | ||
description: "Comma thousand separator, point decimal mark", | ||
@@ -1001,3 +1012,3 @@ thousand_separator: ",", | ||
test: function(str) { return /^(\+|-)?\d{1,3}(\s\d{3})*(\.\d+)?((e|E)(\+|-)?\d+)?$/.test(str); }, | ||
parse: function(str) { return parseFloat(str.replace(/\s/, "").replace(",", "")); }, | ||
parse: function(str) { return parseFloat(str.replace(/\s/g, "")); }, | ||
description: "Space thousand separator, point decimal mark", | ||
@@ -1019,3 +1030,3 @@ thousand_separator: " ", | ||
test: function(str) { return /^(\+|-)?\d{1,3}(\.\d{3})*(,\d+)?((e|E)(\+|-)?\d+)?$/.test(str); }, | ||
parse: function(str) { return parseFloat(str.replace(".", "").replace(",", ".")); }, | ||
parse: function(str) { return parseFloat(str.replace(/\./g, "").replace(/,/, ".")); }, | ||
description: "Point thousand separator, comma decimal mark", | ||
@@ -1028,3 +1039,3 @@ thousand_separator: ".", | ||
test: function(str) { return /^(\+|-)?\d{1,3}(\s\d{3})*(,\d+)?((e|E)(\+|-)?\d+)?$/.test(str); }, | ||
parse: function(str) { return parseFloat(str.replace(/\s/, "").replace(",", ".")); }, | ||
parse: function(str) { return parseFloat(str.replace(/\s/g, "").replace(/,/, ".")); }, | ||
description: "Space thousand separator, comma decimal mark", | ||
@@ -1037,3 +1048,3 @@ thousand_separator: " ", | ||
test: function(str) { return /^(\+|-)?\d+(,\d+)?((e|E)(\+|-)?\d+)?$/.test(str); }, | ||
parse: function(str) { return parseFloat(str.replace(",", ".")); }, | ||
parse: function(str) { return parseFloat(str.replace(/,/, ".")); }, | ||
description: "No thousand separator, comma decimal mark", | ||
@@ -1040,0 +1051,0 @@ thousand_separator: "", |
{ | ||
"name": "@flourish/interpreter", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"description": "Does a best guess at the type of data supplied", | ||
@@ -5,0 +5,0 @@ "main": "interpreter.js", |
import { timeFormat, timeParse } from "d3-time-format"; | ||
function createDatetimeInterpreter(format_string) { | ||
function createDatetimeInterpreter(format_string, secondaryTest) { | ||
var parser = timeParse(format_string); | ||
var formatter = timeFormat(format_string); | ||
var test; | ||
if (typeof secondaryTest === "function") { | ||
test = function(str) { return parser(str) !== null && secondaryTest(str); }; | ||
} | ||
else { | ||
test = function(str) { return parser(str) !== null; }; | ||
} | ||
return Object.freeze({ | ||
test: function(str) { return parser(str) !== null; }, | ||
test: test, | ||
parse: function(str) { return parser(str); }, | ||
@@ -21,2 +28,3 @@ type: "datetime", | ||
createDatetimeInterpreter("%m/%d/%Y"), | ||
createDatetimeInterpreter("%d/%m/%Y"), | ||
createDatetimeInterpreter("%d-%b-%y"), | ||
@@ -27,3 +35,6 @@ createDatetimeInterpreter("%m/%Y"), | ||
createDatetimeInterpreter("%d %b"), | ||
createDatetimeInterpreter("%Y"), | ||
createDatetimeInterpreter("%Y", function(str) { | ||
var val = parseFloat(str); | ||
return val > 1499 && val < 2200; | ||
}), | ||
createDatetimeInterpreter("%B"), | ||
@@ -34,3 +45,3 @@ createDatetimeInterpreter("%b"), | ||
createDatetimeInterpreter("%X"), | ||
createDatetimeInterpreter("%H:%M %p"), | ||
createDatetimeInterpreter("%I:%M %p"), | ||
createDatetimeInterpreter("%H:%M") | ||
@@ -37,0 +48,0 @@ ]); |
// https://stackoverflow.com/a/16148273 | ||
var comma_point = { | ||
test: function(str) { return /^(\+|-)?\d{1,3}(,\d{3})*(\.\d+)?((e|E)(\+|-)?\d+)?$/.test(str); }, | ||
parse: function(str) { return parseFloat(str.replace(",", "")); }, | ||
parse: function(str) { return parseFloat(str.replace(/,/g, "")); }, | ||
description: "Comma thousand separator, point decimal mark", | ||
@@ -12,3 +12,3 @@ thousand_separator: ",", | ||
test: function(str) { return /^(\+|-)?\d{1,3}(\s\d{3})*(\.\d+)?((e|E)(\+|-)?\d+)?$/.test(str); }, | ||
parse: function(str) { return parseFloat(str.replace(/\s/, "").replace(",", "")); }, | ||
parse: function(str) { return parseFloat(str.replace(/\s/g, "")); }, | ||
description: "Space thousand separator, point decimal mark", | ||
@@ -30,3 +30,3 @@ thousand_separator: " ", | ||
test: function(str) { return /^(\+|-)?\d{1,3}(\.\d{3})*(,\d+)?((e|E)(\+|-)?\d+)?$/.test(str); }, | ||
parse: function(str) { return parseFloat(str.replace(".", "").replace(",", ".")); }, | ||
parse: function(str) { return parseFloat(str.replace(/\./g, "").replace(/,/, ".")); }, | ||
description: "Point thousand separator, comma decimal mark", | ||
@@ -39,3 +39,3 @@ thousand_separator: ".", | ||
test: function(str) { return /^(\+|-)?\d{1,3}(\s\d{3})*(,\d+)?((e|E)(\+|-)?\d+)?$/.test(str); }, | ||
parse: function(str) { return parseFloat(str.replace(/\s/, "").replace(",", ".")); }, | ||
parse: function(str) { return parseFloat(str.replace(/\s/g, "").replace(/,/, ".")); }, | ||
description: "Space thousand separator, comma decimal mark", | ||
@@ -48,3 +48,3 @@ thousand_separator: " ", | ||
test: function(str) { return /^(\+|-)?\d+(,\d+)?((e|E)(\+|-)?\d+)?$/.test(str); }, | ||
parse: function(str) { return parseFloat(str.replace(",", ".")); }, | ||
parse: function(str) { return parseFloat(str.replace(/,/, ".")); }, | ||
description: "No thousand separator, comma decimal mark", | ||
@@ -51,0 +51,0 @@ thousand_separator: "", |
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
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
39523
1151