Skip to content

Commit

Permalink
Version_0.1.7-test2
Browse files Browse the repository at this point in the history
  • Loading branch information
censujiang committed May 27, 2023
1 parent edaef43 commit 37e21a8
Show file tree
Hide file tree
Showing 10 changed files with 170 additions and 28 deletions.
79 changes: 57 additions & 22 deletions dist/index.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/*!
* @uni-helper/galanga 0.1.7-test1 (https://github.com/uni-helper/galanga)
* @uni-helper/galanga 0.1.7-test2 (https://github.com/uni-helper/galanga)
* API https://galanga.censujiang.com/api/
* Copyright 2014-2023 censujiang. All Rights Reserved
* Licensed under Apache License 2.0 (https://github.com/uni-helper/galanga/blob/master/LICENSE)
*/

//操作cookie的方法
const localCookie = {
const localCookie$1 = {
getItem: function (sKey) {
return decodeURIComponent(document.cookie.replace(new RegExp('(?:(?:^|.*;)\\s*' + encodeURIComponent(sKey).replace(/[-.+*]/g, '\\$&') + '\\s*\\=\\s*([^;]*).*$)|^.*$'), '$1')) || null;
},
Expand Down Expand Up @@ -61,26 +61,6 @@ const localCookie = {
}
};

const url = {
getQuery(name) {
const result = window.location.search.match(new RegExp('[?&]' + name + '=([^&]+)', 'i'));
if (result == null || result.length < 1) {
return '';
}
return result[1];
},
getHash(name) {
const result = window.location.hash.match(new RegExp('[#&]' + name + '=([^&]+)', 'i'));
if (result == null || result.length < 1) {
return '';
}
return result[1];
},
getPath() {
return window.location.pathname;
},
};

// 检查输入的值是否为空
function checkNull(val) {
if (val === null || val === undefined || val === '' || typeof val === 'number' && isNaN(val)) {
Expand Down Expand Up @@ -504,6 +484,61 @@ function formatNumber(value, decimal = 2) {
return (Math.floor(value * decimalValue) / decimalValue).toString();
}

const localCookie = {
getItem: (sKey) => {
let result = null;
// #ifdef H5
result = localCookie$1.getItem(sKey);
// #endif
return result;
},
setItem: (sKey, sValue, vEnd, sPath, sDomain, bSecure) => {
// #ifdef H5
localCookie$1.setItem(sKey, sValue, vEnd, sPath, sDomain, bSecure);
// #endif
},
removeItem: (sKey, sPath, sDomain) => {
// #ifdef H5
localCookie$1.removeItem(sKey, sPath, sDomain);
// #endif
},
hasItem: (sKey) => {
let result = false;
// #ifdef H5
result = localCookie$1.hasItem(sKey);
// #endif
return result;
},
keys: () => {
let result = [];
// #ifdef H5
result = localCookie$1.keys();
// #endif
return result;
},
clear: () => {
// #ifdef H5
localCookie$1.clear();
// #endif
}
};

const url = {
getPath: () => {
const uniRouter = getCurrentPages();
const currentRoute = uniRouter[uniRouter.length - 1];
return '/' + currentRoute.route;
},
getQuery: (value) => {
const uniRouter = getCurrentPages();
const currentRoute = uniRouter[uniRouter.length - 1];
return currentRoute.$page.options[value];
},
getHash: () => {
return undefined;
}
};

const clipboard = {
read: async (onlyString = true) => {
let result;
Expand Down
39 changes: 39 additions & 0 deletions esm/cookie.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import * as origin from 'galanga';
export const localCookie = {
getItem: (sKey) => {
let result = null;
// #ifdef H5
result = origin.localCookie.getItem(sKey);
// #endif
return result;
},
setItem: (sKey, sValue, vEnd, sPath, sDomain, bSecure) => {
// #ifdef H5
origin.localCookie.setItem(sKey, sValue, vEnd, sPath, sDomain, bSecure);
// #endif
},
removeItem: (sKey, sPath, sDomain) => {
// #ifdef H5
origin.localCookie.removeItem(sKey, sPath, sDomain);
// #endif
},
hasItem: (sKey) => {
let result = false;
// #ifdef H5
result = origin.localCookie.hasItem(sKey);
// #endif
return result;
},
keys: () => {
let result = [];
// #ifdef H5
result = origin.localCookie.keys();
// #endif
return result;
},
clear: () => {
// #ifdef H5
origin.localCookie.clear();
// #endif
}
};
4 changes: 2 additions & 2 deletions esm/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ export const info = {
//version: packageJson.version,
};
//引入并导出所有原有的子模块
export { localCookie } from 'galanga';
export { url } from 'galanga';
export { checkNull, checkNotNull, strLength, formatBytes, checkPassword, checkEmail } from 'galanga';
export { updateObjectFromImport } from 'galanga';
export { filterUniqueByProperty } from 'galanga';
export { formatNumber } from 'galanga';
//导出自己的子模块
export { localCookie } from './cookie';
export { url } from './url';
export { checkDeviceType, clipboard } from './device';
export { notificationPermission, clipboardPermission, locationPermission } from './permission';
15 changes: 15 additions & 0 deletions esm/url.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
export const url = {
getPath: () => {
const uniRouter = getCurrentPages();
const currentRoute = uniRouter[uniRouter.length - 1];
return '/' + currentRoute.route;
},
getQuery: (value) => {
const uniRouter = getCurrentPages();
const currentRoute = uniRouter[uniRouter.length - 1];
return currentRoute.$page.options[value];
},
getHash: () => {
return undefined;
}
};
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@uni-helper/galanga",
"version": "0.1.7-test1",
"version": "0.1.7-test2",
"description": "JS common function library(UNI-APP version of Galanga)",
"main": "esm/index.js",
"jsnext:main": "esm/index.js",
Expand Down
40 changes: 40 additions & 0 deletions src/cookie.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import * as origin from 'galanga';

export const localCookie = {
getItem:(sKey:string) => {
let result = null;
// #ifdef H5
result = origin.localCookie.getItem(sKey);
// #endif
return result;
},
setItem:(sKey:string, sValue:string, vEnd?:number | string | Date, sPath?:string, sDomain?:string, bSecure?:boolean) => {
// #ifdef H5
origin.localCookie.setItem(sKey, sValue, vEnd, sPath, sDomain, bSecure);
// #endif
},
removeItem:(sKey:string, sPath?:string, sDomain?:string) => {
// #ifdef H5
origin.localCookie.removeItem(sKey, sPath, sDomain);
// #endif
},
hasItem:(sKey:string) => {
let result = false;
// #ifdef H5
result = origin.localCookie.hasItem(sKey);
// #endif
return result;
},
keys:() => {
let result = [];
// #ifdef H5
result = origin.localCookie.keys();
// #endif
return result;
},
clear:() => {
// #ifdef H5
origin.localCookie.clear();
// #endif
}
}
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ export const info = {
}

//引入并导出所有原有的子模块
export { localCookie } from 'galanga';
export { checkNull, checkNotNull, strLength, formatBytes, checkPassword, checkEmail } from 'galanga';
export { updateObjectFromImport } from 'galanga';
export { filterUniqueByProperty } from 'galanga';
export { formatNumber } from 'galanga';

//导出自己的子模块
export { localCookie } from './cookie';
export { url } from './url';
export { checkDeviceType, clipboard } from './device';
export { notificationPermission, clipboardPermission, locationPermission } from './permission';
8 changes: 8 additions & 0 deletions types/cookie.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export declare const localCookie: {
getItem: (sKey: string) => any;
setItem: (sKey: string, sValue: string, vEnd?: number | string | Date, sPath?: string, sDomain?: string, bSecure?: boolean) => void;
removeItem: (sKey: string, sPath?: string, sDomain?: string) => void;
hasItem: (sKey: string) => boolean;
keys: () => any[];
clear: () => void;
};
4 changes: 2 additions & 2 deletions types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ export declare const info: {
author: string;
type: string;
};
export { localCookie } from 'galanga';
export { url } from 'galanga';
export { checkNull, checkNotNull, strLength, formatBytes, checkPassword, checkEmail } from 'galanga';
export { updateObjectFromImport } from 'galanga';
export { filterUniqueByProperty } from 'galanga';
export { formatNumber } from 'galanga';
export { localCookie } from './cookie';
export { url } from './url';
export { checkDeviceType, clipboard } from './device';
export { notificationPermission, clipboardPermission, locationPermission } from './permission';
5 changes: 5 additions & 0 deletions types/url.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export declare const url: {
getPath: () => string;
getQuery: (value: string) => any;
getHash: () => any;
};

0 comments on commit 37e21a8

Please sign in to comment.