Skip to content

Instantly share code, notes, and snippets.

/**
* Simple node.js style script loader for modern browsers
**/
function loadScript(src, cb) {
var script = document.createElement('script');
script.async = true;
script.src = src;
script.onerror = function() {
cb(new Error("Failed to load" + src));
let arr1 = [9,2,3,4,10],
arr2 = [2,3,4,5,6];
let arr = [arr1,arr2];
function count(arr){
let tmp = [];
arr[0].forEach(function(v,i){
tmp.push([]);
})
arr.forEach(function(v,i){
// 属性名替换
const transformModel = (object = {}, keymap = {}) => {
if (typeof object !== 'object' || object === null) return object
if (Array.isArray(object)) {
return object.map(value => transformModel(value, keymap))
}
return Object.keys(object).reduce((result, curkey) => {
if (keymap[curkey]) {
const { value, children } = keymap[curkey]
result[value] = transformModel(object[curkey], children)
/**
* 元素是否在视窗内
* @param {*} el
*/
export function isInViewPort(el: HTMLElement): boolean {
//获取屏幕高度
let windowTop = window.innerHeight
|| document.documentElement.clientHeight
|| document.body.clientHeight;;
// 获取元素相对视窗的位置
function findPathByLeafId(vefPath, nodes, path) {
if(_.isUndefined(path)) {
path = [];
}
for(let i = 0; i < nodes.length; i++) {
let tmpPath = path.concat();
const item = nodes[i]
tmpPath.push(item.path);
if (!_.isEmpty(item.redirect)) {
tmpPath.push(item.redirect);
func GET_TEXT()
let begin = searchpos('\(\%V\@<!.\|^\)\%V', 'nw')
let end = searchpos('\%V.\%V\@!', 'nw')
if begin[0] == end[0]
let line = getline('.')
return strpart(line, begin[1], end[1]-begin[1])
endif
return ''
endf
if exists('s:loaded')
finish
endif
let s:loaded = 1
let s:use_default_surround_config = get(g:, 'use_default_surround_config', 1)
if s:use_default_surround_config == 1
" 快速添加、去除、修改pairs
" add、remove、update pairs
nnoremap <silent> ys :call SurroundAddPairs(SurroundGetLR())<CR>
vnoremap <silent><buffer> C :<c-u>call <SID>console()<cr>
func s:console()
let tag = getline(line("."))[col("'<") - 1 : col("'>") - 2]
let l = line('.')
let space = substitute(getline(l), '\v(^\s*).*', '\1', '')
call appendbufline('%', line('.'), printf(space . 'console.log(`[logger-%s] => `, %s)', tag, tag))
endf
const fs = require('fs');
const path = require('path')
const glob = require('globby')
function moduleName (modules) {
let filename = path.basename(modules)
let parts = filename.split('.')
parts.pop()
filename = parts.join('.')
import requests
import json
import os
down_path = 'images'
if not os.path.exists(down_path):
os.makedirs(down_path)
url = 'http://www.quanquansy.com/data.json'