1.3.2 • Published 3 years ago

registerable v1.3.2

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

test GitHub release deno land nest badge deno doc deno version node support version bundle size npm download

dependencies Status codecov Codacy Badge npm type definitions Commitizen friendly Gitmoji semantic-release License: MIT


:bookmark: Table of Contents

:sparkles: Features

  • :zap: Multi runtime support (Deno, Node.js)
  • :books: Pure TypeScript and provides type definition
  • :earth_americas: Universal module, providing ES modules and UMD
  • :package: Optimized, super slim size
  • :page_facing_up: TSDoc-style comments

Module registry

:memo: API

CLI

The Cli interface is common to Deno and Node.js.

@runtime <name> [Options]

@runtime: How to call it depends on the runtime. See Deno or Node.js sections.

name: Check module is registerable or not. required

Options:
All options are optional

flagdesctypedefaultchoice
-r, --registryQuery to registryarraydeno.land, nest.land, npmdeno.land, nest.land, npm
-j, --jsonDisplay to JSON formatbooleanfalse
--verboseVerbose modebooleantrue
-h, --helpShow helpboolean
-v, --versionShow version number

Deno

@runtime: deno run --allow-net https://deno.land/x/registerable/cli.ts

Configuration

Required permissions:

  • --allow-net
Local

You can use it directly from the CLI by using deno run:

deno run --allow-net https://deno.land/x/registerable/cli.ts <name> [Options]
Global

You can also install it globally using the following:

deno install --allow-net -n registerable https://deno.land/x/registerable/cli.ts

Then, the package is available to run:

registerable <name> [Options]

Node.js

Local

You can install locally.

yarn add -D registerable
or
npm i -D registerable

then,

yarn registerable <name> [Options]
or
npm run registerable <name> [Options]
Global

You can also install it globally using the following:

yarn global add registerable

registerable <name> [Options]

JavaScript API

The JavaScript API is the best way to call it programmatically.

Type Definition:

declare const registerable: <T extends "nest.land" | "npm" | "deno.land">(
  name: string,
  option?: Partial<Option<T>> | undefined
) => Promise<RegisterableResult<T>>;

Parameters

registerable(name, option)

This function accept 2 arguments.

name required

nametypedesc
namestringQuery name

option optional

nametypedescdefault
registryarrayPick the package registry to query. choice: deno.land, nest.land and npmdeno.land, nest.land, npm
modestringSpecifies where this function is called. choice: server or universalserver

What is mode?

You can avoid CORS errors by specifying the mode. For server mode, it queries the public API in the package registry directly.

With the exception of deno.land, the public api response headers do not have the Access-Control-Allow-Origin property set. That is, if call this function from browser, you will get a CORS error.

To avoid this, we have prepared a Proxy server. It returns the result of running the registerable function on the server and the response header with Access-Control-Allow-Origin: * added.

You can get the result from the following URL:

https://registerable.vercel.app/check-name

Mode of universal queries this URL and gets the same results as server mode without CORS errors.

If there is a possibility of calling the registerable function from a Browser such as SPA or SSR, the mode should be universal.

However, if it is clear that it will be called only on the server side, it is recommended to use in server mode from the viewpoint of performance. Therefore, it is set to server mode by default.

Return value

The return value is a JSONObject that indicates whether it can be registered in the package registry, an error message if there is a validation error in query name, and which query caused the error.

{
  result: {
    "deno.land"?: boolean,
    "nest.land"?: boolean,
    npm?: boolean,
  },
  error: {
     "deno.land"?: string,
     "nest.land"?: string,
      npm?: string,
  },
  hasError: boolean,
  errorRegistry: ("deno.land" | "nest.land" | npm)[],
  name: string,
}
namedesc
nameSame as query name
resultMap of registry name and result of registerable or not
errorMap of registry name and validation error message
hasErrorSet this flag to true if each registry query has more than one name validation error.
errorRegistryList the registry names that had validation errors

Definition of error

If the package name exists, it will not be treated as an error. Violation of the package name rules in each package registry will report an error.

Click here for package name validation rules.

For example, if there is a validation error as the package name for deno.land and nest.land :

const { result, error, errorRegistry } = await registerable('exist-package-name')
// result
{
  result: {
    "deno.land": false,
    "nest.land": false,
    npm: true,
  },
  error: {
     "deno.land": "Name contains only the characters a-z, 0-9 and _",
     "nest.land": "Name contains only the characters a-z, 0-9 and _",
  },
  hasError: true,
  errorRegistry: ["deno.land", "nest.land"],
  name: "exist-package-name",
}

errorRegistry.forEach((registry) => console.warn(registry, error[registry]))
// deno.land "Name contains only the characters a-z, 0-9 and _"
// nest.land "Name contains only the characters a-z, 0-9 and _"

Examples

await registerable('not_exist_package')
// result
{
  result: {
    "deno.land": true,
    "nest.land": true,
    npm: true,
  },
  error: {},
  hasError: false,
  errorRegistry: [],
  name: "not_exist_package",
}

await registerable('not_exist_package', {
  registry: ['deno.land']
})
// result
{
  result: {
    "deno.land": true
  },
  error: {},
  hasError: false,
  errorRegistry: [],
  name: "not_exist_package",
}

:green_heart: Supports

The TypeScript version must be 4.1.0 or higher.

This project provide ES modules and UMD. The range supported by both is different.

ES modules

Limit support to the latest environment to reduce the bundle size.

DenoNode.jsEdgeFirefoxChromeSafariiOS SafariSamsungOpera
^1.6.0^14.16.0last 2 versionslast 2 versionslast 2 versionslast 2 versionslast 2 versionslast 2 versionslast 2 versions

UMD

Browser is supporting since IE11.

Node.jsIE / EdgeFirefoxChromeSafariiOS SafariSamsungOpera
^6.17.0IE11 / ^16^60^61^10.1^10.3^8.2^48

Compared to ES modules, UMD has a bundle size increase of about 2.5x. Recommend using ES modules as much as possible.

:handshake: Contributing

Contributions, issues and feature requests are welcome!Feel free to check issues.

:seedling: Show your support

Give a ⭐️ if this project helped you!

:bulb: License

Copyright © 2021-present TomokiMiyauci.

Released under the MIT license

1.3.2

3 years ago

1.3.2-beta.1

3 years ago

1.3.1

3 years ago

1.3.1-beta.1

3 years ago

1.3.0

3 years ago

1.3.0-beta.1

3 years ago

1.2.3

3 years ago

1.2.3-beta.1

3 years ago

1.2.2-beta.2

3 years ago

1.2.2

3 years ago

1.2.2-beta.1

3 years ago

1.2.1

3 years ago

1.2.1-beta.1

3 years ago

1.2.0-beta.6

3 years ago

1.2.0

3 years ago

1.2.0-beta.5

3 years ago

1.2.0-beta.4

3 years ago

1.2.0-beta.3

3 years ago

1.2.0-beta.2

3 years ago

1.2.0-beta.1

3 years ago

1.1.0

3 years ago

1.1.0-beta.6

3 years ago

1.1.0-beta.5

3 years ago