0.5.15 • Public • Published


30 seconds of code

License Gitter chat PRs Welcome Travis Build Insight.io js-semistandard-style

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 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?


Install globally

npm i tsoc -g

Install as a dependency

npm i tsoc --save


      var tsoc = require('tsoc'); //The variable name can be anything even, `_` or `$` ;)
      tsoc.sum(1,2,3); //returns 6
      tsoc.scrollToTop(); //Browser snippets are excluded from the node package so this will give a error `scrollToTop` is not a function.
      tsoc.isTravisCI(); //This works


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); //returns 6
  TSOC.isTravisCI(); //Node snippets are excluded from the browser package so this will give a error `isTravisCI` is not a function.
  TSOC.scrollToTop(); //This will work

You can also use your favorite variable by doing :-

var _ = TSOC.
_.sum(1,2,3); //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 :-

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;

Package Sidebar


npm i tsoc

Weekly Downloads






Unpacked Size

81 kB

Total Files


Last publish


  • atomiks
  • chalarangelo
  • kriadmin
  • rohittanwar