Skip to content

Instantly share code, notes, and snippets.

@wewindy
wewindy / esm-package.md
Created July 11, 2022 15:36 — forked from sindresorhus/esm-package.md
Pure ESM package

Pure ESM package

The package linked to from here is now pure ESM. It cannot be require()'d from CommonJS.

This means you have the following choices:

  1. Use ESM yourself. (preferred)
    Use import foo from 'foo' instead of const foo = require('foo') to import the package. You also need to put "type": "module" in your package.json and more. Follow the below guide.
  2. If the package is used in an async context, you could use await import(…) from CommonJS instead of require(…).
  3. Stay on the existing version of the package until you can move to ESM.
@wewindy
wewindy / wkt-geojson.d.ts
Created May 24, 2022 10:17
WKTString-Geojson Transformer
export interface IGeoJson {
type: 'Feature' | 'Point' | 'LineString' | 'Polygon' | 'MultiPoint' | 'MultiLineString' | 'MultiPolygon' | 'GeometryCollection';
coordinates?: any[];
geometry?: IGeoJson;
geometries?: IGeoJson[];
crs?: string | {
type: string;
properties: {
name: string;
};
@wewindy
wewindy / local-highlight.js
Created May 23, 2022 06:17
CesiumLocalHighlight
fetch('./some-region.geojson').then(res => res.json()).then(data => {
let features = data.features;
let positionArray = [];
// 获取区域的经纬度坐标
for (let i = 0; i < features[0].geometry.coordinates[0].length; i++) {
let coor = features[0].geometry.coordinates[0][i];
positionArray.push(coor[0]);
positionArray.push(coor[1]);
}
@wewindy
wewindy / gradients.ts
Created March 30, 2022 10:27
web-color-gradients
export const Rainbow_7: string[] = [
'rgb(255, 0, 0)',
'rgb(255, 165, 0)',
'rgb(255, 255, 0)',
'rgb(0, 255, 0)',
'rgb(0, 255, 255)',
'rgb(0, 0, 255)',
'rgb(139, 0, 255)'
]
@wewindy
wewindy / fragment.glsl
Created February 17, 2022 06:57
shader-useful-function
uniform vec2 u_resolution;
// 接受一个二维向量,返回一个伪随机值
float rand(const vec2 seed) {
float t = dot(vec2(12.9898, 78.233), seed);
return fract(sin(t) * (4375.85453 + t));
}
void main() {
vec2 st = gl_FragCoord.xy / u_resolution.xy;
@wewindy
wewindy / snazzy.json
Created February 9, 2022 07:13
WindowsTerminal ColorSchemas
{
"background": "#1E1F29",
"black": "#000000",
"blue": "#49BAFF",
"brightBlack": "#818181",
"brightBlue": "#49BAFF",
"brightCyan": "#8BE9FE",
"brightGreen": "#50FB7C",
"brightPurple": "#FC4CB4",
"brightRed": "#FC4346",
@wewindy
wewindy / index.css
Created December 21, 2021 10:27
prettyScrollBar
/* 滚动槽 */
::-webkit-scrollbar {
width : .5rem;
height: .5rem;
}
::-webkit-scrollbar-track {
border-radius : .25rem;
background : rgba(0, 0, 0, 0.06);
box-shadow : inset 0 0 .4rem rgba(0, 0, 0, 0.08);
@wewindy
wewindy / isCCW.ts
Created December 6, 2021 02:19
is-clockwise
type Point = [number, number, number?]
const isCCW = (p1: Point, p2: Point, p3: Point) => {
return (p2[0] - p1[0]) * (p3[1] - p1[1]) - (p2[1] - p1[1]) * (p3[0] - p1[0]) > 0
}
@wewindy
wewindy / isMobile.js
Created September 12, 2021 21:36
Regexp isMobile
const isMobile = /android|avantgo|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od|ad)|iris|kindle|lge |maemo|midp|mmp|opera m(ob|in)i|palm(os)?|phone|p(ixi|re)\/|plucker|pocket|psp|symbian|treo|up\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino/i.test(navigator.userAgent);
if (isMobile) {
location.replace('手机页面');
} else {
location.replace('PC页面');
}
/*
作者:菜鸟码农Java笔记
链接:https://www.zhihu.com/question/485560131/answer/2116400654
@wewindy
wewindy / moment-demo.js
Created August 2, 2021 06:49
A simple custom moment format demo
import moment from 'moment'
moment(`2010/1/1 19:20:59.990`, 'YYYY/M/D HH:mm:ss.SSS')
// 解析到的月份是0开头的