Move some utils to fione
This commit is contained in:
26
.eustia.js
Normal file
26
.eustia.js
Normal file
@@ -0,0 +1,26 @@
|
||||
module.exports = {
|
||||
script: {
|
||||
files: 'script/*.js',
|
||||
output: 'script/util.js',
|
||||
format: 'commonjs'
|
||||
},
|
||||
eruda: {
|
||||
library: 'https://raw.githubusercontent.com/liriliri/fione/master/',
|
||||
files: 'src/**/*.js',
|
||||
ignore: 'src/**/stringify.js',
|
||||
output: 'src/lib/util.js',
|
||||
exclude: ['createCfg'],
|
||||
format: 'es'
|
||||
},
|
||||
stringify: {
|
||||
files: 'src/lib/stringify.js',
|
||||
output: 'src/lib/stringifyUtil.js',
|
||||
format: 'es'
|
||||
},
|
||||
test: {
|
||||
files: ['test/*.js', 'test/*.html'],
|
||||
exclude: ['js'],
|
||||
namespace: 'util',
|
||||
output: 'test/util.js'
|
||||
}
|
||||
}
|
||||
1
.gitignore
vendored
1
.gitignore
vendored
@@ -2,6 +2,7 @@
|
||||
node_modules/
|
||||
test/lib/
|
||||
coverage/
|
||||
eustia/cache/
|
||||
test/playground.html
|
||||
eruda.js
|
||||
!/test/eruda.js
|
||||
|
||||
@@ -12,6 +12,7 @@ doc/
|
||||
.gitignore
|
||||
.npmignore
|
||||
.prettierignore
|
||||
.eustia.js
|
||||
.travis.yml
|
||||
CHANGELOG.md
|
||||
prettier.config.js
|
||||
|
||||
@@ -1,10 +0,0 @@
|
||||
/* Escape json string.
|
||||
*/
|
||||
|
||||
_('escapeJsStr')
|
||||
|
||||
function exports(str) {
|
||||
return escapeJsStr(str)
|
||||
.replace(/\\'/g, "'")
|
||||
.replace(/\t/g, '\\t')
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
/* Add origin to url if needed.
|
||||
*/
|
||||
|
||||
let link = document.createElement('a')
|
||||
|
||||
function exports(href) {
|
||||
link.href = href
|
||||
|
||||
return (
|
||||
link.protocol + '//' + link.host + link.pathname + link.search + link.hash
|
||||
)
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
/* Extract file name from url.
|
||||
*/
|
||||
|
||||
_('last trim')
|
||||
|
||||
function exports(url) {
|
||||
let ret = last(url.split('/'))
|
||||
|
||||
if (ret.indexOf('?') > -1) ret = trim(ret.split('?')[0])
|
||||
|
||||
return ret === '' ? 'unknown' : ret
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
/* Get object type.
|
||||
*/
|
||||
|
||||
_('upperFirst')
|
||||
|
||||
function exports(obj) {
|
||||
if (obj.constructor && obj.constructor.name) return obj.constructor.name
|
||||
|
||||
return upperFirst({}.toString.call(obj).replace(/(\[object )|]/g, ''))
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
/* Check if a url is cross origin.
|
||||
*/
|
||||
|
||||
_('startWith')
|
||||
|
||||
let origin = window.location.origin
|
||||
|
||||
function exports(url) {
|
||||
return !startWith(url, origin)
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
/* Turn string like '0px' to number.
|
||||
*/
|
||||
|
||||
_('toNum')
|
||||
|
||||
function exports(str) {
|
||||
return toNum(str.replace('px', ''))
|
||||
}
|
||||
@@ -1,33 +0,0 @@
|
||||
/* Safe localStorage and sessionStorage.
|
||||
*/
|
||||
|
||||
_('isUndef memStorage')
|
||||
|
||||
function exports(type, memReplacement) {
|
||||
if (isUndef(memReplacement)) memReplacement = true
|
||||
|
||||
let ret
|
||||
|
||||
switch (type) {
|
||||
case 'local':
|
||||
ret = window.localStorage
|
||||
break
|
||||
case 'session':
|
||||
ret = window.sessionStorage
|
||||
break
|
||||
}
|
||||
|
||||
try {
|
||||
// Safari private browsing
|
||||
let x = 'test-localStorage-' + Date.now()
|
||||
ret.setItem(x, x)
|
||||
let y = ret.getItem(x)
|
||||
ret.removeItem(x)
|
||||
if (y !== x) throw new Error()
|
||||
} catch (e) {
|
||||
if (memReplacement) return memStorage
|
||||
return
|
||||
}
|
||||
|
||||
return ret
|
||||
}
|
||||
32
package.json
32
package.json
@@ -21,38 +21,6 @@
|
||||
"pre-commit": "npm run ci"
|
||||
}
|
||||
},
|
||||
"eustia": {
|
||||
"script": {
|
||||
"files": "script/*.js",
|
||||
"output": "script/util.js",
|
||||
"format": "commonjs"
|
||||
},
|
||||
"eruda": {
|
||||
"files": "src/**/*.js",
|
||||
"ignore": "src/**/stringify.js",
|
||||
"output": "src/lib/util.js",
|
||||
"exclude": [
|
||||
"createCfg"
|
||||
],
|
||||
"format": "es"
|
||||
},
|
||||
"stringify": {
|
||||
"files": "src/lib/stringify.js",
|
||||
"output": "src/lib/stringifyUtil.js",
|
||||
"format": "es"
|
||||
},
|
||||
"test": {
|
||||
"files": [
|
||||
"test/*.js",
|
||||
"test/*.html"
|
||||
],
|
||||
"exclude": [
|
||||
"js"
|
||||
],
|
||||
"namespace": "util",
|
||||
"output": "test/util.js"
|
||||
}
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/liriliri/eruda.git"
|
||||
|
||||
@@ -1337,8 +1337,9 @@ export var fullUrl = _.fullUrl = (function () {
|
||||
/* Add origin to url if needed.
|
||||
*/
|
||||
|
||||
function exports(href) {
|
||||
let link = document.createElement('a')
|
||||
|
||||
function exports(href) {
|
||||
link.href = href
|
||||
|
||||
return (
|
||||
|
||||
Reference in New Issue
Block a user