Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@flourish/interpreter

Package Overview
Dependencies
Maintainers
10
Versions
33
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@flourish/interpreter - npm Package Compare versions

Comparing version 1.0.1 to 1.0.2

34

interpreter.js

@@ -956,13 +956,16 @@ (function (global, factory) {

if (typeof secondaryTest === "function") {
test = function(str) { return parser(str) !== null && secondaryTest(str); };
test = function(str) {
str = str.trim();
return parser(str) !== null && secondaryTest(str);
};
}
else {
test = function(str) { return parser(str) !== null; };
test = function(str) { return parser(str.trim()) !== null; };
}
return Object.freeze({
test: test,
parse: function(str) { return parser(str); },
parse: function(str) { return parser(str.trim()); },
type: "datetime",
description: format_string,
stringToString: function(str) { return formatter(parser(str)); },
stringToString: function(str) { return formatter(parser(str.trim())); },
datetimeToString: function(dt) { return formatter(dt); }

@@ -1004,3 +1007,3 @@ });

var comma_point = {
test: function(str) { return /^(\+|-)?\d{1,3}(,\d{3})*(\.\d+)?((e|E)(\+|-)?\d+)?$/.test(str); },
test: function(str) { return /^(\+|-)?\d{1,3}(,\d{3})*(\.\d+)?((e|E)(\+|-)?\d+)?$/.test(str.trim()); },
parse: function(str) { return parseFloat(str.replace(/,/g, "")); },

@@ -1013,3 +1016,3 @@ description: "Comma thousand separator, point decimal mark",

var space_point = {
test: function(str) { return /^(\+|-)?\d{1,3}(\s\d{3})*(\.\d+)?((e|E)(\+|-)?\d+)?$/.test(str); },
test: function(str) { return /^(\+|-)?\d{1,3}(\s\d{3})*(\.\d+)?((e|E)(\+|-)?\d+)?$/.test(str.trim()); },
parse: function(str) { return parseFloat(str.replace(/\s/g, "")); },

@@ -1022,3 +1025,3 @@ description: "Space thousand separator, point decimal mark",

var none_point = {
test: function(str) { return /^(\+|-)?\d+(\.\d+)?((e|E)(\+|-)?\d+)?$/.test(str); },
test: function(str) { return /^(\+|-)?\d+(\.\d+)?((e|E)(\+|-)?\d+)?$/.test(str.trim()); },
parse: function(str) { return parseFloat(str); },

@@ -1032,3 +1035,3 @@ description: "No thousand separator, point decimal mark",

var point_comma = {
test: function(str) { return /^(\+|-)?\d{1,3}(\.\d{3})*(,\d+)?((e|E)(\+|-)?\d+)?$/.test(str); },
test: function(str) { return /^(\+|-)?\d{1,3}(\.\d{3})*(,\d+)?((e|E)(\+|-)?\d+)?$/.test(str.trim()); },
parse: function(str) { return parseFloat(str.replace(/\./g, "").replace(/,/, ".")); },

@@ -1041,3 +1044,3 @@ description: "Point thousand separator, comma decimal mark",

var space_comma = {
test: function(str) { return /^(\+|-)?\d{1,3}(\s\d{3})*(,\d+)?((e|E)(\+|-)?\d+)?$/.test(str); },
test: function(str) { return /^(\+|-)?\d{1,3}(\s\d{3})*(,\d+)?((e|E)(\+|-)?\d+)?$/.test(str.trim()); },
parse: function(str) { return parseFloat(str.replace(/\s/g, "").replace(/,/, ".")); },

@@ -1050,3 +1053,3 @@ description: "Space thousand separator, comma decimal mark",

var none_comma = {
test: function(str) { return /^(\+|-)?\d+(,\d+)?((e|E)(\+|-)?\d+)?$/.test(str); },
test: function(str) { return /^(\+|-)?\d+(,\d+)?((e|E)(\+|-)?\d+)?$/.test(str.trim()); },
parse: function(str) { return parseFloat(str.replace(/,/, ".")); },

@@ -1146,6 +1149,11 @@ description: "No thousand separator, comma decimal mark",

function trim(value) {
return ("" + value).trim();
}
function createAccessorFunction(accessor) {
if (accessor === undefined) return function(value) { return value; };
if (typeof accessor === "function") return function(value, index) { return accessor(value, index); };
return function(value) { return value["" + accessor]; };
if (accessor === undefined) return function(value) { return trim(value); };
if (typeof accessor === "function") return function(value, index) { return trim(accessor(value, index)); };
return function(value) { return trim(value["" + accessor]); };
}

@@ -1152,0 +1160,0 @@

{
"name": "@flourish/interpreter",
"version": "1.0.1",
"version": "1.0.2",
"description": "Does a best guess at the type of data supplied",

@@ -5,0 +5,0 @@ "main": "interpreter.js",

@@ -29,5 +29,10 @@ # Flourish interpreter

## `interpreter(array_of_strings)`
Interpret the `array_of_strings` passed in. Returns an array of interpretation objects (see the section on Interpretation objects below). Each object in the array has passed through the interpretation proceedure and can be though of a as a valid interpretation for the data, given the conditions specified using methods of the `interpreter` function.
## `interpreter(input_array, [accessor])`
Interpret the `input_array` passed in.
If `accessor` is `undefined` then the interpreter acts directly on each element of the array. If `accessor` is a function then the interpeter acts on the result of calling that function with the array value as the first argument and the array index as the second argument. Otherwise, the interpreter acts on the property equal to the value of `accessor` for each element of the `input_array`.
Returns an array of interpretation objects (see the section on Interpretation objects below). Each object in the array has passed through the interpretation proceedure and can be though of a as a valid interpretation for the data, given the conditions specified using methods of the `interpreter` function.
## `interpreter` methods

@@ -34,0 +39,0 @@ Each method of an `interpreter` function acts as both as a setter and a getter depending on whether or not a (non-`undefined`) argument is supplied. The functionality of these methods is described below.

@@ -0,3 +1,7 @@

# 1.0.2
* Trim whitespace
* Add missing info to README
# 1.0.1
Make work with `require` import
* Make work with `require` import

@@ -4,0 +8,0 @@ # 1.0.0

@@ -33,6 +33,11 @@ import { datetime_interpretations } from "./types/datetime";

function trim(value) {
return ("" + value).trim();
}
function createAccessorFunction(accessor) {
if (accessor === undefined) return function(value) { return value; };
if (typeof accessor === "function") return function(value, index) { return accessor(value, index); };
return function(value) { return value["" + accessor]; };
if (accessor === undefined) return function(value) { return trim(value); };
if (typeof accessor === "function") return function(value, index) { return trim(accessor(value, index)); };
return function(value) { return trim(value["" + accessor]); };
}

@@ -39,0 +44,0 @@

@@ -9,13 +9,16 @@ import { timeFormat, timeParse } from "d3-time-format";

if (typeof secondaryTest === "function") {
test = function(str) { return parser(str) !== null && secondaryTest(str); };
test = function(str) {
str = str.trim();
return parser(str) !== null && secondaryTest(str);
};
}
else {
test = function(str) { return parser(str) !== null; };
test = function(str) { return parser(str.trim()) !== null; };
}
return Object.freeze({
test: test,
parse: function(str) { return parser(str); },
parse: function(str) { return parser(str.trim()); },
type: "datetime",
description: format_string,
stringToString: function(str) { return formatter(parser(str)); },
stringToString: function(str) { return formatter(parser(str.trim())); },
datetimeToString: function(dt) { return formatter(dt); }

@@ -22,0 +25,0 @@ });

// https://stackoverflow.com/a/16148273
var comma_point = {
test: function(str) { return /^(\+|-)?\d{1,3}(,\d{3})*(\.\d+)?((e|E)(\+|-)?\d+)?$/.test(str); },
test: function(str) { return /^(\+|-)?\d{1,3}(,\d{3})*(\.\d+)?((e|E)(\+|-)?\d+)?$/.test(str.trim()); },
parse: function(str) { return parseFloat(str.replace(/,/g, "")); },

@@ -11,3 +11,3 @@ description: "Comma thousand separator, point decimal mark",

var space_point = {
test: function(str) { return /^(\+|-)?\d{1,3}(\s\d{3})*(\.\d+)?((e|E)(\+|-)?\d+)?$/.test(str); },
test: function(str) { return /^(\+|-)?\d{1,3}(\s\d{3})*(\.\d+)?((e|E)(\+|-)?\d+)?$/.test(str.trim()); },
parse: function(str) { return parseFloat(str.replace(/\s/g, "")); },

@@ -20,3 +20,3 @@ description: "Space thousand separator, point decimal mark",

var none_point = {
test: function(str) { return /^(\+|-)?\d+(\.\d+)?((e|E)(\+|-)?\d+)?$/.test(str); },
test: function(str) { return /^(\+|-)?\d+(\.\d+)?((e|E)(\+|-)?\d+)?$/.test(str.trim()); },
parse: function(str) { return parseFloat(str); },

@@ -30,3 +30,3 @@ description: "No thousand separator, point decimal mark",

var point_comma = {
test: function(str) { return /^(\+|-)?\d{1,3}(\.\d{3})*(,\d+)?((e|E)(\+|-)?\d+)?$/.test(str); },
test: function(str) { return /^(\+|-)?\d{1,3}(\.\d{3})*(,\d+)?((e|E)(\+|-)?\d+)?$/.test(str.trim()); },
parse: function(str) { return parseFloat(str.replace(/\./g, "").replace(/,/, ".")); },

@@ -39,3 +39,3 @@ description: "Point thousand separator, comma decimal mark",

var space_comma = {
test: function(str) { return /^(\+|-)?\d{1,3}(\s\d{3})*(,\d+)?((e|E)(\+|-)?\d+)?$/.test(str); },
test: function(str) { return /^(\+|-)?\d{1,3}(\s\d{3})*(,\d+)?((e|E)(\+|-)?\d+)?$/.test(str.trim()); },
parse: function(str) { return parseFloat(str.replace(/\s/g, "").replace(/,/, ".")); },

@@ -48,3 +48,3 @@ description: "Space thousand separator, comma decimal mark",

var none_comma = {
test: function(str) { return /^(\+|-)?\d+(,\d+)?((e|E)(\+|-)?\d+)?$/.test(str); },
test: function(str) { return /^(\+|-)?\d+(,\d+)?((e|E)(\+|-)?\d+)?$/.test(str.trim()); },
parse: function(str) { return parseFloat(str.replace(/,/, ".")); },

@@ -51,0 +51,0 @@ description: "No thousand separator, comma decimal mark",

@@ -38,5 +38,5 @@ const { expect } = require("chai");

let f = _createAccessorFunction(null);
expect(object_data.map(f)).to.deep.equal([ undefined, undefined, undefined, undefined ]);
expect(object_data.map(f)).to.deep.equal([ "undefined", "undefined", "undefined", "undefined" ]);
f = _createAccessorFunction(null);
expect([ { "null": 7 } ].map(f)).to.deep.equal([ 7 ]);
expect([ { "null": 7 } ].map(f)).to.deep.equal([ "7" ]);
f = _createAccessorFunction(0);

@@ -43,0 +43,0 @@ expect(array_data.map(f)).to.deep.equal([ "a", "a", "a", "a" ]);

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc