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
| /** | |
| * 获取表单数据对象 | |
| * | |
| * @param {HTMLFormElement | string} form | |
| * @return {object} | |
| */ | |
| export const getFormData = form => { | |
| let data = {} | |
| const kvObjArray = $(form).serializeArray() |
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
| /** | |
| * 生成指定位数的随机数 | |
| * @param {number} x | |
| */ | |
| export const randomStr = (x) => { | |
| let s = ""; | |
| while(s.length < x && x > 0){ | |
| let v = Math.random() < 0.5 ? 32 : 0; | |
| s += String.fromCharCode(Math.round(Math.random() * ((122 - v) - (97 - v)) + (97 - v))); | |
| } |
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
| let num = 123456.1234 | |
| num.toLocaleString('zh-Hans-CN', { style: 'currency', currency: 'CNY' }) | |
| // ¥123,456.12 | |
| num.toLocaleString('en-US', { style: 'currency', currency: 'USD' }) | |
| // $123,456.12 | |
| num.toLocaleString('zh', { style: 'decimal', minimumFractionDigits: 2, maximumFractionDigits: 2 }) | |
| // 123,456.12 |
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
| " 显示行号 | |
| set number | |
| " 显示标尺 | |
| set ruler | |
| " 历史纪录 | |
| set history=1000 | |
| " 输入的命令显示出来,看的清楚些 |
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 UniversalUser = universal(() => import('./User'), { | |
| resolve: () => require.resolveWeak('./User'), | |
| loading: <Loading /> | |
| }) | |
| const User = ({ loading, error, user }) => | |
| <div> | |
| <UniversalUser isLoading={loading} error={error} user={user} /> | |
| </div> |
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
| $vu_base: 375 // iphone6 | |
| @function vu($px) { | |
| @return ($px / $vu_base) * 100vw | |
| } |
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 bcrypt = require('bcrypt') | |
| const jwt = require('jsonwebtoken') | |
| const config = require('../config/security') | |
| function hashPassword(password) { | |
| return new Promise((resolve, reject) => { | |
| bcrypt.genSalt(config.saltRounds) | |
| .then(salt => { | |
| return bcrypt.hash(password, salt) | |
| }) |
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 container = document.getElementById('js-list'); | |
| if (!container) { | |
| return | |
| } | |
| const total = 10000 | |
| const batchSize = 4 // 每次插入多少个结点,越大越卡 | |
| const batchCount = total / batchSize // 插入次数 | |
| let batchDone = 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
| const arr = ['aaa', 'bbb', 'aaa', '111']; | |
| const uniqueArr = arr.filter((item, index) => { | |
| return arr.indexOf(item) === index; | |
| }); | |
| console.log(uniqueArr); // ['aaa', 'bbb', '111'] | |
| const simpleUnique = function(arr) { | |
| return [...new Set(arr)] | |
| } |
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 arr = [ | |
| {"name": "Kate", "age": 22}, | |
| {"name": "Candy", "age": 21}, | |
| {"name": "Petty", "age": 20} | |
| ]; | |
| arr.sort(compare('name')) // {"name": "Candy", "age": 21}, {"name": "Kate", "age": 22}, {"name": "Petty", "age": 20} | |
| arr.sort(compare('age')); // {"name": "Petty", "age": 20}, {"name": "Candy", "age": 21}, {"name": "Kate", "age": 22} | |
| function compare(key) { |