UNPKG

mecano

Version:

Common functions for system deployment.

53 lines (48 loc) 1.63 kB
// Generated by CoffeeScript 1.9.1 var crypto; crypto = require('crypto'); module.exports = { escapeshellarg: function(arg) { var result; result = arg.replace(/[^\\]'/g, function(match) { return match.slice(0, 1) + '\\\''; }); return "'" + result + "'"; }, /* `string.hash(file, [algorithm], callback)` ------------------------------------------ Output the hash of a supplied string in hexadecimal form. The default algorithm to compute the hash is md5. */ hash: function(data, algorithm) { if (arguments.length === 1) { algorithm = 'md5'; } return crypto.createHash(algorithm).update(data).digest('hex'); }, repeat: function(str, l) { return Array(l + 1).join(str); }, /* `string.endsWith(search, [position])` ------------------------------------- Determines whether a string ends with the characters of another string, returning true or false as appropriate. This method has been added to the ECMAScript 6 specification and its code was borrowed from [Mozilla](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/endsWith) */ endsWith: function(str, search, position) { var lastIndex; position = position || str.length; position = position - search.length; lastIndex = str.lastIndexOf(search); return lastIndex !== -1 && lastIndex === position; }, lines: function(str) { return str.split(/\r\n|[\n\r\u0085\u2028\u2029]/g); }, underscore: function(str) { return trim(str).replace(/([a-z\d])([A-Z]+)/g, '$1_$2').replace(/[-\s]+/g, '_').toLowerCase(); } };