Comments (1)
id2url(id, version) {
if (!version) version = 1;
if (typeof id === 'string' && id.length === 24) {
return id;
}
if (id instanceof Array) {
for (let i = 0; i < id.length; i++) {
const value = id[i];
id[i] = this.id2url(value);
}
return id;
} else if (parseInt(id, 10) > 0) {
let url;
switch (version) {
case 1:
url = version + parseInt(`${id * 2 + 56}`, 10 | 0).toString(36 | 0);
break;
default:
url = false;
break;
}
return url;
}
return id;
}
url2id(url, check) {
if (!check) check = false;
if (url.length === 24 && url.match(/^[0-9a-f]+$/)) return url; //兼容MongoId
if (url instanceof Array) {
for (var i = 0; i < url.length; i++) {
var value = url[i];
url[i] = this.url2id(value);
}
return url;
}
else if (url.indexOf(',') > 0) {
url = url.split(',');
for (var i = 0; i < url.length; i++) {
var value = url[i];
if (!value) {
delete url[i];
continue;
}
url[i] = this.url2id(value);
}
return url.join(',');
}
else {
if (check && url.match(/^(null|undefined)$/i)) {
return false;
}
const version = parseInt(url.substr(0, 1));
let id = 0;
switch (version) {
case 1:
//id = (parseInt(base_convert(url.substr(1), 36, 10)) - 56) / 2;
id = (parseInt(
parseInt(url.substr(1) + '', 36 | 0).toString(10 | 0)) - 56) / 2;
break;
case 2: //防止扫用户;
case 3:
case 4:
case 5:
case 6:
case 7:
case 8:
case 9:
id = 0;
break;
default:
id = url;
break;
}
return 0 < id ? parseInt(id) : 0;
}
}
from blog.
Related Issues (20)
- 《JavaScript高级程序设计(第3版)》学习笔记——十七、高级技巧 HOT 3
- 《JavaScript高级程序设计(第3版)》学习笔记——十八、离线应用与客户端存储
- 《JavaScript高级程序设计(第3版)》学习笔记——十九、最佳实践
- 几个奇怪的 CSS 问题 HOT 2
- 《JavaScript高级程序设计(第3版)》学习笔记——二十、新兴的 API
- 用 js 获取网页的各种位置和尺寸
- height:auto 与 transition
- 乱码一通
- 编程字体收集
- http、http1.0、http1.1、https、spdy、http2.0 浅对比总结
- zc
- 事件冒泡与捕获依赖的是什么?
- “慢一点”
- 一段有意思的代码
- #Daily Record# 2020年10月 - 第4周
- #Daily Record# 2020年11月 - 第1周
- #Daily Record# 2020年11月 - 第2周
- #Daily Record# 2020年11月 - 第3周
- #Daily Record# 2020年11月 - 第4周
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from blog.