JSPM

@igor.dvlpr/hook

1.0.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 16
  • Score
    100M100P100Q15243F
  • License MIT

๐Ÿช Hooks onto a JavaScript prototype, either extending or changing its behavior or replacing it completely. ๐Ÿ‘บ

Package Exports

  • @igor.dvlpr/hook
  • @igor.dvlpr/hook/dist/index.mjs

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@igor.dvlpr/hook) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Hook


๐Ÿช Hooks onto a JavaScript prototype, either extending or changing its
behavior or replacing it completely ๐Ÿ‘บ




๐Ÿ’– Support further development

I work hard for every project, including this one and your support means a lot to me!
Consider buying me a coffee. โ˜•
Thank you for supporting my efforts! ๐Ÿ™๐Ÿ˜Š


Donate to igorskyflyer

@igorskyflyer




[!CAUTION] This package provides ways of modifying the native prototype(s) of built-in JavaScript objects, use it only if you know what you're doing and with caution as it may cause unexpected results!



๐Ÿ•ต๐Ÿผ Usage

Install it by executing:

npm i "@igor.dvlpr/hook"

๐Ÿคน๐Ÿผ API

function hook(
  proto: any,
  method: string,
  handler: HandlerFn,
  replace: boolean = false
): boolean

Hooks onto a JavaScript prototype in order to extend, modify or completely replace a given method of it.


  • proto - a prototype, e.g. Array.prototype, Number.prototype, etc.
  • method - a method to hook onto, e.g. 'push' of Array.prototype.
  • handler a custom function to run when the hooked method is called.
  • replace a Boolean indicating whether the prototype method should be replaced completely. Defaults to false.

Returns a Boolean whether the hooking onto was successful.


Example

import { hook } from '@igor.dvlpr/hook'

hook(Array.prototype, 'unshift', function (x) {
    // any code can be here,
    // not just owned by the prototype
    // you're hooking/replacing
  this.push(x * 2)
})

const array: number[] = []

array.unshift(128)

console.log(array) // [128, 256]

๐Ÿชช License

Licensed under the MIT license which is available here, MIT license.


@igor.dvlpr/jmap

๐Ÿ•ถ๏ธ Reads a JSON file into a Map. ๐ŸŒป

@igor.dvlpr/strip-html

๐Ÿฅž Removes HTML code from the given string. Can even extract text-only from the given an HTML string. โœจ

@igor.dvlpr/comment-it

๐Ÿ“œ Formats the provided string as a comment, either a single or a multi line comment for the given programming language. ๐Ÿ’ป

@igor.dvlpr/normalized-string

๐Ÿ’Š NormalizedString provides you with a String type with consistent line-endings, guaranteed. ๐Ÿ“ฎ

@igor.dvlpr/keppo

๐ŸŽก Parse, manage, compare and output SemVer-compatible version numbers. ๐Ÿ›ก



Provided by Igor Dimitrijeviฤ‡ (@igorskyflyer).