@datasketch/taco
Advanced tools
| export default { | ||
| extensions: { | ||
| ts: 'module' | ||
| }, | ||
| nodeArguments: [ | ||
| '--loader=ts-node/esm' | ||
| ] | ||
| } |
| type FactoryObject = { | ||
| editorName: string; | ||
| formatterName: string; | ||
| config: (format: Record<string, any>) => { | ||
| editorParams: Record<string, any>; | ||
| formatterParams: Record<string, any>; | ||
| }; | ||
| }; | ||
| type Factory = { | ||
| [x: string]: FactoryObject; | ||
| }; | ||
| type FactoryResult = { | ||
| editor: string; | ||
| formatter: string; | ||
| editorParams: Record<string, any>; | ||
| formatterParams: Record<string, any>; | ||
| }; | ||
| export declare const factory: Factory; | ||
| export declare const getFactory: (hdType: string, format?: Record<string, any>) => FactoryResult; | ||
| export {}; |
| export declare const factories: Record<string, { | ||
| name: string; | ||
| config: (format: Record<string, any>) => Record<string, any>; | ||
| }>; |
| declare function getFormatter(hdType: string, format?: Record<string, any>): { | ||
| formatter: string | Function; | ||
| formatterParams: Record<string, any>; | ||
| }; | ||
| export { getFormatter }; |
| import test from 'ava' | ||
| import { getColumnDefinitions } from '../src/columns.js' | ||
| import iris from './fixtures/iris.json' assert { type: 'json' } | ||
| import books from './fixtures/books.json' assert { type: 'json' } | ||
| test('it outputs column definition for iris dict', t => { | ||
| const expected = [ | ||
| { | ||
| field: 'sepal_length', | ||
| title: 'Sepal.Length', | ||
| editor: 'number' | ||
| }, | ||
| { | ||
| field: 'sepal_width', | ||
| title: 'Sepal.Width', | ||
| editor: 'number' | ||
| }, | ||
| { | ||
| field: 'petal_length', | ||
| title: 'Petal.Length', | ||
| editor: 'number' | ||
| }, | ||
| { | ||
| field: 'petal_width', | ||
| title: 'Petal.Width', | ||
| editor: 'number' | ||
| }, | ||
| { | ||
| field: 'species', | ||
| title: 'Species', | ||
| editor: 'list', | ||
| editorParams: { | ||
| autocomplete: true, | ||
| multiselect: false, | ||
| values: ['setosa', 'versicolor', 'virginica'] | ||
| } | ||
| } | ||
| ] | ||
| const columnDefinitions = getColumnDefinitions(iris) | ||
| t.deepEqual(columnDefinitions.length, expected.length) | ||
| t.deepEqual(columnDefinitions, expected) | ||
| }) | ||
| test('it outputs column definition for books dict', t => { | ||
| const expected = [ | ||
| { | ||
| field: 'title', | ||
| title: 'Title' | ||
| }, | ||
| { | ||
| field: 'author', | ||
| title: 'Author' | ||
| }, | ||
| { | ||
| field: 'cover', | ||
| title: 'Cover', | ||
| formatter: 'image', | ||
| formatterParams: { | ||
| height: '150px' | ||
| } | ||
| } | ||
| ] | ||
| const columnDefinitions = getColumnDefinitions(books) | ||
| t.deepEqual(columnDefinitions.length, expected.length) | ||
| t.deepEqual(columnDefinitions, expected) | ||
| }) |
| [ | ||
| { | ||
| "id": "title", | ||
| "label": "Title", | ||
| "hdType": "Txt" | ||
| }, | ||
| { | ||
| "id": "author", | ||
| "label": "Author", | ||
| "hdType": "Txt" | ||
| }, | ||
| { | ||
| "id": "cover", | ||
| "label": "Cover", | ||
| "hdType": "Img" | ||
| } | ||
| ] |
| [ | ||
| { | ||
| "id": "sepal_length", | ||
| "label": "Sepal.Length", | ||
| "hdType": "Num" | ||
| }, | ||
| { | ||
| "id": "sepal_width", | ||
| "label": "Sepal.Width", | ||
| "hdType": "Num" | ||
| }, | ||
| { | ||
| "id": "petal_length", | ||
| "label": "Petal.Length", | ||
| "hdType": "Num" | ||
| }, | ||
| { | ||
| "id": "petal_width", | ||
| "label": "Petal.Width", | ||
| "hdType": "Num" | ||
| }, | ||
| { | ||
| "id": "species", | ||
| "label": "Species", | ||
| "hdType": "Cat", | ||
| "format": { | ||
| "categories": [ | ||
| "setosa", | ||
| "versicolor", | ||
| "virginica" | ||
| ] | ||
| } | ||
| } | ||
| ] |
+1
-1
@@ -1,1 +0,1 @@ | ||
| const r={Cat:{name:"list",config:r=>({values:r.categories,autocomplete:!0,multiselect:!1})}};function t(t){if(!Array.isArray(t))throw new Error("Dictionary must be an array");return t.map((t=>{const{editor:e,editorParams:a}=function(t,e={}){const a=r[t];return a?{editor:a.name,editorParams:a.config(e)}:{editor:"input",editorParams:{}}}(t.hdType,t.format);return{title:t.label,field:t.id,editor:e,editorParams:a}}))}export{t as getColumnDefinitions}; | ||
| const r={editorName:"input",formatterName:"plaintext"},t={Cat:Object.assign(Object.assign({},r),{editorName:"list",config:r=>({editorParams:{values:r.categories,autocomplete:!0,multiselect:!1},formatterParams:{}})}),Num:Object.assign(Object.assign({},r),{editorName:"number",config:r=>({editorParams:{},formatterParams:{}})}),Bin:{editorName:"tickCross",formatterName:"tickCross",config:r=>({editorParams:{},formatterParams:{}})}};function a(a){if(!Array.isArray(a))throw new Error("Dictionary must be an array");return a.map((a=>Object.assign({title:a.label,field:a.id},((a,e={})=>{const o=t[a];if(!o){const{editorName:t,formatterName:a}=r;return{editor:t,formatter:a,editorParams:{},formatterParams:{}}}const{editorName:m,formatterName:i}=o,{editorParams:s,formatterParams:n}=o.config(e);return{editor:m,formatter:i,editorParams:s,formatterParams:n}})(a.hdType,a.format))))}export{a as getColumnDefinitions}; |
+1
-1
@@ -1,1 +0,1 @@ | ||
| var Taco=function(t){"use strict";const r={Cat:{name:"list",config:t=>({values:t.categories,autocomplete:!0,multiselect:!1})}};return t.getColumnDefinitions=function(t){if(!Array.isArray(t))throw new Error("Dictionary must be an array");return t.map((t=>{const{editor:e,editorParams:i}=function(t,e={}){const i=r[t];return i?{editor:i.name,editorParams:i.config(e)}:{editor:"input",editorParams:{}}}(t.hdType,t.format);return{title:t.label,field:t.id,editor:e,editorParams:i}}))},t}({}); | ||
| var Taco=function(r){"use strict";const t={editorName:"input",formatterName:"plaintext"},a={Cat:Object.assign(Object.assign({},t),{editorName:"list",config:r=>({editorParams:{values:r.categories,autocomplete:!0,multiselect:!1},formatterParams:{}})}),Num:Object.assign(Object.assign({},t),{editorName:"number",config:r=>({editorParams:{},formatterParams:{}})}),Bin:{editorName:"tickCross",formatterName:"tickCross",config:r=>({editorParams:{},formatterParams:{}})}};return r.getColumnDefinitions=function(r){if(!Array.isArray(r))throw new Error("Dictionary must be an array");return r.map((r=>Object.assign({title:r.label,field:r.id},((r,e={})=>{const o=a[r];if(!o){const{editorName:r,formatterName:a}=t;return{editor:r,formatter:a,editorParams:{},formatterParams:{}}}const{editorName:i,formatterName:m}=o,{editorParams:s,formatterParams:n}=o.config(e);return{editor:i,formatter:m,editorParams:s,formatterParams:n}})(r.hdType,r.format))))},r}({}); |
@@ -5,10 +5,12 @@ type Field = { | ||
| hdType: string; | ||
| format: Record<string, any>; | ||
| format?: Record<string, any>; | ||
| }; | ||
| declare function getColumnDefinitions(dictionary: Field[]): { | ||
| editor: string; | ||
| formatter: string; | ||
| editorParams: Record<string, any>; | ||
| formatterParams: Record<string, any>; | ||
| title: string; | ||
| field: string; | ||
| editor: string | Function; | ||
| editorParams: Record<string, any>; | ||
| }[]; | ||
| export { getColumnDefinitions }; |
@@ -1,4 +0,8 @@ | ||
| export declare const factories: Record<string, { | ||
| name: string; | ||
| config: (format: Record<string, any>) => Record<string, any>; | ||
| }>; | ||
| type FactoryObject = { | ||
| [x: string]: { | ||
| name: string; | ||
| config: (format: Record<string, any>) => Record<string, any>; | ||
| }; | ||
| }; | ||
| export declare const factories: FactoryObject; | ||
| export {}; |
+14
-7
| { | ||
| "name": "@datasketch/taco", | ||
| "version": "0.2.0", | ||
| "version": "0.2.1", | ||
| "description": "", | ||
@@ -9,7 +9,9 @@ "main": "dist/taco.es.js", | ||
| "scripts": { | ||
| "build": "del-cli dist && rollup -c" | ||
| "build": "del-cli dist && rollup -c", | ||
| "test": "ava tests/*", | ||
| "start": "ava --watch" | ||
| }, | ||
| "keywords": [], | ||
| "author": "", | ||
| "license": "ISC", | ||
| "author": "David Daza <david@datasketch.co>", | ||
| "license": "MIT", | ||
| "devDependencies": { | ||
@@ -29,5 +31,10 @@ "@rollup/plugin-terser": "^0.4.1", | ||
| }, | ||
| "engines": { | ||
| "node": "18" | ||
| } | ||
| "repository": { | ||
| "type": "git", | ||
| "url": "git+https://github.com/datasketch/taco.git" | ||
| }, | ||
| "bugs": { | ||
| "url": "https://github.com/datasketch/taco/issues" | ||
| }, | ||
| "homepage": "https://github.com/datasketch/taco#readme" | ||
| } |
+6
-3
@@ -5,3 +5,4 @@ { | ||
| "lib": ["es6"], | ||
| "module": "ES2020", | ||
| "module": "ESNext", | ||
| "moduleResolution": "nodenext", | ||
| "rootDir": "src", | ||
@@ -17,4 +18,6 @@ "declaration": true, | ||
| "noImplicitAny": true, | ||
| "skipLibCheck": true | ||
| } | ||
| "skipLibCheck": true, | ||
| "resolveJsonModule": true | ||
| }, | ||
| "exclude": ["tests"] | ||
| } |
| import { getEditor } from './editor/index.js' | ||
| type Field = { | ||
| id: string | ||
| label: string | ||
| hdType: string | ||
| format: Record<string, any> | ||
| } | ||
| function getColumnDefinitions (dictionary: Field[]) { | ||
| if (!Array.isArray(dictionary)) { | ||
| throw new Error('Dictionary must be an array') | ||
| } | ||
| return dictionary.map(field => { | ||
| const { editor, editorParams } = getEditor(field.hdType, field.format) | ||
| return { | ||
| title: field.label, | ||
| field: field.id, | ||
| editor, | ||
| editorParams | ||
| } | ||
| }) | ||
| } | ||
| export { getColumnDefinitions } |
| export const factories: Record<string, { name: string, config: (format: Record<string, any>) => Record<string, any>}> = { | ||
| Cat: { | ||
| name: 'list', | ||
| config: (format: Record<string, any>) => ({ | ||
| values: format.categories, | ||
| autocomplete: true, | ||
| multiselect: false | ||
| }) | ||
| } | ||
| } |
| import { factories } from './factories.js' | ||
| function getEditor (hdType: string, format: Record<string, any> = {}): { editor: string | Function; editorParams: Record<string, any> } { | ||
| const factory = factories[hdType] | ||
| if (!factory) { | ||
| return { | ||
| editor: 'input', | ||
| editorParams: {} | ||
| } | ||
| } | ||
| return { editor: factory.name, editorParams: factory.config(format) } | ||
| } | ||
| export { getEditor } |
| export * from './columns.js' |
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
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 2 instances in 1 package
Mixed license
LicensePackage contains multiple licenses.
Found 1 instance in 1 package
No contributors or author data
MaintenancePackage does not specify a list of contributors or an author in package.json.
Found 1 instance in 1 package
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
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
No website
QualityPackage does not have a website.
Found 1 instance in 1 package
9395
57.34%19
18.75%0
-100%248
90.77%0
-100%3
-25%0
-100%1
Infinity%