JavaScript Tips

Javascript/NPM/Yarn

Yarn: Update Packages Globally

yarn global upgrade-interactive

Yarn: Fix missing/bad signature issue

curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -

NPM: Update Packages Globally

npm i npm-check -g
npm-check -gu

JS: Fake Geolocation Data

navigator.geolocation.getCurrentPosition = function(success, failure) { 
    success({ coords: { 
        latitude: 42.3143286, 
        longitude: -71.0403234

    }, timestamp: Date.now() }); 
}

JS: Flatten multiple arrays

let arrays = [
  ["$6"],
  ["$12"],
  ["$25"],
  ["$25"],
  ["$18"],
  ["$22"],
  ["$10"]
];

let merged = [].concat.apply([], arrays);

JS: Get only unique values in array (ala PHP’s array_unique)

[ ...new Set(array) ]

Last updated