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

docparser-node

v1.2.2

Published

Docparser API Node Client

Downloads

852

Readme

Documentation

For a generic description of the Docparser API, please see our developer documentation here. Our developer documentation lists all available API methods with their parameters and expected responses.

Installation

This library is available from npm.

npm install docparser-node

Configuration

Create a Docparser JavaScript Client by using your Docparser API Token:

var docparser = require('docparser-node');

var client = new docparser.Client("validAPIKey");

Test Your Authentication

You can call our ping() method to test your API key. The method retuns a promise.

client.ping()
  .then(function() {
    console.log('authentication succeeded!')
  })
  .catch(function(err) {
    console.log('authentication failed!')
  })

Usage

Document Parsers

List All Document Parsers Returns a list of the document parsers created in your account.

client.getParsers()
  .then(function (parsers) {
    console.log(parsers)
    // => [{"id":"someparserid","label":"My Document Parser"}]

  })
  .catch(function (err) {
    console.log(err)
  })

Documents

The Docparser JavaScript SDK offers two different methods for importing your document.

All import methods allow you to pass an optional remote_id with your document. The remote ID can be any arbitrary string with a maximum length of 255 characters. The submitted value will be kept throughout the processing and will be available later once you obtain the parsed data with our API or through Webhooks. The remote_id can be passed in the options object to our upload methods.

The upload methods (uploadByPath, uploadByStream) allow you to override the filename by specifying the filename parameter in options.

Upload Document From Local File System

Reads a file from your local filesystem and uploads it to your document parser.

client.uploadFileByPath('someparserid', './test.pdf', {remote_id: 'test'})
  .then(function (result) {
    // => {"id":"document_id","file_size":198989,"quota_used":16,"quota_left":34,"quota_refill":"1970-01-01T00:00:00+00:00"}
  })
  .catch(function (err) {
    console.log(err)
  })

Upload Document From A Readable Stream

This method creates a new document in your document parser based on the raw file content or a file pointer. Additionally, a filename and a remote_id can be provided in the options object.

client.uploadFileByStream('someparserid', fs.createReadStream('filepath'), options)
  .then(function (result) {
    // => {"id":"document_id","file_size":198989,"quota_used":16,"quota_left":34,"quota_refill":"1970-01-01T00:00:00+00:00"}
  })
  .catch(function (err) {
    console.log(err)
  })

Fetch Document From An URL

Imports a document from a publicly available HTTP(S) URL.

client.fetchDocumentFromURL('someparserid', 'http://example.com/test.pdf', {remote_id: 'test'})
  .then(function (result) {
    // => {"id":"document_id","file_size":153914,"quota_used":17,"quota_left":33,"quota_refill":"1970-01-01T00:00:00+00:00"}
  })
  .catch(function (err) {
    console.log(err)
  })

Parsed Data

The Docparser API allows you to retrieve the extracted document data. You can either list the data of multiple documents or get the data of a specific document.

Both methods used for retrieving parsed data allow you to specify the "format" parameter - this allows you to choose between a flat structure and a nested array structure. For most implementations, leaving it as "object" will serve you fine.

Please note: Polling the API for new results is not the recommended way of obtaining your data. A much better way than polling our API for parsed data is to use Webhooks. By using webhooks, parsed data will be pushed to your API immediately after parsing.

Get Data Of One Document

Fetches the parsed data for a specific document by providing a parserId and the documentId. The documentId is the Docparser Document ID which is returned when importing a document through the API.

client.getResultsByDocument(parserId, documentId, {format: 'object'})
  .then(function (result) {
    console.log(result)
  })
  .catch(function (err) {
    console.log(err)
  })

Get Data Of Multiple Documents

Fetches the results of multiple documents parsed by a specific document parser. This function allows you granular filtering and ordering of the results. Please see our documentation for the list of available parameters.

client.getResultsByParser(parserId, {format: 'object'})
  .then(function (result) {
    console.log(result)
  })
  .catch(function (err) {
    console.log(err)
  })

Contributing

Bug reports and pull requests are welcome on GitHub.

Please follow Standard Code Style with your contributions. You can check for code style by running npm test when developing this library.

License

The library is available as open source under the terms of the MIT License.

The MIT License (MIT)

Copyright (c) 2016 DAUSINGER DIGITAL EURL.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Changelog

  • 11/16/2017 initial release