JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 2184
  • Score
    100M100P100Q96457F
  • License MIT

XML detection plugin for file-type

Package Exports

  • @file-type/xml

Readme

NPM version Node.js CI npm downloads

@file-type/xml

Detector plugin for file-type for XML files.

Installation

npm install @file-type/xml

Usage

The following example shows how add the XML detector to file-type.

import {NodeFileTypeParser} from 'file-type';
import {detectXml} from '@file-type/xml';

const parser = new FileTypeParser({customDetectors: [detectXml]});
const fileType = await parser.fromFile('example.kml');
console.log(fileType);

You can also use the XML detector outside file-type:

import {XmlTextDetector} from '@file-type/xml';

const xmlTextDetector = new XmlTextDetector();
xmlTextDetector.write('<svg xmlns="http://www.w3.org/2000/svg"><path fill="#00CD9F"/></svg>');
const fileType = xmlTextDetector.fileType;
console.log(JSON.stringify(fileType)); // Outputs: {"ext":"svg","mime":"image/svg+xml"}

Support file formats