1.2.0 • Published 2 years ago

semverhook v1.2.0

Weekly downloads
-
License
ISC
Repository
-
Last release
2 years ago

semverhook

1.5kb minimalist hook sdk

API

  • semverhook = require("semverhook")()
  • import("id") : Promise
  • resolve("id") : string
  • on("resolveRequest" || "resolvePath" || "import" || "beforeImport", function)
  • off("resolveRequest" || "resolvePath" || "import" || "beforeImport", function)
  • get("id")
  • getSync("id")

例子

const semverhook = require("semverhook")()

semverhook.on("beforeImport", (id) => {
  return new Promise(res => {
    setTimeout(() => {
      res(id)
    }, 3000)
  })
})
semverhook.on("resolveRequest", function (request) {
    if (Math.random() > .5) {
      return {
        ...request,
        name: "randomName",
        query: "50%"
      }
    }
})

semverhook.on("resolvePath", function ({name, version, entry, query}) {
  console.log(this === semverhook) // true
  console.log(name) // "@scope/name"
  console.log(version) // "^1.0.3"
  console.log(entry) // "entry"
  console.log(query) // "query=1"
  
  function join(start, str) {
    return (str && `${start}${str}`) || ""
  }
  return `https://unpkg.com/${name}${join("@", version)}${join("/", entry)}${join("?", query)}`
})

semverhook.on("import", function (url) {
  console.log(this === semverhook) // true
  // return systemjs.import(url)
  return {examModule: url}
})

await semverhook.import("@scope/name@^1.0.3/entry?query=1")
semverhook.resolve("@scope/name@^1.0.3/entry?query=1") // https://unpkg.com/@scope/name@^1.0.3/entry?query=1
1.2.0

2 years ago

1.1.2

2 years ago

1.1.1

2 years ago

1.1.0

2 years ago

1.0.8

2 years ago

1.0.7

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago