uti

javascript implementation of a "Uniform Type Identifier" (UTI)

  • uti

Downloads in past

Stats

StarsIssuesVersionUpdatedCreatedSize
uti
418.2.12 months ago8 years agoMinified + gzip package size for uti in KB

Readme

npm License bundlejs downloads GitHub Issues Build Status Styled with prettier Commitizen friendly Known Vulnerabilities Coverage Status
uti

Uniform Type Identifier

Please see ars technica article for a description about the principles of UTIs.
For a list of known UTIs please see here
example

myuti.js


import { UTIController } from "uti";

const uc = new UTIController();
const doesConformTo = uc.conformsTo("public.image", "public.data");
console.log("doesConformTo: " + doesConformTo);

console.log(uc.getUTIsForFileName("a.txt")[0]);

Output
doesConformTo: true
public.plain-text
API

Table of Contents

*   [Parameters](#parameters)
*   [Properties](#properties)
*   [conformsTo](#conformsto)
    *   [Parameters](#parameters-1)
*   [toJSON](#tojson)
*   [Properties](#properties-1)
*   [register](#register)
    *   [Parameters](#parameters-2)
*   [getUTI](#getuti)
    *   [Parameters](#parameters-3)
*   [getUTIsForMimeType](#getutisformimetype)
    *   [Parameters](#parameters-4)
*   [getUTIsForFileName](#getutisforfilename)
    *   [Parameters](#parameters-5)
*   [conformsTo](#conformsto-1)
    *   [Parameters](#parameters-6)
*   [fileNameConformsTo](#filenameconformsto)
    *   [Parameters](#parameters-7)

UTI

Object representing a UTI.

Parameters

Properties

conformsTo

Check for conformity.

Parameters


Returns boolean true if other conforms to the receiver

toJSON

Deliver JSON representation of the UTI. Sample result
{
  "name": "myUTI",
  "conformsTo": [ "uti1", "uti2"]
}

Returns
Object json representation of the UTI

UTIController

Registry of UTIs.

Properties

Map<string, UTI>
  • utiByFileNameExtension
  • Map<string, UTI>

    register

    Registers additional types.

    Parameters

    getUTI

    Lookup a given UTI.

    Parameters


    Returns string UTI for the given name or undefined if UTI is not present.

    getUTIsForMimeType

    Lookup a UTIs for a mime type.

    Parameters

    • mimeType string mime type to get UTIs for

    Returns
    string UTI for the given mime type or undefined if no UTI is registerd for the mime type

    getUTIsForFileName

    Lookup a UTI for a file name. First the file name extension is extracted. Then a lookup in the reistered UTIs for file name extions is executed.

    Parameters

    • fileName string file to detect UTI for

    Returns
    Array<string> UTI for the given fileName or undefined if no UTI is registerd for the file names extension

    conformsTo

    Check whenever two UTI are conformant. If a conforms to b and b conforms to c then a also conforms to c.

    Parameters

    string second UTI
    Returns boolean true if UTI a conforms to UTI b.

    fileNameConformsTo

    Lookup a UTI for a file name and check conformance.

    Parameters

    • fileName string file to detect UTI for
    • uti
    string to check conformance against
    Returns boolean ture if utils for file name are conformant
    install
    With npm
    do:
    npm install uti
    license
    BSD-2-Clause