adjustment

This commit is contained in:
2023-07-27 10:03:53 +08:00
parent 3e9ee59178
commit 29209a3a00
17 changed files with 456 additions and 173 deletions

View File

@ -1,4 +1,4 @@
function setCookie(name, value, expireDays) {
export function setCookie(name, value, expireDays) {
if (name == null) {
return;
}
@ -14,7 +14,7 @@ function setCookie(name, value, expireDays) {
document.cookie = `${name}=${encodeURIComponent(value)}${extra}`;
}
function getCookie(name) {
export function getCookie(name) {
if (name == null) {
return null;
}
@ -29,12 +29,6 @@ function getCookie(name) {
return null;
}
function deleteCookie(name) {
export function deleteCookie(name) {
setCookie(name, '', -1);
}
export {
getCookie,
setCookie,
deleteCookie
}

View File

@ -98,7 +98,7 @@ function applyLanguage(dom, result) {
}
}
async function init(dom = document.body, options = {}) {
export async function init(dom = document.body, options = {}) {
const lgid = getCurrentLgId();
let lgres = localStorage.getItem(getStorageKey(lgid));
let result;
@ -139,14 +139,14 @@ async function init(dom = document.body, options = {}) {
}
}
function r(key, defaultValue) {
export function r(key, defaultValue) {
if (cache != null) {
return getLanguage(cache, key, defaultValue);
}
return defaultValue;
}
const lang = {
export const lang = {
get current() {
return getCurrentLgId();
},
@ -156,10 +156,4 @@ const lang = {
get savedSuccessfully() {
return r('savedSuccessfully', 'Saved successfully.');
}
}
export {
init,
r,
lang
}

View File

@ -8,7 +8,7 @@ function combineUrl(url) {
return (consts.path || '') + url;
}
function get(url, options = {}) {
export function get(url, options = {}) {
return fetch(combineUrl(url), {
method: options.method || 'GET',
headers: {
@ -21,7 +21,7 @@ function get(url, options = {}) {
});
}
function post(url, data, options = {}) {
export function post(url, data, options = {}) {
// let contentType;
if (data instanceof FormData) {
// contentType = 'multipart/form-data';
@ -46,7 +46,7 @@ function post(url, data, options = {}) {
});
}
function upload(url, data, options = {}) {
export function upload(url, data, options = {}) {
return new Promise((resolve, reject) => {
const request = new XMLHttpRequest();
request.onreadystatechange = function () {
@ -73,10 +73,4 @@ function upload(url, data, options = {}) {
}
request.send(data);
});
}
export {
get,
post,
upload
}

View File

@ -1,8 +1,8 @@
function nullOrEmpty(s) {
export function nullOrEmpty(s) {
return s == null || typeof s !== 'string' || s.length === 0;
}
function contains(s, key, ignoreCase) {
export function contains(s, key, ignoreCase) {
if (nullOrEmpty(s) || key == null) {
return false;
}
@ -15,21 +15,21 @@ function contains(s, key, ignoreCase) {
return s.indexOf(key) >= 0;
}
function endsWith(s, suffix) {
export function endsWith(s, suffix) {
if (nullOrEmpty(s) || nullOrEmpty(suffix)) {
return false;
}
return s.indexOf(suffix) === s.length - suffix.length;
}
function padStart(s, num, char) {
export function padStart(s, num, char) {
if (nullOrEmpty(s) || isNaN(num) || num <= s.length) {
return s;
}
return (char ?? ' ').repeat(num - s.length);
}
function formatUrl(msg) {
export function formatUrl(msg) {
//const urlReg = /(https?:\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*\/?/ig;
//const urlArrray = str.match(urlReg);
const p = /(http|ftp|https):\/\/.+?(\s|\r\n|\r|\n|\"|\'|\*|$)/g;
@ -53,7 +53,7 @@ function formatUrl(msg) {
return msg;
}
function escapeHtml(text) {
export function escapeHtml(text) {
if (text == null) {
return '';
}
@ -64,13 +64,4 @@ function escapeHtml(text) {
.replaceAll('\r\n', '<br/>')
.replaceAll('\n', '<br/>')
.replaceAll(' ', '&nbsp;');
}
export {
nullOrEmpty,
contains,
endsWith,
padStart,
formatUrl,
escapeHtml
}