![Logo](https://github.com/Chalarangelo/30-seconds-of-code/raw/HEAD/logo.png)
30 seconds of code
![js-semistandard-style](https://img.shields.io/badge/code%20style-semistandard-brightgreen.svg)
Curated collection of useful Javascript snippets that you can understand in 30 seconds or less.
- You can find the official documentation for each snippet here
- 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.
- :warning: Most of these snippets are not production-ready. This can be verified by the fact that
anagrams
works in O(n!)
time.
Note :-
The version number of this package does not hold any special meaning. The package is updated regularly and depends upon the author. If you want a package which has more meaningful version numbers or is updated regularly(weekly) then you should use the official package.
How to use the snippets?
Node
Install globally
npm i tsoc -g
Install as a dependency
npm i tsoc --save
Using
var tsoc = require('tsoc');
tsoc.sum(1,2,3);
tsoc.scrollToTop();
tsoc.isTravisCI();
Website
Add the following in the head tag of your html document and place the tsoc.js
file in the same directory as your html document
<script src ="tsoc.js">
Or if you want to use CDN :-
<script src = "unpkg.com/tsoc">
Now you can use the snippets in your document by using TSOC.snippetName
TSOC.sum(1,2,3);
TSOC.isTravisCI();
TSOC.scrollToTop();
You can also use your favorite variable by doing :-
var _ = TSOC.
_.sum(1,2,3);
Additional Details
The tsoc.js
file is same for node and browser and is UMD. The node snippet and browser snippets are differentiated by doing the following :-
if(typeof window !== "undefined"){
var functionName = function functionName(args){
}
window.tsoc.functionName = functionName;
}
if (typeof module !== "undefined"){
var functionName = function functionName(args){
}
exports.functionName = functionName;
}