3.8 KiB
3.8 KiB
30 seconds of code
Curated collection of useful JavaScript snippets that you can understand in 30 seconds or less.
- Use Ctrl + F or command + F to search for a snippet.
- Contributions welcome, please read the contribution guide.
- Snippets are written in ES6, use the Babel transpiler to ensure backwards-compatibility.
- You can import these snippets into your text editor of choice (VSCode, Atom, Sublime) using the files found in this repo.
- You can import these snippets into Alfred 3, using this file.
Related
Package
⚠️ NOTICE: A few of our snippets are not yet optimized for production (see disclaimers for individual snippet issues).
You can find a package with all the snippets on npm.
# With npm
npm install 30-seconds-of-code
# With yarn
yarn add 30-seconds-of-code
CDN links
Details
Browser
IMPORTANT: replace the
srcwith the full version link and desired target spec (such as ES5 minified)):
<script src="https://unpkg.com/30-seconds-of-code"></script>
<script>
_30s.average(1, 2, 3);
</script>
Node
// CommonJS
const _30s = require('30-seconds-of-code');
_30s.average(1, 2, 3);
// ES Modules
import _30s from '30-seconds-of-code';
_30s.average(1, 2, 3);
To import snippets directly:
// CommonJS
const { average } = require('30-seconds-of-code');
average(1, 2, 3);
// ES Modules
import { average } from '30-seconds-of-code';
average(1, 2, 3);

