UNPKG

1.34 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$/
13};
14
15module.exports = {
16 isCompressedPath: function(pathname) {
17 return regex.compress.test(pathname);
18 },
19 isValidPath: function(pathname) {
20 return regex.handle.test(pathname);
21 },
22 lessError: function(err) {
23 // An error while less is processing the file.
24 module.exports.log('LESS ' + err.type + ' error', err.message, 'error');
25 module.exports.log('LESS File', err.filename + ' ' + err.line + ':' + err.column, 'error');
26 },
27 log: function(key, value, type) {
28 // Only log for errors.
29 if(type !== 'error') {
30 return;
31 }
32
33 console[type](" \u001b[90m%s :\u001b[0m \u001b[36m%s\u001b[0m", key, value);
34 },
35 logDebug: function(key, value, type) {
36 switch(type) {
37 case 'log':
38 case 'info':
39 case 'error':
40 case 'warn':
41 break;
42 default:
43 type = 'log';
44 }
45
46 console[type](" \u001b[90m%s :\u001b[0m \u001b[36m%s\u001b[0m", key, value);
47 },
48 maybeCompressedSource: function(pathname) {
49 return (regex.compress.test(pathname)
50 ? pathname.replace(regex.compress, '.less')
51 : pathname.replace('.css', '.less')
52 );
53 }
54};