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 🙏

© 2025 – Pkg Stats / Ryan Hefner

google-doc-viewer-helper

v2.0.7

Published

Helper utilities for Google Doc Viewer

Downloads

63

Readme

Google Doc Viewer Helper Utils

Google provides a Doc Viewer that leverages their Google Docs platform to show a certain amount of file formats it is compatible with. This library is to ensure we can generate valid Google Doc Viewer URLs, and serves as a utility to know if files are a valid format, that can be leveraged in applications such as ensuring we don't unnecessarily try to route users to an embedded Google Doc Viewer that can't open the file requested anyway.

Getting Started

npm i google-doc-viewer-helper -S

Import in your application:

import gDocHelper from 'google-doc-viewer-helper';

To generate a generic Google Doc URL, leverage

gDocHelper#generateGoogleDocUrlWithParams(params, viewerOverride)

| parameter | type | options | defaultValue | description | |----------------|--------|-------------------|--------------|-----------------------------------------------------------------------| | params | object | n/a | null | All parameters to be used in a Google Doc url | | viewerOverride | string | 'default'/'gview' | 'default' | Which viewer implementation Google Docs will use to open the document |

const testFileUrl = 'http://www.fakeurl.com/myTest.pdf';
const myParams = {
    embedded: false,
    url: testUrl,
};
gDocHelper.generateGoogleDocUrlWithParams(myParams);
// => https://docs.google.com/viewer?embedded=false&url=http%3A%2F%2Fwww.fakeurl.com%2FmyTest.pdf

gDocHelper.generateGoogleDocUrlWithParams(myParams, 'gview');
// => https://docs.google.com/gview?embedded=false&url=http%3A%2F%2Fwww.fakeurl.com%2FmyTest.pdf

You can also use shorthand to generate embedded Google doc urls (Most common usecase). gDocHelper#generateGoogleDocUrlWithParams(urlToEmbed, additionalParams, viewerOverride)

| parameter | type | options | defaultValue | description | |------------------|--------|-------------------|--------------|---------------------------------------------------------------------------------------------| | urlToEmbed | string | n/a | null | URL to file we wish viewer to open | | additionalParams | object | n/a | null | Additional parameters for the Google Doc URL (WARNING: Can override default params) |
| viewerOverride | string | 'default'/'gview' | 'default' | Which viewer implementation Google Docs will use to open the document (WARNING: 'gview' is deprecated, but supports some special cases. An error will be written to the console when selecting this viewer.) |

const testFileUrl = 'http://www.fakeurl.com/myTest.pdf';
gDocHelper.generateEmbeddedGoogleDocUrl(testFileUrl);
// => https://docs.google.com/viewer?embedded=true&url=http%3A%2F%2Fwww.fakeurl.com%2FmyTest.pdf

You can also simply check if a specific file format can be opened by Google Docs Viewer gDocHelper#isSupportedFormat(urlToValidate)

| parameter | type | description | |------------------|--------|--------------------------------------------------------------------| | urlToValidate | string | URL to file we wish to validate as being supported by Google docs |

gDocHelper.isSupportedFormat('http://www.fakeurl.com/myTest.pptx');
// => true

gDocHelper.isSupportedFormat('http://www.fakeurl.com/myTest.xlsx');
// => true

gDocHelper.isSupportedFormat('http://www.fakeurl.com/myTest');
// => false

gDocHelper.isSupportedFormat('http://www.fakeurl.com/myTest.bat');
// => false

Running tests

We leverage mocha and chai for testing, and cover common usecases as part of simple unit testing.

npm test

TODO

  • ~~Remove lodash dependency~~
  • Expose supported formats in case they want to be listed or used elsewhere
  • Expose supported viewers and their requirements.
    • Enforce requirements when using these viewers

Dependencies

NONE!

Authors

  • Doel L Gonzalez

License

This project is licensed under the MIT License