Javascript

Inbox

Native Addons

async / await

Compilers

Bundlers

  • Webpack
    • neutrino.js - Create and build modern JavaScript applications with zero initial configuration.
    • webpackmonitor - A tool for monitoring webpack optimization metrics through the development process
  • parcel - Blazing fast, zero configuration web application bundler

Linters

Template engine

Util libraries

  • momentjs
    • Fomat momentjs date to PHP DateTime compatible YYYY-MM-DDTHH:mm:ss

ECMAScript 6

Javascript Runtimes

Server side javascript

Snippets

Check if object is empty

1
2
3
4
5
6
7
const object = {}

if (Object.keys(object).length) {
console.log('Object is not empty')
} else {
console.log('Object is empty')
}

Convert javascript object into serialized querystring

Taken from stackoverflow

1
2
3
4
5
6
7
8
9
10
11
12
serialize = function(obj) {
var str = [];
for(var p in obj) {
if (obj.hasOwnProperty(p)) {
str.push(encodeURIComponent(p) + "=" + encodeURIComponent(obj[p]));
}
}
return str.join("&");
}

console.log(serialize({foo: "hi there", bar: "100%" }));
// foo=hi%20there&bar=100%25

This one also converts recursive objects (using php “array” notation for the query string)

1
2
3
4
5
6
7
8
9
10
11
12
13
serialize = function(obj, prefix) {
var str = [], p;
for(p in obj) {
if (obj.hasOwnProperty(p)) {
var k = prefix ? prefix + "[" + p + "]" : p, v = obj[p];
str.push((v !== null && typeof v === "object") ? serialize(v, k) : encodeURIComponent(k) + "=" + encodeURIComponent(v));
}
}
return str.join("&");
}

console.log(serialize({foo: "hi there", bar: { blah: 123, quux: [1, 2, 3] }}));
// foo=hi%20there&bar%5Bblah%5D=123&bar%5Bquux%5D%5B0%5D=1&bar%5Bquux%5D%5B1%5D=2&bar%5Bquux%5D%5B2%5D=3

Convert dashed-string to camelCase

Source

1
var camelCased = myString.replace(/-([a-z])/g, function (g) { return g[1].toUpperCase(); });

Faletten javascript object to has only one level depth

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
const flattenObject = (ob) => {
var toReturn = {};

for (var index in ob) {
if (!ob.hasOwnProperty(index)) {
continue;
}

if ((typeof ob[index]) === 'object') {
var flatObject = flattenObject(ob[index]);
for (var prop in flatObject) {
if (!flatObject.hasOwnProperty(prop)) {
continue;
}

toReturn[index + '.' + prop] = flatObject[prop];
}
} else {
toReturn[index] = ob[index];
}
}
return toReturn;
}

editorconfig for javascript projects

1
2
3
4
5
6
7
8
9
10
11
12
13
14
# .editorconfig
# EditorConfig is awesome: http://EditorConfig.org

# top-most EditorConfig file
root = true

# Unix-style newlines with a newline ending every file
[*]
end_of_line = lf
insert_final_newline = true
indent_style = space
trim_trailing_whitespace = true
charset = utf-8
indent_size = 2

importjs

ImportJS is a tool to automatically import dependencies in your JavaScript
project. Use it along with one of our editor integrations for
Atom, Emacs, Sublime, Vim, or VS Code.

Remove ; character from automatic import

1
2
3
4
5
6
7
// .importjs.js
module.exports = {
importStatementFormatter ({ importStatement }) {
return importStatement.replace(/;$/, '')
}
}
`
⬆︎TOP