Bug:Fix file validation issue
[vnfsdk/refrepo.git] / vnfmarket / src / main / webapp / vnfmarket / node_modules / karma / lib / helper.js
1 var fs = require('fs')
2 var path = require('path')
3 var _ = require('lodash')
4 var useragent = require('useragent')
5
6 exports.browserFullNameToShort = function (fullName) {
7   var agent = useragent.parse(fullName)
8   return agent.toAgent() + ' (' + agent.os + ')'
9 }
10
11 exports.isDefined = function (value) {
12   return !_.isUndefined(value)
13 }
14
15 exports.isFunction = _.isFunction
16 exports.isString = _.isString
17 exports.isObject = _.isObject
18 exports.isArray = _.isArray
19
20 var ABS_URL = /^https?:\/\//
21 exports.isUrlAbsolute = function (url) {
22   return ABS_URL.test(url)
23 }
24
25 exports.camelToSnake = function (camelCase) {
26   return camelCase.replace(/[A-Z]/g, function (match, pos) {
27     return (pos > 0 ? '_' : '') + match.toLowerCase()
28   })
29 }
30
31 exports.ucFirst = function (word) {
32   return word.charAt(0).toUpperCase() + word.substr(1)
33 }
34
35 exports.dashToCamel = function (dash) {
36   var words = dash.split('-')
37   return words.shift() + words.map(exports.ucFirst).join('')
38 }
39
40 exports.arrayRemove = function (collection, item) {
41   var idx = collection.indexOf(item)
42
43   if (idx !== -1) {
44     collection.splice(idx, 1)
45     return true
46   }
47
48   return false
49 }
50
51 exports.merge = function () {
52   var args = Array.prototype.slice.call(arguments, 0)
53   args.unshift({})
54   return _.merge.apply({}, args)
55 }
56
57 exports.formatTimeInterval = function (time) {
58   var mins = Math.floor(time / 60000)
59   var secs = (time - mins * 60000) / 1000
60   var str = secs + (secs === 1 ? ' sec' : ' secs')
61
62   if (mins) {
63     str = mins + (mins === 1 ? ' min ' : ' mins ') + str
64   }
65
66   return str
67 }
68
69 var replaceWinPath = function (path) {
70   return exports.isDefined(path) ? path.replace(/\\/g, '/') : path
71 }
72
73 exports.normalizeWinPath = process.platform === 'win32' ? replaceWinPath : _.identity
74
75 exports.mkdirIfNotExists = function mkdir (directory, done) {
76   // TODO(vojta): handle if it's a file
77   /* eslint-disable handle-callback-err */
78   fs.stat(directory, function (err, stat) {
79     if (stat && stat.isDirectory()) {
80       done()
81     } else {
82       mkdir(path.dirname(directory), function () {
83         fs.mkdir(directory, done)
84       })
85     }
86   })
87   /* eslint-enable handle-callback-err */
88 }
89
90 // export lodash
91 exports._ = _