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

google-docs-components

Package Overview
Dependencies
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

google-docs-components - npm Package Compare versions

Comparing version 1.0.3 to 1.0.4

dist/cjs/componentsFromDoc.d.ts

18

dist/cjs/index.d.ts

@@ -1,14 +0,6 @@

import type { document, element } from "google-docs-parser";
import { ComponentData, Config, ContentData, ElementData } from "./types";
import { ComponentData, Config, ContentData, ElementData, TableData } from "./types";
import { ProcessedContent } from "./types";
export declare type ParseContent = (element: Array<element>) => ProcessedContent;
export type { ProcessedContent, ComponentData, ContentData, ElementData, Config };
export declare type ProcessedDocument = {
body: ProcessedContent;
footnotes: {
[index: number]: ProcessedContent;
};
readAt: number;
title: string;
};
export declare function componentsFromDoc(config: Config, doc: document): ProcessedDocument;
import componentsFromDoc from "./componentsFromDoc";
import findSections from "./findSections";
export type { ProcessedContent, ComponentData, ContentData, ElementData, TableData, Config };
export { componentsFromDoc, findSections };

@@ -6,102 +6,7 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.componentsFromDoc = void 0;
const processTable_1 = __importDefault(require("./processTable"));
function componentsFromDoc(config, doc) {
const footnoteMap = {};
function processElement(element) {
if (typeof element == "string") {
return element;
}
if (element.type == "paragraph") {
const paragraph = element;
const data = {
element: "p",
children: parseContent(paragraph.children),
};
return data;
}
if (element.type == "list") {
const list = element;
const tag = list.ordered ? "ol" : "ul";
const toListItems = (elements) => {
const listItems = [];
elements.forEach((child) => {
if (listItems.length && (child === null || child === void 0 ? void 0 : child.element) == "ul" || child.element == "ol") {
listItems[listItems.length - 1].children.push(child);
return;
}
if (child.children) {
//Google Docs considers list items as paragraphs, but we don't want that in our html
listItems.push(Object.assign({}, child, { element: "li" }));
return;
}
listItems.push({
element: "li",
children: [child]
});
});
return listItems;
};
const data = {
element: tag,
children: toListItems(parseContent(list.items))
};
return data;
}
if (element.type == "styledText") {
const styledText = element;
const tag = styledText.link ? "a" : "span";
const data = Object.assign({ element: tag, children: [styledText.text], style: styledText.css }, (styledText.link && { attrs: { href: styledText.link } }));
return data;
}
if (element.type == "table") {
const table = element;
const component = processTable_1.default(config.components, table, parseContent);
if ("error" in component) {
console.error(component.message);
if (component.error == "ComponentNotFoundError") {
const data = {
rows: table.rows,
cells: table.cells.map(parseContent)
};
return data;
}
return false;
}
return component;
}
if (element.type == "footnoteReference") {
const { footnoteNumber, footnoteId } = element;
footnoteMap[footnoteId] = footnoteNumber;
return {
component: "FootnoteReference",
props: {
footnoteNumber: footnoteNumber
}
};
}
return false;
}
const parseContent = (elements) => {
if (Array.isArray(elements)) {
return elements.map(processElement).filter(Boolean);
}
};
if (doc) {
const processedBody = parseContent(doc.body);
let processedFootnotes;
if (doc.footnotes) {
const footnoteContent = (footnoteId) => {
const footnote = doc.footnotes[footnoteId];
if (!footnote)
return false;
return parseContent(footnote);
};
const footnoteEntries = Object.entries(footnoteMap).map(([footnoteId, footnoteNumber]) => ([footnoteNumber, footnoteContent(footnoteId)]));
processedFootnotes = Object.fromEntries(footnoteEntries);
}
return Object.assign({ body: processedBody, title: doc.title, readAt: doc.readAt }, (processedFootnotes && { footnotes: processedFootnotes }));
}
}
exports.componentsFromDoc = componentsFromDoc;
exports.findSections = exports.componentsFromDoc = void 0;
const componentsFromDoc_1 = __importDefault(require("./componentsFromDoc"));
exports.componentsFromDoc = componentsFromDoc_1.default;
const findSections_1 = __importDefault(require("./findSections"));
exports.findSections = findSections_1.default;
//# sourceMappingURL=index.js.map
import { ComponentData, ComponentDef, DevSlotData } from "./types";
import { elementTypes } from "google-docs-parser";
import { ParseContent } from "./index";
import { ParseContent } from "./componentsFromDoc";
declare type Table = elementTypes.table;

@@ -5,0 +5,0 @@ export declare type ComponentParseErrorType = "TableFormatError" | "InvalidPropError" | "ComponentError" | "ComponentNotFoundError";

export declare type ContentData = ElementData | ComponentData | TableData | DevSlotData;
export declare type ProcessedContent = Array<ContentData>;
export declare type ProcessedDocument = {
body: ProcessedContent;
footnotes: {
[index: number]: ProcessedContent;
};
readAt: number;
title: string;
};
export declare type ElementData = string | {

@@ -4,0 +12,0 @@ element: string;

@@ -1,14 +0,6 @@

import type { document, element } from "google-docs-parser";
import { ComponentData, Config, ContentData, ElementData } from "./types";
import { ComponentData, Config, ContentData, ElementData, TableData } from "./types";
import { ProcessedContent } from "./types";
export declare type ParseContent = (element: Array<element>) => ProcessedContent;
export type { ProcessedContent, ComponentData, ContentData, ElementData, Config };
export declare type ProcessedDocument = {
body: ProcessedContent;
footnotes: {
[index: number]: ProcessedContent;
};
readAt: number;
title: string;
};
export declare function componentsFromDoc(config: Config, doc: document): ProcessedDocument;
import componentsFromDoc from "./componentsFromDoc";
import findSections from "./findSections";
export type { ProcessedContent, ComponentData, ContentData, ElementData, TableData, Config };
export { componentsFromDoc, findSections };

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

import componentFromTable from "./processTable";
export function componentsFromDoc(config, doc) {
const footnoteMap = {};
function processElement(element) {
if (typeof element == "string") {
return element;
}
if (element.type == "paragraph") {
const paragraph = element;
const data = {
element: "p",
children: parseContent(paragraph.children),
};
return data;
}
if (element.type == "list") {
const list = element;
const tag = list.ordered ? "ol" : "ul";
const toListItems = (elements) => {
const listItems = [];
elements.forEach((child) => {
if (listItems.length && (child === null || child === void 0 ? void 0 : child.element) == "ul" || child.element == "ol") {
listItems[listItems.length - 1].children.push(child);
return;
}
if (child.children) {
//Google Docs considers list items as paragraphs, but we don't want that in our html
listItems.push(Object.assign({}, child, { element: "li" }));
return;
}
listItems.push({
element: "li",
children: [child]
});
});
return listItems;
};
const data = {
element: tag,
children: toListItems(parseContent(list.items))
};
return data;
}
if (element.type == "styledText") {
const styledText = element;
const tag = styledText.link ? "a" : "span";
const data = Object.assign({ element: tag, children: [styledText.text], style: styledText.css }, (styledText.link && { attrs: { href: styledText.link } }));
return data;
}
if (element.type == "table") {
const table = element;
const component = componentFromTable(config.components, table, parseContent);
if ("error" in component) {
console.error(component.message);
if (component.error == "ComponentNotFoundError") {
const data = {
rows: table.rows,
cells: table.cells.map(parseContent)
};
return data;
}
return false;
}
return component;
}
if (element.type == "footnoteReference") {
const { footnoteNumber, footnoteId } = element;
footnoteMap[footnoteId] = footnoteNumber;
return {
component: "FootnoteReference",
props: {
footnoteNumber: footnoteNumber
}
};
}
return false;
}
const parseContent = (elements) => {
if (Array.isArray(elements)) {
return elements.map(processElement).filter(Boolean);
}
};
if (doc) {
const processedBody = parseContent(doc.body);
let processedFootnotes;
if (doc.footnotes) {
const footnoteContent = (footnoteId) => {
const footnote = doc.footnotes[footnoteId];
if (!footnote)
return false;
return parseContent(footnote);
};
const footnoteEntries = Object.entries(footnoteMap).map(([footnoteId, footnoteNumber]) => ([footnoteNumber, footnoteContent(footnoteId)]));
processedFootnotes = Object.fromEntries(footnoteEntries);
}
return Object.assign({ body: processedBody, title: doc.title, readAt: doc.readAt }, (processedFootnotes && { footnotes: processedFootnotes }));
}
}
import componentsFromDoc from "./componentsFromDoc";
import findSections from "./findSections";
export { componentsFromDoc, findSections };
//# sourceMappingURL=index.js.map
import { ComponentData, ComponentDef, DevSlotData } from "./types";
import { elementTypes } from "google-docs-parser";
import { ParseContent } from "./index";
import { ParseContent } from "./componentsFromDoc";
declare type Table = elementTypes.table;

@@ -5,0 +5,0 @@ export declare type ComponentParseErrorType = "TableFormatError" | "InvalidPropError" | "ComponentError" | "ComponentNotFoundError";

export declare type ContentData = ElementData | ComponentData | TableData | DevSlotData;
export declare type ProcessedContent = Array<ContentData>;
export declare type ProcessedDocument = {
body: ProcessedContent;
footnotes: {
[index: number]: ProcessedContent;
};
readAt: number;
title: string;
};
export declare type ElementData = string | {

@@ -4,0 +12,0 @@ element: string;

{
"name": "google-docs-components",
"version": "1.0.3",
"version": "1.0.4",
"main": "./dist/cjs/index.js",

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

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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