@flourish/interpreter
Advanced tools
Comparing version 0.1.0 to 0.2.0
@@ -6,6 +6,3 @@ { | ||
"extends": "plugin:@flourish/flourish/flourish", | ||
"rules": { | ||
"space-before-blocks": ["error", "always"] | ||
}, | ||
"env": { "browser": true } | ||
} |
{ | ||
"name": "@flourish/interpreter", | ||
"version": "0.1.0", | ||
"version": "0.2.0", | ||
"description": "Does a best guess at the type of data supplied", | ||
"main": "interpreter.js", | ||
"module": "src/index.js", | ||
"directories": { | ||
"test": "test" | ||
}, | ||
"main": "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", | ||
"minify": "uglifyjs -m -o interpreter.min.js interpreter.js", | ||
"lint": "eslint src" | ||
"pretest": "npm run build", | ||
"test": "mocha" | ||
}, | ||
@@ -23,11 +21,13 @@ "author": "Kiln Enterprises Ltd", | ||
"dependencies": { | ||
"d3-time-format": "^2.0.5", | ||
"rollup": "^0.41.1", | ||
"rollup-plugin-node-resolve": "^3.0.0", | ||
"uglify-js": "^2.7.5" | ||
"d3-time-format": "^2.0.5" | ||
}, | ||
"devDependencies": { | ||
"chai": "^4.2.0", | ||
"@flourish/eslint-plugin-flourish": "^0.7.2", | ||
"eslint": "git://github.com/robinhouston/eslint.git#bug-ignoredNodes", | ||
"pre-commit": "^1.2.2" | ||
"eslint": "^6.4.0", | ||
"mocha": "^6.2.0", | ||
"rollup": "^1.21.4", | ||
"rollup-plugin-node-resolve": "^5.2.0", | ||
"pre-commit": "^1.2.2", | ||
"uglify-js": "^2.7.5" | ||
}, | ||
@@ -34,0 +34,0 @@ "precommit": [ |
@@ -0,3 +1,10 @@ | ||
# 0.2.0 | ||
* Add 1pm and 01/86 formats | ||
* Drop Tue and Tuesday formats | ||
* Allow usage of accessor function for second argument of intepreter | ||
* Convert second arguments that aren't undefined, functions or strings to strings (allows for array indexing with numbers) | ||
* Add a few basic tests | ||
# 0.1.0 | ||
* Improve date handling | ||
* Add longitude and latitude types |
import nodeResolve from "rollup-plugin-node-resolve"; | ||
export default { | ||
entry: "src/index.js", | ||
format: "umd", | ||
moduleName: "interpreter", | ||
dest: "interpreter.js", | ||
plugins: [ | ||
nodeResolve() | ||
] | ||
input: "src/index.js", | ||
output: { | ||
file: "interpreter.js", | ||
format: "umd", | ||
name: "interpreter" | ||
}, | ||
plugins: [ | ||
nodeResolve() | ||
], | ||
onwarn: function (warning, warn) { | ||
if (warning.code === "CIRCULAR_DEPENDENCY") return; | ||
if (warning.code === "UNRESOLVED_IMPORT") { | ||
throw new Error( | ||
"Couldn't resolve the dependency " + warning.source + | ||
" (from " + warning.importer + "): sometimes you can" + | ||
" fix this with 'npm install', or add '" + warning.source + | ||
" to 'external'. See: " + warning.url | ||
); | ||
} | ||
warn(warning); | ||
} | ||
}; | ||
@@ -6,9 +6,15 @@ import { datetime_interpreters } from "./types/datetime"; | ||
function createParserTest(val) { return function(func) { return func.test(val); }; } | ||
function createParserTest(val) { return function(interpreter) { return interpreter.test(val); }; } | ||
function _createAccessorFunction(arr, accessor) { | ||
if (accessor === undefined) return function(index) { return arr[index]; }; | ||
if (typeof accessor === "function") return function(index) { return accessor(arr[index], index); }; | ||
return function(index) { return arr[index]["" + accessor]; }; | ||
} | ||
function createInterpreter(n_max) { | ||
n_max = n_max > 0 ? n_max : 1000; | ||
return function(arr, prop) { | ||
return function(arr, accessor) { | ||
if (!Array.isArray(arr)) return undefined; | ||
@@ -18,11 +24,6 @@ if (!arr.length) return string_interpreters.slice(); | ||
var n = Math.min(n_max, arr.length); | ||
var getVal = (function() { | ||
if (typeof prop !== "string") return function(index) { return arr[index]; }; | ||
return function(index) { return arr[index] ? arr[index][prop] : undefined; }; | ||
})(); | ||
var getVal = _createAccessorFunction(arr, accessor); | ||
var interpreters = datetime_interpreters.concat(number_interpreters, coordinate_interpreters); | ||
for (var i = 0; i<n && interpreters.length; i++) { | ||
for (var i = 0; i < n && interpreters.length; i++) { | ||
var val = getVal(i); | ||
@@ -37,2 +38,2 @@ if (val) interpreters = interpreters.filter(createParserTest(val)); | ||
export { createInterpreter }; | ||
export { createInterpreter, _createAccessorFunction }; |
@@ -35,2 +35,3 @@ import { timeFormat, timeParse } from "d3-time-format"; | ||
createDatetimeInterpreter("%d-%b-%y"), | ||
createDatetimeInterpreter("%m/%y"), | ||
createDatetimeInterpreter("%m/%Y"), | ||
@@ -46,6 +47,5 @@ createDatetimeInterpreter("%b %Y"), | ||
createDatetimeInterpreter("%b"), | ||
createDatetimeInterpreter("%A"), | ||
createDatetimeInterpreter("%a"), | ||
createDatetimeInterpreter("%X"), | ||
createDatetimeInterpreter("%I:%M %p"), | ||
createDatetimeInterpreter("%I%p"), | ||
createDatetimeInterpreter("%H:%M") | ||
@@ -52,0 +52,0 @@ ]); |
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
1
11
12864
8
299
1
- Removedrollup@^0.41.1
- Removedrollup-plugin-node-resolve@^3.0.0
- Removeduglify-js@^2.7.5
- Removedalign-text@0.1.4(transitive)
- Removedbuiltin-modules@2.0.0(transitive)
- Removedcamelcase@1.2.1(transitive)
- Removedcenter-align@0.1.3(transitive)
- Removedcliui@2.1.0(transitive)
- Removeddecamelize@1.2.0(transitive)
- Removedfunction-bind@1.1.2(transitive)
- Removedhasown@2.0.2(transitive)
- Removedis-buffer@1.1.6(transitive)
- Removedis-core-module@2.16.1(transitive)
- Removedis-module@1.0.0(transitive)
- Removedkind-of@3.2.2(transitive)
- Removedlazy-cache@1.0.4(transitive)
- Removedlongest@1.0.1(transitive)
- Removedpath-parse@1.0.7(transitive)
- Removedrepeat-string@1.6.1(transitive)
- Removedresolve@1.22.10(transitive)
- Removedright-align@0.1.3(transitive)
- Removedrollup@0.41.6(transitive)
- Removedrollup-plugin-node-resolve@3.4.0(transitive)
- Removedsource-map@0.5.7(transitive)
- Removedsource-map-support@0.4.18(transitive)
- Removedsupports-preserve-symlinks-flag@1.0.0(transitive)
- Removeduglify-js@2.8.29(transitive)
- Removeduglify-to-browserify@1.0.2(transitive)
- Removedwindow-size@0.1.0(transitive)
- Removedwordwrap@0.0.2(transitive)
- Removedyargs@3.10.0(transitive)