UNPKG

1.47 kBJavaScriptView Raw
1"use strict";
2
3/*!
4 * Utiltiy methods for the less middleware.
5 *
6 * Copyright(c) 2014 Randy Merrill <Zoramite+github@gmail.com>
7 * MIT Licensed
8 */
9
10var regex = {
11 compress: /(\.|-)min\.css$/,
12 handle: /\.css(\.map)?$/,
13 sourceMap: /\.css\.map$/
14};
15
16module.exports = {
17 isCompressedPath: function(pathname) {
18 return regex.compress.test(pathname);
19 },
20 isSourceMap: function( pathname ){
21 return regex.sourceMap.test(pathname);
22 },
23 isValidPath: function(pathname) {
24 return regex.handle.test(pathname);
25 },
26 lessError: function(err) {
27 // An error while less is processing the file.
28 module.exports.log('LESS ' + err.type + ' error', err.message, 'error');
29 module.exports.log('LESS File', err.filename + ' ' + err.line + ':' + err.column, 'error');
30 },
31 log: function(key, value, type) {
32 // Only log for errors.
33 if(type !== 'error') {
34 return;
35 }
36
37 console[type](" \u001b[90m%s :\u001b[0m \u001b[36m%s\u001b[0m", key, value);
38 },
39 logDebug: function(key, value, type) {
40 switch(type) {
41 case 'log':
42 case 'info':
43 case 'error':
44 case 'warn':
45 break;
46 default:
47 type = 'log';
48 }
49
50 console[type](" \u001b[90m%s :\u001b[0m \u001b[36m%s\u001b[0m", key, value);
51 },
52 maybeCompressedSource: function(pathname) {
53 return (regex.compress.test(pathname)
54 ? pathname.replace(regex.compress, '.less')
55 : pathname.replace('.css', '.less')
56 );
57 }
58};