You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

simple-datatables

Package Overview
Dependencies
Maintainers
1
Versions
99
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

simple-datatables - npm Package Compare versions

Comparing version

to
7.0.3

1

dist/dts/read_data.d.ts
import { cellType, DataOption, headerCellType, inputCellType, inputHeaderCellType, columnSettingsType } from "./types";
export declare const readDataCell: (cell: inputCellType, columnSettings: columnSettingsType) => cellType;
export declare const readHeaderCell: (cell: inputHeaderCellType) => headerCellType;
export declare const readDOMHeaderCell: (cell: HTMLElement) => headerCellType;
export declare const readTableData: (dataOption: DataOption, dom: (HTMLTableElement | undefined), columnSettings: any, defaultType: any, defaultFormat: any) => {

@@ -5,0 +6,0 @@ data: any[];

2

dist/dts/types.d.ts

@@ -25,3 +25,3 @@ interface elementNodeType {

data: string | number | boolean | elementNodeType[] | object;
type?: "html";
type?: ("html" | "string");
text?: string;

@@ -28,0 +28,0 @@ }

@@ -27,3 +27,3 @@ import { DiffDOM } from 'diff-dom';

data: string | number | boolean | elementNodeType[] | object;
type?: "html";
type?: ("html" | "string");
text?: string;

@@ -30,0 +30,0 @@ }

@@ -60,8 +60,7 @@ >Please note that the API is not finalised and may change so check back once in while.

* `type` (string, optional): "node" in case of the data field is an array of DiffDOM nodes.
* `text` (string, ptional): In case the browser's automatic conversion of the data field to a string to display in a browser is not working correctly, this field can be sued to control what is being rendered.
* `type` (string, optional): "html" in case of the data field is an array of DiffDOM nodes. "string" in case of a plaintext string.
**Content cells** are also obejcts with the same fields as **header fields** and additionally with this field:
**Content cells** are also objects with the same `data` and `text` fields that **header fields** has and additionally with this field:

@@ -68,0 +67,0 @@ * `order` (string or integer, optional): Used for sorting in case and is useful if the `data` field cannot be used for sorting.

@@ -33,2 +33,27 @@ ### Install

});
```
```
### Initial data
You can either supply initial data through the options object or by starting with a table that already has data filled in.
If you start out with a table that already contains header cells, you can add these attributes to individual header cells
to influence how the corresponding column is treated:
* `data-type`: Can be used to set the type of the column. It works the same as using `type` in the [columns](columns) option.
* `data-hidden`: If set to `"true"` will hide the column. It works the same as using `hidden` in the [columns](columns) option.
* `data-searchable`: If set to `"false"` will prevent searching of the column. It works the same as using `searchable` in the [columns](columns) option.
* `data-sortable`: If set to `"false"` will prevent sorting of the column. It works the same as using `sortable` in the [columns](columns) option.
If you start out with a table that already contains data, you can add these attributes to individual cells to influence how
the cell is being processed:
* `data-content`: If this attribute is present on a cell, the value of this attribute rather than the contents of the cell
will be processed.
* `data-order`: If this attribute is present on a cell, the value of this attribute will be used for ordering the row in case
of sorting. Any other sort order will be overridden. IF the field only xcontains numeric characters, the field will first
be converted to a number.
{
"name": "simple-datatables",
"version": "7.0.2",
"version": "7.0.3",
"description": "A lightweight, dependency-free JavaScript HTML table plugin.",

@@ -5,0 +5,0 @@ "main": "dist/index.js",

@@ -1,2 +0,2 @@

import {stringToObj} from "diff-dom"
import {stringToObj, nodeToObj} from "diff-dom"
import {parseDate} from "./date"

@@ -60,5 +60,55 @@ import {objToText} from "./helpers"

const readDOMDataCell = (cell: HTMLElement, columnSettings : columnSettingsType) : cellType => {
let cellData : cellType
switch (columnSettings.type) {
case "string":
cellData = {
data: cell.innerText
}
break
case "date": {
const data = cell.innerText
cellData = {
data,
order: parseDate(data, columnSettings.format)
}
break
}
case "number":
cellData = {
data: parseInt(cell.innerText, 10),
text: cell.innerText
}
break
case "boolean": {
const data = !["false", "0", "null", "undefined"].includes(cell.innerText.toLowerCase().trim())
cellData = {
data,
order: data ? 1 : 0,
text: data ? "1" : "0"
}
break
}
default: { // "html", "other"
const node = nodeToObj(cell)
cellData = {
data: node.childNodes || [],
text: cell.innerText,
order: cell.innerText
}
break
}
}
return cellData
}
export const readHeaderCell = (cell: inputHeaderCellType) : headerCellType => {
if (cell instanceof Object && cell.constructor === Object && cell.hasOwnProperty("data") && (typeof cell.text === "string" || typeof cell.data === "string")) {
if (
cell instanceof Object &&
cell.constructor === Object &&
cell.hasOwnProperty("data") &&
(typeof cell.text === "string" || typeof cell.data === "string")
) {
return cell

@@ -88,9 +138,23 @@ }

export const readTableData = (dataOption: DataOption, dom: (HTMLTableElement | undefined)=undefined, columnSettings, defaultType, defaultFormat) => {
const decodeDOM = document.createElement("textarea")
const decode = function(input: string) {
decodeDOM.innerHTML = input
return decodeDOM.value
export const readDOMHeaderCell = (cell: HTMLElement) : headerCellType => {
const node = nodeToObj(cell)
let cellData
if (node.childNodes && (node.childNodes.length !== 1 || node.childNodes[0].nodeName !== "#text")) {
cellData = {
data: node.childNodes,
type: "html",
text: objToText(node)
}
} else {
cellData = {
data: cell.innerText,
type: "string"
}
}
return cellData
}
export const readTableData = (dataOption: DataOption, dom: (HTMLTableElement | undefined)=undefined, columnSettings, defaultType, defaultFormat) => {
const data = {

@@ -104,3 +168,3 @@ data: [],

data.headings = Array.from(dom.tHead.querySelectorAll("th")).map((th, index) => {
const heading = readHeaderCell(decode(th.innerHTML))
const heading = readDOMHeaderCell(th)
if (!columnSettings[index]) {

@@ -153,3 +217,12 @@ columnSettings[index] = {

row => Array.from(row.cells).map(
(cell, index) => readDataCell(cell.dataset.content || decode(cell.innerHTML), columnSettings[index])
(cell, index) => {
const cellData = cell.dataset.content ?
readDataCell(cell.dataset.content, columnSettings[index]) :
readDOMDataCell(cell, columnSettings[index])
if (cell.dataset.order) {
cellData.order = isNaN(parseFloat(cell.dataset.order)) ? cell.dataset.order : parseFloat(cell.dataset.order)
}
return cellData
}
)

@@ -156,0 +229,0 @@ )

@@ -33,3 +33,3 @@ // Same definitions as in diff-dom

data: string | number | boolean | elementNodeType[] | object;
type?: "html";
type?: ("html" | "string");
text?: string;

@@ -36,0 +36,0 @@ }

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display