New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@flourish/interpreter

Package Overview
Dependencies
Maintainers
22
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

to
8.6.0

interpreter.min.js

105

interpreter.js
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
typeof define === 'function' && define.amd ? define(['exports'], factory) :
(global = global || self, factory(global.createInterpreter = {}));
}(this, (function (exports) { 'use strict';
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.createInterpreter = {}));
})(this, (function (exports) { 'use strict';

@@ -92,2 +92,5 @@ var t0 = new Date,

var timeDay = day;
day.range;
function weekday(i) {

@@ -112,2 +115,10 @@ return newInterval(function(date) {

sunday.range;
monday.range;
tuesday.range;
wednesday.range;
thursday.range;
friday.range;
saturday.range;
var year = newInterval(function(date) {

@@ -135,2 +146,5 @@ date.setMonth(0, 1);

var timeYear = year;
year.range;
var utcDay = newInterval(function(date) {

@@ -146,2 +160,5 @@ date.setUTCHours(0, 0, 0, 0);

var utcDay$1 = utcDay;
utcDay.range;
function utcWeekday(i) {

@@ -166,2 +183,10 @@ return newInterval(function(date) {

utcSunday.range;
utcMonday.range;
utcTuesday.range;
utcWednesday.range;
utcThursday.range;
utcFriday.range;
utcSaturday.range;
var utcYear = newInterval(function(date) {

@@ -189,2 +214,5 @@ date.setUTCMonth(0, 1);

var utcYear$1 = utcYear;
utcYear.range;
function localDate(d) {

@@ -212,3 +240,3 @@ if (0 <= d.y && d.y < 100) {

function formatLocale(locale) {
function formatLocale$1(locale) {
var locale_dateTime = locale.dateTime,

@@ -379,3 +407,3 @@ locale_date = locale.date,

i = parseSpecifier(d, specifier, string += "", 0),
week, day$1;
week, day;
if (i != string.length) return null;

@@ -401,5 +429,5 @@

if ("Z" in d) {
week = utcDate(newDate(d.y, 0, 1)), day$1 = week.getUTCDay();
week = day$1 > 4 || day$1 === 0 ? utcMonday.ceil(week) : utcMonday(week);
week = utcDay.offset(week, (d.V - 1) * 7);
week = utcDate(newDate(d.y, 0, 1)), day = week.getUTCDay();
week = day > 4 || day === 0 ? utcMonday.ceil(week) : utcMonday(week);
week = utcDay$1.offset(week, (d.V - 1) * 7);
d.y = week.getUTCFullYear();

@@ -409,5 +437,5 @@ d.m = week.getUTCMonth();

} else {
week = localDate(newDate(d.y, 0, 1)), day$1 = week.getDay();
week = day$1 > 4 || day$1 === 0 ? monday.ceil(week) : monday(week);
week = day.offset(week, (d.V - 1) * 7);
week = localDate(newDate(d.y, 0, 1)), day = week.getDay();
week = day > 4 || day === 0 ? monday.ceil(week) : monday(week);
week = timeDay.offset(week, (d.V - 1) * 7);
d.y = week.getFullYear();

@@ -419,5 +447,5 @@ d.m = week.getMonth();

if (!("w" in d)) d.w = "u" in d ? d.u % 7 : "W" in d ? 1 : 0;
day$1 = "Z" in d ? utcDate(newDate(d.y, 0, 1)).getUTCDay() : localDate(newDate(d.y, 0, 1)).getDay();
day = "Z" in d ? utcDate(newDate(d.y, 0, 1)).getUTCDay() : localDate(newDate(d.y, 0, 1)).getDay();
d.m = 0;
d.d = "W" in d ? (d.w + 6) % 7 + d.W * 7 - (day$1 + 5) % 7 : d.w + d.U * 7 - (day$1 + 6) % 7;
d.d = "W" in d ? (d.w + 6) % 7 + d.W * 7 - (day + 5) % 7 : d.w + d.U * 7 - (day + 6) % 7;
}

@@ -708,3 +736,3 @@

function formatDayOfYear(d, p) {
return pad(1 + day.count(year(d), d), p, 3);
return pad(1 + timeDay.count(timeYear(d), d), p, 3);
}

@@ -738,3 +766,3 @@

function formatWeekNumberSunday(d, p) {
return pad(sunday.count(year(d) - 1, d), p, 2);
return pad(sunday.count(timeYear(d) - 1, d), p, 2);
}

@@ -749,3 +777,3 @@

d = dISO(d);
return pad(thursday.count(year(d), d) + (year(d).getDay() === 4), p, 2);
return pad(thursday.count(timeYear(d), d) + (timeYear(d).getDay() === 4), p, 2);
}

@@ -758,3 +786,3 @@

function formatWeekNumberMonday(d, p) {
return pad(monday.count(year(d) - 1, d), p, 2);
return pad(monday.count(timeYear(d) - 1, d), p, 2);
}

@@ -801,3 +829,3 @@

function formatUTCDayOfYear(d, p) {
return pad(1 + utcDay.count(utcYear(d), d), p, 3);
return pad(1 + utcDay$1.count(utcYear$1(d), d), p, 3);
}

@@ -831,3 +859,3 @@

function formatUTCWeekNumberSunday(d, p) {
return pad(utcSunday.count(utcYear(d) - 1, d), p, 2);
return pad(utcSunday.count(utcYear$1(d) - 1, d), p, 2);
}

@@ -842,3 +870,3 @@

d = UTCdISO(d);
return pad(utcThursday.count(utcYear(d), d) + (utcYear(d).getUTCDay() === 4), p, 2);
return pad(utcThursday.count(utcYear$1(d), d) + (utcYear$1(d).getUTCDay() === 4), p, 2);
}

@@ -851,3 +879,3 @@

function formatUTCWeekNumberMonday(d, p) {
return pad(utcMonday.count(utcYear(d) - 1, d), p, 2);
return pad(utcMonday.count(utcYear$1(d) - 1, d), p, 2);
}

@@ -891,4 +919,2 @@

var locale;
var timeFormat;
var timeParse;
var utcFormat;

@@ -909,5 +935,5 @@ var utcParse;

function defaultLocale(definition) {
locale = formatLocale(definition);
timeFormat = locale.format;
timeParse = locale.parse;
locale = formatLocale$1(definition);
locale.format;
locale.parse;
utcFormat = locale.utcFormat;

@@ -922,3 +948,2 @@ utcParse = locale.utcParse;

function shield(func) {

@@ -969,3 +994,2 @@ return function(str) {

// Checks a string against datetime regexes for different strftime date formats so that

@@ -1099,2 +1123,8 @@ // non-standard datetime strings can still be parsed as dates by d3-time-parse

}),
createDatetimeInterpretation("%Y%m", function(str, passed_primary_test) { // 197204
if (!passed_primary_test) return false;
var year = parseFloat(str.slice(0, 4));
var month = parseFloat(str.slice(4));
return year > 1000 && month > 0 && month <= 12;
}),

@@ -1147,2 +1177,3 @@ createDatetimeInterpretation("%d %b %Y", function(str, passed_primary_test) { // 27 Apr 1972

createDatetimeInterpretation("%b '%y"), // Apr '72
createDatetimeInterpretation("%b ’%y"), // Apr ’72
createDatetimeInterpretation("%B %-d %Y"), // April 27 1972

@@ -1361,3 +1392,3 @@

function formatLocale$1(locale) {
function formatLocale(locale) {
var group = locale.grouping === undefined || locale.thousands === undefined ? identity : formatGroup(map.call(locale.grouping, Number), locale.thousands + ""),

@@ -1502,3 +1533,3 @@ currencyPrefix = locale.currency === undefined ? "" : locale.currency[0] + "",

var thousands = interp.thousand_separator;
var locale = formatLocale$1({decimal: decimal, thousands: thousands, grouping: [3], currency: ["", ""]});
var locale = formatLocale({decimal: decimal, thousands: thousands, grouping: [3], currency: ["", ""]});
var format, specifier;

@@ -1517,3 +1548,2 @@

// https://stackoverflow.com/a/16148273

@@ -1550,3 +1580,2 @@ var comma_point = {

var point_comma = {

@@ -1582,3 +1611,2 @@ test: shield(function(str) { return /^(\+|-)?\d{1,3}(\.\d{3})*(,\d+)?((e|E)(\+|-)?\d+)?$/.test(str.trim()); }),

var number_interpretations = Object.freeze([

@@ -1624,3 +1652,2 @@ comma_point,

function snakeToCamel(snake_string) {

@@ -1632,7 +1659,5 @@ return snake_string.replace(/_(\w)/g, function(match, capture) {

function noSort(a, b) { return a.index - b.index; }
function sortBySuccess(a, b) { return b.n_success - a.n_success || noSort(a, b); }
function trim(value) {

@@ -1642,3 +1667,2 @@ return ("" + value).trim();

function createAccessorFunction(accessor) {

@@ -1650,3 +1674,2 @@ if (accessor === undefined) return function(value) { return trim(value); };

function createInterpreter(interpretations_array) {

@@ -1721,3 +1744,2 @@ if (!interpretations_array) interpretations_array = DEFAULT_INTERPRETATIONS_ARRAY;

createInterpreter.DATETIME_IDS = Object.freeze(datetime_interpretations.map(function(d) { return d.id; }));

@@ -1727,3 +1749,2 @@ createInterpreter.NUMBER_IDS = Object.freeze(number_interpretations.map(function(d) { return d.id; }));

createInterpreter.getInterpretation = (function() {

@@ -1735,6 +1756,4 @@ var interpretations = datetime_interpretations.concat(number_interpretations, string_interpretation);

createInterpreter._createAccessorFunction = createAccessorFunction;
var recognised_formats = INTERPRETATION_OPTIONS;

@@ -1745,4 +1764,2 @@

Object.defineProperty(exports, '__esModule', { value: true });
})));
}));
{
"name": "@flourish/interpreter",
"version": "8.5.0",
"version": "8.6.0",
"private": false,

@@ -8,10 +8,2 @@ "description": "Does a best guess at the type of data supplied",

"module": "src/index.js",
"scripts": {
"build": "rollup -c",
"lint": "eslint src",
"minify": "uglifyjs -m -o interpreter.min.js interpreter.js",
"prepare": "npm run build && npm run minify",
"pretest": "npm run build",
"test": "mocha"
},
"author": "Kiln Enterprises Ltd",

@@ -28,10 +20,20 @@ "license": "LicenseRef-LICENSE",

"devDependencies": {
"@babel/core": "^7.23.6",
"@babel/preset-env": "^7.23.6",
"@flourish/eslint-plugin-flourish": "^0.7.2",
"@rollup/plugin-babel": "^6.0.4",
"chai": "^4.2.0",
"eslint": "^8.35.0",
"mocha": "^6.2.2",
"rollup": "^1.25.2",
"rollup-plugin-node-resolve": "^5.2.0",
"mocha": "^10.2.0",
"rollup": "^4.6.1",
"@rollup/plugin-node-resolve": "^15.2.3",
"uglify-js": "^3.6.4"
},
"scripts": {
"build": "rollup -c",
"lint": "eslint .",
"minify": "uglifyjs -m -o interpreter.min.js interpreter.js",
"pretest": "npm run build",
"test": "mocha"
}
}
}

@@ -0,1 +1,4 @@

# 8.6.0
* Add "%b ’%y" and "%Y%m" datetime format
# 8.5.0

@@ -2,0 +5,0 @@ * Add "%d.%m.%Y", "%m.%d.%y" and "%M:%S" datetime formats

@@ -21,3 +21,2 @@ import { datetime_interpretations } from "./types/datetime.js";

function snakeToCamel(snake_string) {

@@ -29,7 +28,5 @@ return snake_string.replace(/_(\w)/g, function(match, capture) {

function noSort(a, b) { return a.index - b.index; }
function sortBySuccess(a, b) { return b.n_success - a.n_success || noSort(a, b); }
function trim(value) {

@@ -39,3 +36,2 @@ return ("" + value).trim();

function createAccessorFunction(accessor) {

@@ -47,3 +43,2 @@ if (accessor === undefined) return function(value) { return trim(value); };

export function createInterpreter(interpretations_array) {

@@ -118,3 +113,2 @@ if (!interpretations_array) interpretations_array = DEFAULT_INTERPRETATIONS_ARRAY;

createInterpreter.DATETIME_IDS = Object.freeze(datetime_interpretations.map(function(d) { return d.id; }));

@@ -124,3 +118,2 @@ createInterpreter.NUMBER_IDS = Object.freeze(number_interpretations.map(function(d) { return d.id; }));

createInterpreter.getInterpretation = (function() {

@@ -132,7 +125,5 @@ var interpretations = datetime_interpretations.concat(number_interpretations, string_interpretation);

createInterpreter._createAccessorFunction = createAccessorFunction;
export var recognised_formats = INTERPRETATION_OPTIONS;

@@ -5,3 +5,2 @@ function notAStringError(not_a_str) {

function shield(func) {

@@ -15,3 +14,2 @@ return function(str) {

export { shield, notAStringError };

@@ -41,3 +41,2 @@ import { utcParse, utcFormat } from "d3-time-format";

// Checks a string against datetime regexes for different strftime date formats so that

@@ -171,2 +170,8 @@ // non-standard datetime strings can still be parsed as dates by d3-time-parse

}),
createDatetimeInterpretation("%Y%m", function(str, passed_primary_test) { // 197204
if (!passed_primary_test) return false;
var year = parseFloat(str.slice(0, 4));
var month = parseFloat(str.slice(4));
return year > 1000 && month > 0 && month <= 12;
}),

@@ -219,2 +224,3 @@ createDatetimeInterpretation("%d %b %Y", function(str, passed_primary_test) { // 27 Apr 1972

createDatetimeInterpretation("%b '%y"), // Apr '72
createDatetimeInterpretation("%b ’%y"), // Apr ’72
createDatetimeInterpretation("%B %-d %Y"), // April 27 1972

@@ -273,3 +279,2 @@

export { datetime_interpretations };
import { shield } from "./common.js";
import { formatLocale } from "d3-format";
function getFormatFunction(interp) {

@@ -22,3 +21,2 @@ var decimal = interp.decimal_mark;

// https://stackoverflow.com/a/16148273

@@ -55,3 +53,2 @@ var comma_point = {

var point_comma = {

@@ -87,3 +84,2 @@ test: shield(function(str) { return /^(\+|-)?\d{1,3}(\.\d{3})*(,\d+)?((e|E)(\+|-)?\d+)?$/.test(str.trim()); }),

var number_interpretations = Object.freeze([

@@ -104,3 +100,2 @@ comma_point,

export { number_interpretations };
import { notAStringError } from "./common.js";
var string_interpretation = Object.freeze({

@@ -13,3 +12,2 @@ test: function(str) { return typeof str === "string" ? true : notAStringError(str); },

export { string_interpretation };

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

const string_data = [ "a", "b", "c", "d"];

@@ -11,3 +10,2 @@ const object_data = [ { letter: "a" }, { letter: "b" }, { letter: "c" }, { letter: "d" }];

describe("_createAccessorFunction", () => {

@@ -49,3 +47,2 @@ describe("when no accessor argument is passed in", () => {

describe("interpeter", () => {

@@ -65,2 +62,14 @@ it("should return only the string-type object (at most) for an empty array", () => {

it("should interpret sparse columns based on the non-empty values", () => {
let interpret = createInterpreter();
let interpretations = interpret(["I'm a string", "", "", "", ""]);
expect(interpretations[0].type).to.equal("string");
interpretations = interpret([10, 2, "", "", "", ""]);
expect(interpretations[0].type).to.equal("number");
interpretations = interpret(["2016-12-03T08:19:56.000Z", "", "", "", ""]);
expect(interpretations[0].type).to.equal("datetime");
});
it("should correctly interpret and format well-formatted datetimes", () => {

@@ -95,2 +104,3 @@ const interpret = createInterpreter();

expect(checkMatch(["Dec '16", "Apr '27", "Oct '02"], "%b '%y")).to.equal(true);
expect(checkMatch(["Dec ’16", "Apr ’27", "Oct ’02"], "%b ’%y")).to.equal(true);
expect(checkMatch(["December 3 2016", "April 27 1927", "October 21 1502"], "%B %-d %Y")).to.equal(true);

@@ -178,3 +188,2 @@ expect(checkMatch(["03 Dec 16", "27 Apr 27", "21 Oct 02"], "%d %b %y")).to.equal(true);

describe("interpeter.parse", () => {

@@ -194,2 +203,3 @@ describe("Parsing datetimes", () => {

checkMatch("%Y-%m", "2016-12", 2016);
checkMatch("%Y%m", "201612", 2016);
checkMatch("%m/%d/%Y %H:%M", "12/03/2016 19:45", 2016);

@@ -264,3 +274,2 @@ checkMatch("%m/%d/%y", "12/03/16", 2016);

describe("createInterpreter.DATETIME_IDS", () => {

@@ -293,3 +302,2 @@ it("should be a frozen array of strings", () => {

describe("createInterpreter.getInterpretation", () => {

@@ -324,3 +332,2 @@ const checkMethod = function(id) { return createInterpreter.getInterpretation(id).id === id; };

// All numeric types use a single method to create a formatter function so just test one formatter

@@ -327,0 +334,0 @@ describe("format method of number$space_comma interpretation", () => {