Skip to main content
Deno 2 is finally here ๐ŸŽ‰๏ธ
Learn more

Deno port of IonicaBizau/deffy

deffy

deffy

Small and fast library to set default values.

๐Ÿ“‹ Example

// Dependencies
import {Deffy} from "https://deno.land/x/deffy/lib/deffy.ts"

console.log(Deffy(undefined, "Hello World"));
// => "Hello World"

console.log(Deffy("Hello World", 42));
// => 42

console.log(Deffy("Hello", "World"));
// => "Hello"

console.log(Deffy("", "World", true));
// => "World"

console.log(Deffy("", "World"));
// => ""

console.log(Deffy("foo", function (input: string) {
    return input === "foo" ? "bar" : "foo";
}));
// => "bar"

:question: Get Help

There are few ways to get help:

  1. Please post questions on Stack Overflow. You can open issues with questions, as long you add a link to your Stack Overflow question.
  2. For bug reports and feature requests, open issues. ๐Ÿ›

๐Ÿ“ Documentation

Deffy(input, def, options)

Computes a final value by providing the input and default values.

Params

  • Anything input: The input value.

  • Anything|Function def: The default value or a function getting the input value as first argument.

  • Object|Boolean options: The empty value or an object containing the following fields:

  • empty (Boolean): Handles the input value as empty field (input || default). Default is false.

Return

  • Anything The computed value.

๐Ÿ˜‹ How to contribute

Have an idea? Found a bug? See how to contribute.

๐Ÿ’ซ Where is this library used?

If you are using this library in one of your projects, add it in this list. โœจ

๐Ÿ“œ License

MIT ยฉ Ionicฤƒ Bizฤƒu MIT ยฉ Hunter Paulson