mirror of https://github.com/requarks/wiki
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
67 lines
1.6 KiB
67 lines
1.6 KiB
7 years ago
|
import filesize from 'filesize.js'
|
||
7 years ago
|
import _ from 'lodash'
|
||
8 years ago
|
|
||
7 years ago
|
/* global siteConfig */
|
||
|
|
||
8 years ago
|
const helpers = {
|
||
7 years ago
|
/**
|
||
|
* Convert bytes to humanized form
|
||
|
* @param {number} rawSize Size in bytes
|
||
|
* @returns {string} Humanized file size
|
||
|
*/
|
||
|
filesize (rawSize) {
|
||
|
return _.toUpper(filesize(rawSize))
|
||
|
},
|
||
|
/**
|
||
|
* Convert raw path to safe path
|
||
|
* @param {string} rawPath Raw path
|
||
|
* @returns {string} Safe path
|
||
|
*/
|
||
|
makeSafePath (rawPath) {
|
||
|
let rawParts = _.split(_.trim(rawPath), '/')
|
||
|
rawParts = _.map(rawParts, (r) => {
|
||
|
return _.kebabCase(_.deburr(_.trim(r)))
|
||
|
})
|
||
|
|
||
|
return _.join(_.filter(rawParts, (r) => { return !_.isEmpty(r) }), '/')
|
||
|
},
|
||
|
resolvePath (path) {
|
||
|
if (_.startsWith(path, '/')) { path = path.substring(1) }
|
||
|
return `${siteConfig.path}${path}`
|
||
|
},
|
||
|
/**
|
||
|
* Set Input Selection
|
||
|
* @param {DOMElement} input The input element
|
||
|
* @param {number} startPos The starting position
|
||
|
* @param {nunber} endPos The ending position
|
||
|
*/
|
||
|
setInputSelection (input, startPos, endPos) {
|
||
|
input.focus()
|
||
|
if (typeof input.selectionStart !== 'undefined') {
|
||
|
input.selectionStart = startPos
|
||
|
input.selectionEnd = endPos
|
||
|
} else if (document.selection && document.selection.createRange) {
|
||
|
// IE branch
|
||
|
input.select()
|
||
|
var range = document.selection.createRange()
|
||
|
range.collapse(true)
|
||
|
range.moveEnd('character', endPos)
|
||
|
range.moveStart('character', startPos)
|
||
|
range.select()
|
||
|
}
|
||
|
}
|
||
8 years ago
|
}
|
||
|
|
||
8 years ago
|
export default {
|
||
8 years ago
|
install(Vue) {
|
||
|
Vue.$helpers = helpers
|
||
|
Object.defineProperties(Vue.prototype, {
|
||
|
$helpers: {
|
||
|
get() {
|
||
|
return helpers
|
||
|
}
|
||
|
}
|
||
|
})
|
||
8 years ago
|
}
|
||
|
}
|