30 seconds of code
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.
- ⚠️ Most of these snippets are not production-ready. This can be verified by the fact that
anagrams
works inO(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 = ; //The variable name can be anything even, `_` or `$` ;) tsoc; //returns 6 tsoc; //Browser snippets are excluded from the node package so this will give a error `scrollToTop` is not a function. tsoc; //This works
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
Or if you want to use CDN :-
Now you can use the snippets in your document by using TSOC.snippetName
TSOC; //returns 6 TSOC; //Node snippets are excluded from the browser package so this will give a error `isTravisCI` is not a function. TSOC; //This will work
You can also use your favorite variable by doing :-
var _ = TSOC_; //Returns 6
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 :-
iftypeof window !== "undefined" var { //Code } windowtsocfunctionName = functionName;if typeof module !== "undefined" var { //Code } exportsfunctionName = functionName;