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

multic

v0.6.0

Published

converged linter, compiler and minifier API for multiple web sources: jade, html, less/sass/scss, css, coffee-script, es6/6to5/babel, javascript/es5, html2js

Downloads

4

Readme

Compile, Minify, Lint

multic attempts to fix the compilation, minification, linting inconsistancies by providing:

  • simple, consistent API
  • consistent error and warning level objects
  • sane defaults for errors and warnings
  • converged lint rules

Supported sources

Install for your app

cd /path/to/your/app
npm install multic --save

Usage

Pattern

var multic = require('multic');

// with promise
var promise = multic(source|path[, options])[.file].coffee|css|es6|html|jade|less|sass[.css|html|js][.min][.write]([target_file]);

// with callback function(err, res) {}
multic(source|path[, options])[.file].coffee|css|es6|html|jade|less|sass[.css|html|js][.min](callback);

// write to output file with callback
multic(source|path[, options])[.file].coffee|css|es6|html|jade|less|sass[.css|html|js][.min].write(target_file, callback);

Examples

JavaScript string minification

var promise = multic(script, {file: 'my/file/name.js'}).js.min();

Jade file->HTML compilation

var promise = multic('my/jade/file.jade').file.jade.html();

Compile LESS file to CSS + write to output file

var promise = multic('my/sass/file.scss').file.less.css.write('my/deployment/dist.css');

Compile SASS file to CSS + minify + write to output file

var promise = multic('my/sass/file.scss').file.sass.css.min.write('my/deployment/dist.min.css');

Lint only (syntax errors and warnings, no processing)

var promise = multic('my/js/file.js').file.js()

Promise response

var promise = multic('my/sass/file.scss').file.sass.css.min();
promise.then( function (res) {
  console.log('source:', res.source);
  console.log('compiled:', res.compiled);
  console.log('minified:', res.minified);
}, function (err) {
  console.error('error:', err);
  console.error('response object is also available:', err.res);
} );

Callback signiture

  • err: null or Error instance (same as the first item in res.errors)
  • res: response object

Response object properties

{
  source:   '#id1.class1\n  h1 Hello\n  include templates/_hi\n',
  compiled: '<div id='id1' class='class1'>\n  <h1>Hello</h1>\n  <h2>Hi</h2>\n</div>\n',
  minified: '<div id='id1' class='class1'> <h1>Hello</h1> <h2>Hi</h2></div>',
  includes: ['/home/johndoe/Projects/testapp/markup/templates/_hi.jade'],
  errors:   [],
  warnings: []
}
  • source: (string) source code (if loaded from file)
  • compiled: (string) compiled, unminified code (on compilation requests)
  • minified: (string) minified code (on minification requests)
  • includes: (Array) of *(string)*s included files (only used for Jade, Less and Sass files with includes/import)
  • errors: (Array) of (Error)-inherited objects
  • warnings: (Array) of (Error)-inherited objects

Consequent Errors and Warnings

Objects created using instances of object inherited from JavaScript-native Error class:

{
  title:   'Syntax Error',
  message: 'Unexpected <',
  file:    'src/test.coffee',
  line:    2,
  column:  6,
  sourceLines: {
    0: 'x = (a) ->',
    1: '  a + 1',
    2: '  x = <-',
    3: ''
  }
}

multic attempts to provide a unified interface for all errors and warnings. You get these properties on the errors/warnings:

  • message: (string) literal description of the error/warning
  • title: (string) short description of the error/warning
  • file: (string) file path of error
  • line: (number) indication of error/warning line (0-based index, i.e. first line is line 0)
  • column: (number) indication of error/warning column in line (0-based index, i.e. first column is column 0)
  • sourceLines: (number) a snippet of the source code around the error/warning. Keys are 0-based line numbers, values are the lines (without the \n character at the end). 11 lines (error/warning line + 5 previous + 5 following lines) or less (when the line is near the start or end of file).

WARNING! Although these properties are available most of the time, keep in mind that:

  • jade related errors and warnings usually will not have column property
  • file property is only added if
    • source is loaded from file, or
    • you have specified {file: '/my/file/name.ext'} as option with your source string (see below)
  • some exotic errors may not have anything but message (and file if source is loaded from file or you sp)

Options

file file path for source string

This is useful for error messages and to define include path start point for Jade, Less and Sass includes/imports

multic(source_string, {file: '*path/to/my/source/file.ext*'}).min(callback);

moduleName string for Angulat module generator (html.js and jade.js compilers)

Define Angular module name for your markup.

multic(source_string, {moduleName: 'name.space.joe'}).html.js(callback);

Configurable lint rules

See table of lint rules

multic(source_file_path, {
  max_line_length:  80,
  file_end_newline: false
  // ...
}).file.min(callback);

Turn off linting

Pass {lint: false} option explicitly to disable linting.

multic(source, {lint: false}).js.min(callback);

Utilized minifiers

Utilized external linters

Promises

Used library: promise

Coming soon (TODO)

  • Missing lint rule implementations and tests, added descriptions and links for rules
  • CLI