Skip to content

Instantly share code, notes, and snippets.

@anddoutoi
anddoutoi / npm-commands-scripts-life-cycle-phases.md
Created November 15, 2022 21:02 — forked from dcleao/npm-commands-scripts-life-cycle-phases.md
NPM Commands, Scripts, Life-cycle Phases

NPM Commands, Scripts, Life-cycle Phases

The following describes the behaviour of several npm commands, particularly w.r.t. the scripts that are run in each, for NPM version 6.5.0.

npm build <other-package-folder>

  1. npm run preinstall
  2. link binaries (node-gyp)
  3. for each bin command in other package:
@anddoutoi
anddoutoi / esm-package.md
Created November 15, 2022 10:01 — forked from sindresorhus/esm-package.md
Pure ESM package

Pure ESM package

The package that linked you here is now pure ESM. It cannot be require()'d from CommonJS.

This means you have the following choices:

  1. Use ESM yourself. (preferred)
    Use import foo from 'foo' instead of const foo = require('foo') to import the package. You also need to put "type": "module" in your package.json and more. Follow the below guide.
  2. If the package is used in an async context, you could use await import(…) from CommonJS instead of require(…).
  3. Stay on the existing version of the package until you can move to ESM.
const foos = ['fubar']
const foo = undefined
const defaultFoos = ['snafu']
const fubar = foos ? foos : foo ? [foo] : defaultFoos
console.log(fubar)
@anddoutoi
anddoutoi / README.md
Last active February 9, 2017 12:31
I, for one, welcome our new overloards…

Overloard

Utility function to create overloaded functions

  • Start in usage.js and follow the imports
  • Userland interesting stuff can be found in factories.js
  • usage.js for examples of… usages
@anddoutoi
anddoutoi / car-factory.js
Last active January 27, 2017 23:42
Car Factory
function makeCar(brand, model) {
return {
brand,
model,
};
}
const makeToyota = makeCar.bind(null, 'Toyota');
const makeVolvo = makeCar.bind(null, 'Volvo');
function isInTheDOM(element) {
return element.ownerDocument === getRootNode(element);
function getRootNode(element) {
var rootNode = element;
var parentNode;
while (parentNode = rootNode.parentNode) {
rootNode = parentNode;
}
@anddoutoi
anddoutoi / a.js
Created November 13, 2013 14:04
Run time lookup
function A() {
this.name = 'A';
}
A.prototype.log = function () {
console.log( 'A', this );
};
var a = new A();
a.log();
@anddoutoi
anddoutoi / my-directive.js
Created September 28, 2013 09:33
The so called 2-way binding in AngularJS. More like lol-binding imo.
angular.directive( 'myDirective', function () {
return {
link: function ( scope, element ) {
element.on( 'click', function ( event ) {
scope.foo = 'bar';
// need to $scope.$apply here. Ugly! Should be automagic.
} );
},
restrict: 'E'
};
@anddoutoi
anddoutoi / DebugPubSub.bookmarklet
Created December 13, 2012 12:42
Bookmarklet that activates PubSub debugging.
javascript:(function(){pubsub.subscribe('*',function%20(data,topic){console.log(topic+':%20'+JSON.stringify(data));});}());
@anddoutoi
anddoutoi / ReAnimator.js
Created February 13, 2012 15:43
Function that tweens element
var tweenWithReAnimator = (function () {
var defaults,
getStyleProperties;
defaults = {
frameRate: 24,// The human eye can only register motion at a rate of approximately 24 frames per second. Faster than that, and the brain just doesn't recognize the difference.
tweenTime: 400
};
getStyleProperties = function ( o ) {