Last active
May 14, 2018 07:55
-
-
Save junjie-xyz/b9489bc40eb7976b2c614a5466e7fbbb to your computer and use it in GitHub Desktop.
js-snippet
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function detectPlatform () { | |
| var e = window.navigator.userAgent.toLowerCase() | |
| return /wechatdevtools/.test(e) ? 'wechatdevtools' : /(iphone|ipad)/.test(e) ? 'ios' : /android/.test(e) ? 'android' : void 0 | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function getPrototype (value) { | |
| if (Object.getPrototypeOf) { | |
| return Object.getPrototypeOf(value) | |
| } else if (value.__proto__) { | |
| return value.__proto__ | |
| } else if (value.constructor) { | |
| return value.constructor.prototype | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const isArray = function (e) { | |
| return Array.isArray ? Array.isArray(e) : "[object Array]" === Object.prototype.toString.call(e) | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const isString = function (e) { | |
| return "[object String]" === Object.prototype.toString.call(e) | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var junjieDebug = function (data) { | |
| var formatedJSON = JSON.stringify(data, null, 2) | |
| console.log(data) | |
| console.log(formatedJSON) | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const objAssign = Object.assign || function (originObj) { | |
| for (var t = 1; t < arguments.length; t++) { | |
| var n = arguments[t]; | |
| for (var i in n) Object.prototype.hasOwnProperty.call(n, i) && (originObj[i] = n[i]) | |
| } | |
| return originObj | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function parseDate (d = new Date()) { | |
| var year = d.getFullYear() | |
| var month = d.getMonth() + 1 | |
| var day = d.getDate() | |
| var hour = d.getHours() | |
| var minute = d.getMinutes() | |
| var second = d.getSeconds() | |
| return { | |
| year, | |
| month, | |
| day, | |
| hour, | |
| minute, | |
| second | |
| } | |
| }, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function parseDate (d = new Date()) { | |
| var year = d.getFullYear() | |
| var month = change(d.getMonth() + 1) | |
| var day = change(d.getDate()) | |
| var hour = change(d.getHours()) | |
| var minute = change(d.getMinutes()) | |
| var second = change(d.getSeconds()) | |
| function change (t) { | |
| if (t < 10) { | |
| return '0' + t | |
| } else { | |
| return t | |
| } | |
| } | |
| return { | |
| year, | |
| month, | |
| day, | |
| hour, | |
| minute, | |
| second | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function _toArray (e) { | |
| return Array.isArray(e) ? e : Array.from(e) | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function unescapeText(escapedText) { | |
| const dict = { | |
| '<': '<', | |
| '>': '>', | |
| '&': '&', | |
| '"': '"' | |
| } | |
| for(var reg in dict) { | |
| escapedText = escapedText.replace(new RegExp(reg,'g'), dict[reg]) | |
| } | |
| return escapedText | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment