Giter Club home page Giter Club logo

lang-map's Introduction

lang-map NPM version

Get the language associated with a file extension or the extensions associated with a language using the data from GitHub's Linguist YAML file

Heads up! API Changes in 0.4.0

The API changed in v0.4.0. Please see the documentation below for details on the new API. Don't hesitate to create an issue if you have any questions.

Install

Install with npm

$ npm i lang-map --save

Usage

var map = require('lang-map');

Get language by extension

Returns the language that is associated with the given file extension (with or without .):

var map = require('lang-map');

map.languages('coffee');
//=> [ 'coffeescript' ]
map.languages('handlebars');
//=> [ 'handlebars' ]
map.languages('hbs');
//=> [ 'handlebars' ]
map.languages('javascript');
//=> [ 'javascript' ]
map.languages('js');
//=> [ 'javascript' ]
map.languages('md');
//=> [ 'markdown' ]
map.languages('mkdown');
//=> [ 'markdown' ]

Why is an array of languages returned?

In some (rare) cases an extension maps to multiple languages.

map.languages('h');
//=> [ 'c', 'c++', 'objective-c' ]

Get extensions by language

Returns the list of file extensions associated with the given language:

var map = require('lang-map');

map.extensions('coffee');
//=> [ 'coffee', '_coffee', 'cjsx', 'cson', 'iced' ]
map.extensions('hbs');
//=> [ 'handlebars', 'hbs' ]
map.extensions('markdown');
//=> [ 'md', 'markdown', 'mkd', 'mkdn', 'mkdown', 'ron' ]
map.extensions('md');
//=> [ 'md', 'markdown', 'mkd', 'mkdn', 'mkdown', 'ron' ]
map.extensions('c');
//=> [ 'c', 'cats', 'h', 'idc', 'w' ]

Get the object of entensions

var map = require('lang-map');
var extensions = map().extensions;

Get the object of languages

var map = require('lang-map');
var languages = map().languages;

Related projects

language-map: GitHub's Linguist YAML language map provided as JSON

Updating languages

Update the .json language files in lib/.

$ npm run update

Running tests

Install dev dependencies:

$ npm i -d && npm test

Contributing

Pull requests and stars are always welcome. For bugs and feature requests, please create an issue

Author

Jon Schlinkert

License

Copyright © 2015 Jon Schlinkert Released under the MIT license.


This file was generated by verb-cli on August 18, 2015.

lang-map's People

Contributors

jonschlinkert avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.