Skip to main content
Deno 2 is finally here 🎉️
Learn more

g-utils

A bunch of utility functions and other such things.

Usage

You can either import each individual function from their specific file, like so:

import randomElem from "https://deno.land/x/grutils@0.0.4/randomElem.ts"; // the function is a default export so you can call it whatever you want.

console.log(randomElem([1, 2, 3, 4, 5]));

or just import individual function from the mod.ts file, like so:

import { randomElem } from "https://deno.land/x/grutils@0.0.4/mod.ts"; // randomElem is not a default export in this case.

console.log(randomElem([1, 2, 3, 4, 5]));

Available utilities

All the utilities available from this library.

randomElem

Returns a random element from the array given.

inArr

Returns true if the element given is part of the array given, else returns false

trimEnds

Returns the given string with the characters trimmed on each side by the length given, which is default by 1.

Example usage:

import { trimEnds } from "https://deno.land/x/grutils@0.0.4/mods.ts";

console.log(trimEnds("!Hello!")) // logs Hello to the console.

Direction

An enum with the 4 cardinal directions

Note: This isn’t default exported because of how exports behave with enums, also note that enums are 0-indexed so North is 0, South is 1, West is 2, East is 3.

indexOfEnd

Returns the last index of the given substring inside the given string, otherwise works the same as String.prototype.indexOf()