mime-info-stream-parser
Convert freedesktop mime info XML to a JSON dictionary.
Last updated 8 days ago by efcmeg .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install mime-info-stream-parser 
SYNC missed versions from official npm registry.

mime-info-stream-parser

Npm Version Build Status Coverage Status

Convert freedesktop mime info XML to a simple JSON dictionary.

The freedesktop project provides an XML spec and 700+ mime type descriptions.

The parser implements a transform stream using sax js internally, converting freedesktop mime info XML to a JSON stream. Written to file, the output can be used:

// tsconfig.json compilerOptions.resolveJsonModule = true
import db from './db.json';

console.log(db['text/plain']);
/*
{
    comment: 'plain text document',
}
*/
console.log(db['application/pdf']);
/*
{
    comment: 'PDF document',
    acronym: 'PDF',
    acronymExpanded: 'Portable Document Format'
}
*/
// PDF alias
console.log(db['image/pdf']);
/*
{
    comment: 'PDF document',
    acronym: 'PDF',
    acronymExpanded: 'Portable Document Format'
}
*/

Mime type aliases are expanded to full entries. Each entry value is of type:

export interface MimeInfoItem {
  comment: string;
  acronym?: string;
  acronymExpanded?: string;
}
import { MimeInfoItem } from 'mime-info-stream-parser';

Usage

yarn add mime-info-stream-parser

Typescript

import { pipeline } from 'stream';
import { createWriteStream, createReadStream } from 'fs';
import { MimeInfoStreamParser } from 'mime-info-stream-parser';

const read = createReadStream('./freedesktop.org.xml.in', {
  encoding: 'utf-8',
});
const write = createWriteStream('./db.json', {
  encoding: 'utf-8',
});

const mimeInfo = new MimeInfoStreamParser();

pipeline(read, mimeInfo, write, (err) => {
  if (err) {
    console.error(err.message);
  }
});

Node.js

const { MimeInfoStreamParser } = require('mime-info-stream-parser');
// ...

Development

$ yarn && yarn test
$ yarn describe
info:
  Display information about the package scripts
build:
  Clean and rebuild the project
fix:
  Try to automatically fix any linting problems
test:
  Lint and unit test the project
watch:
  Watch and rebuild the project on save, then rerun relevant tests
cov:
  Rebuild, run tests, then create and open the coverage report
reset:
  Delete all untracked files and reset the repo to the last commit

License

MIT

Current Tags

  • 0.3.1                                ...           latest (8 days ago)

9 Versions

  • 0.3.1                                ...           8 days ago
  • 0.3.0                                ...           9 days ago
  • 0.2.1                                ...           10 days ago
  • 0.2.0                                ...           10 days ago
  • 0.1.7                                ...           11 days ago
  • 0.1.6                                ...           11 days ago
  • 0.1.5                                ...           12 days ago
  • 0.1.3                                ...           13 days ago
  • 0.1.1                                ...           13 days ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 13
Last Month 95
Dependencies (2)
Dependents (0)
None

Copyright 2014 - 2016 © taobao.org |