1
0
mirror of synced 2025-12-08 14:54:02 +08:00

Move some utils to fione

This commit is contained in:
redhoodsu
2018-09-06 18:12:44 +08:00
parent 130acc5008
commit 72d1269c51
12 changed files with 827 additions and 925 deletions

26
.eustia.js Normal file
View 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
View File

@@ -2,6 +2,7 @@
node_modules/
test/lib/
coverage/
eustia/cache/
test/playground.html
eruda.js
!/test/eruda.js

View File

@@ -12,6 +12,7 @@ doc/
.gitignore
.npmignore
.prettierignore
.eustia.js
.travis.yml
CHANGELOG.md
prettier.config.js

View File

@@ -1,10 +0,0 @@
/* Escape json string.
*/
_('escapeJsStr')
function exports(str) {
return escapeJsStr(str)
.replace(/\\'/g, "'")
.replace(/\t/g, '\\t')
}

View File

@@ -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
)
}

View File

@@ -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
}

View File

@@ -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, ''))
}

View File

@@ -1,10 +0,0 @@
/* Check if a url is cross origin.
*/
_('startWith')
let origin = window.location.origin
function exports(url) {
return !startWith(url, origin)
}

View File

@@ -1,8 +0,0 @@
/* Turn string like '0px' to number.
*/
_('toNum')
function exports(str) {
return toNum(str.replace('px', ''))
}

View File

@@ -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
}

View File

@@ -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"

View File

@@ -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 (