1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- export default class commonutil {
- //验证手机号
- static isPoneAvailable(str) {
- let myreg = /^[1][0-9]{10}$/;
- if (str.length == 0 || str == null) {
- return false;
- } else if (!myreg.test(str)) {
- return false;
- } else {
- return true;
- }
- }
- /**
- *map转化为对象(map所有键都是字符串,可以将其转换为对象)
- */
- static strMapToObj(strMap) {
- let obj = Object.create(null);
- for (let [ k, v ] of strMap) {
- obj[k] = v;
- }
- return obj;
- }
- /**
- *map转换为json
- */
- static mapToJson(map) {
- return JSON.stringify(this.strMapToObj(map));
- }
- /**
- *对象转换为Map
- */
- static objToStrMap(obj) {
- let strMap = new Map();
- for (let k of Object.keys(obj)) {
- strMap.set(k, obj[k]);
- }
- return strMap;
- }
- /**
- *json转换为map
- */
- static jsonToMap(jsonStr) {
- return this.objToStrMap(JSON.parse(jsonStr));
- }
- }
|