@hyurl/utils

Utility functions of HyURL collection.

Usage no npm install needed!

<script type="module">
  import hyurlUtils from 'https://cdn.skypack.dev/@hyurl/utils';
</script>

README

HyURL Utilities

Utility functions of HyURL collection.

This package currently contains the following functions, more functions may be included in the future. Each function is stored in a separated file.

Since 0.1.50, this package now supports Node.js, Web and Deno.

Import

There are two ways to import these functions.

All At Once

This method will load all functions into memory, even if you don't need some of them.

import * as utils from "@hyurl/utils";

// or import specific functions

import { count, ensureType } from "@hyurl/utils";

Only Needed

This method will only load needed functions, which is recommended.

import count from "@hyurl/utils/count";
import ensureType from "@hyurl/utils/ensureType";

Utilities Types

Other than utility functions, this package also provides some utility types for TypeScript, they are located in the following file and exposed to the global namespace.

import "@hyurl/utils/types";

Web Support

When using this package in the browser, there are three ways to import this package.

  1. Import From node_modules

This is the same as above, but requires a module bundler such as webpack.

  1. Load ES Module
<script type="module">
    import utils from "https://github.com/hyurl/utils/raw/master/esm/index.js";
    // Note the difference with the TypeScript/CommonJS version.
</script>

Note: this module can also be used Node.js as well.

Load Bundle

<script src="https://github.com/hyurl/utils/raw/master/bundle/index.js"></script>
<script>
    const { count } = window["@hyurl/utils"];

    console.log(count([1,2,3]));
<script>

Deno Support

Yes, this package can be used directly in Deno, to use it, there are two ways to import:

  1. Directly from GitHub (recommended):
import * as utils from "https://github.com/hyurl/utils/raw/master/mod.ts";
  1. Via Deno hosting service:
import * as utils from "https://deno.land/x/hyurl_utils/mod.ts";

Unit Test

In Node.js

npm test

In Deno

npm run test-deno
# or
deno test test/deno/example.ts