npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

googledocs-downloader

v1.0.0

Published

`googledocs-downloader` is a library for downloading Google Docs documents in various formats and saving their content locally. The library provides functions to retrieve the content of a document in plain text, extract the document ID from a Google Docs

Downloads

192

Readme

GoogleDocs Downloader

googledocs-downloader is a library for downloading Google Docs documents in various formats and saving their content locally. The library provides functions to retrieve the content of a document in plain text, extract the document ID from a Google Docs URL, and download and save the document in different formats.

Installation

To install the library, you can use npm or yarn:

npm install googledocs-downloader

or

yarn add googledocs-downloader

Usage

1. Fetch the content of a Google Docs document in plain text format

import { getTxtDoc } from 'googledocs-downloader';

(async () => {
  const documentId = 'your_document_id_here';
  const content = await getTxtDoc(documentId);

  if (content) {
    console.log('Document content:', content);
  } else {
    console.error('Failed to fetch document content.');
  }
})();

Description

getTxtDoc(documentId: string): Promise<string | null>

  • documentId: The unique identifier of the Google Docs document you want to download.
  • Returns: A promise that resolves to the text content of the document, or null if an error occurs.

2. Extract the document ID from a Google Docs URL

import { getIdDocFromUrl } from 'googledocs-downloader';

const url = 'https://docs.google.com/document/d/1a2b3c4d5e6f7g8h9i0j1k2l3m4n5o6p7';
const documentId = getIdDocFromUrl(url);

console.log('Document ID:', documentId);

Description

getIdDocFromUrl(url: string): string

  • url: The full URL of the Google Docs document.
  • Returns: The extracted document ID from the URL.
  • Throws: Will throw an error if the document ID cannot be extracted from the URL.

3. Download a Google Docs document in a specified format and save it locally

import { savefile } from 'googledocs-downloader';

(async () => {
  const documentId = 'your_document_id_here';
  const dirPath = './downloads';
  const filename = 'my_document';
  const format = 'pdf'; // Supported formats: 'pdf', 'docx', 'odt', 'rtf', 'txt', 'html'

  const filePath = await savefile(documentId, dirPath, filename, format);

  if (filePath) {
    console.log(`Document successfully saved at ${filePath}`);
  } else {
    console.error('Failed to save the document.');
  }
})();

Description

savefile(documentId: string, dirPath: string, filename: string, format: 'pdf' | 'docx' | 'odt' | 'rtf' | 'txt' | 'html'): Promise<string | null>

  • documentId: The ID of the Google Docs document you want to download.
  • dirPath: The path to the directory where the file will be saved.
  • filename: The name of the file without the extension.
  • format: The format in which you want to download the document. Supported formats are 'pdf', 'docx', 'odt', 'rtf', 'txt', and 'html'.
  • Returns: A promise that resolves to the file path if the document is saved successfully, or null if an error occurs.
  • Throws: Will log an error to the console if the documentId, dirPath, filename, or format are invalid, or if there is an issue saving the file.

Contributing

If you wish to contribute to this project, please fork the repository and submit a pull request with your improvements.

License

MIT License. See the LICENSE file for more details.