1 Star 0 Fork 0

不如怀念 / awesome-code-snippets

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README

Awesome-Code-Snippets

:heart: 很棒的且可重用的代码片段。

目录

Content.

代码片段

Code Snippets.

JavaScript

Field data type mapping in the dbf file of ESRI Shapefile.

{
	B: 'Binary',
	C: 'Character',
	D: 'Date',
	N: 'Numeric',
	L: 'Logical',
	M: 'Memo',
	'@': 'Timestamp',
	I: 'Long',
	'+': 'Autoincrement',
	F: 'Float',
	O: 'Double',
	G: 'OLE'
}

HTML

  • MediaDevices.getUserMedia() vs <input type="file" capture />

为了使用 JavaScript 在移动终端上调用媒体设备(相机/麦克风等),H5 API 提供了 MediaDevices.getUserMedia(),但是存在许多兼容性问题;然而,你可以使用 input 标签的 capture 属性作为备选方案。

// `accept` attribute can restrict media type.
// no accept - When the accept attribute does not exist, it will include the camera / camcorder / recorder / file system.
// accept=image/* - camera only.
// accept=video/* - camcorder only.
// accept=audio/* - recorder only.
<input type="file" capture />

CSS

  • 使用 @media 隐藏不需要打印的 DOM 元素
@media print {
  .not-print {
    display: none;
  }
}

标记不需要打印的 DOM 元素:

<div class="not-print"></div>
  • 使用 CSS 规则 break-before break-after 在打印时强制分页:
.page {
  break-before: auto;
  break-after: always;
}

然后:

<section class="page">Page One</section>
<section class="page">Page Two</section>
contain: strict;

Node.js

  • 在 Node.js 中用 POST 请求提交 multipart/form-data 表单数据

Node.js 默认对 multipart/form-data 数据在请求时不进行编码,form-data 模块提供了解决方案:

import FormData from 'form-data'
import axios from 'axios'

const formData = new FormData()
formData.append('username', username)
formData.append('password', password)

// `headers` are very important
axios.post(api, formData, { headers: formData.getHeaders() })
  • npm link

在 Node.js 模块/包开发中,npm link 命令可以在本地进行发布前调试,但会造成一点的问题和文件夹污染,下面提供一个更干净的方式:

"dependencies": {
  "my-dev-module": "file:../my-dev-module/index.min.js"
}
  • 移除 node_modules 文件夹

node_modules 文件夹通常包含大量文件,要在 Windows 系统上删除该文件夹需要耗费很长时间,提供一个有用的命令来快速删除该文件夹:

rmdir "node_modules\" /S /Q
  • 安装 node-sass

安装 node-sass 的过程中总会出现网络错误,可以使用国内镜像源进行安装:

It is easy to fail to install in China in the normal way. Can be installed in the following ways:

npm i -D node-sass --sass_binary_site=https://npm.taobao.org/mirrors/node-sass/

现在,推荐使用 sass 作为替代。

其它

Other.

The reason this repository exists is because gistub's gist cannot be accessed in the normal way.

空文件

简介

Some great code snippets that are very useful and reusable. | 一些非常棒、可重用的代码片段。 展开 收起
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
1
https://gitee.com/i_wang1212/awesome-code-snippets.git
git@gitee.com:i_wang1212/awesome-code-snippets.git
i_wang1212
awesome-code-snippets
awesome-code-snippets
master

搜索帮助