{"library":"option","title":"Option Type for JavaScript","description":"This package provides a robust implementation of the option (or maybe) type for JavaScript, designed to manage optional values and mitigate the pervasive issues of `null` and `undefined`. It offers a functional approach to handling the presence or absence of a value through `some(value)` and `none` constructs, similar to types found in languages like Rust or Scala. The current stable version is `0.2.4`, which was published approximately nine years ago, indicating that the package is no longer actively maintained. Key differentiators include its rich API for value manipulation, such as `map`, `flatMap`, `filter`, `orElse`, and `valueOrElse`, which promote safer and more expressive code compared to traditional null checks. Its `fromNullable` function also provides a convenient way to convert potentially nullish values into `option` types.","language":"javascript","status":"abandoned","last_verified":"Sun Apr 19","install":{"commands":["npm install option"],"cli":null},"imports":["const option = require('option');","const someValue = option.some('hello');","const noValue = option.none;","const maybeValue = option.fromNullable(someNullableVar);"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"const option = require(\"option\");\n\n// Creating Option instances\nconst someUser = option.some({\n    id: 1,\n    name: () => \"Alice\"\n});\nconst noUser = option.none;\n\n// Basic checks\nconsole.log(`someUser isSome: ${someUser.isSome()}`); // true\nconsole.log(`noUser isNone: ${noUser.isNone()}`);     // true\n\n// Retrieving values safely\nfunction greet(userOption) {\n    return userOption.map(user => user.name())\n                     .valueOrElse(\"Anonymous\");\n}\n\nconsole.log(`Greeting someUser: Hello ${greet(someUser)}`); // Hello Alice\nconsole.log(`Greeting noUser: Hello ${greet(noUser)}`);     // Hello Anonymous\n\n// Using fromNullable\nconst nullableString = Math.random() > 0.5 ? \"A string\" : null;\nconst safeOption = option.fromNullable(nullableString);\nconsole.log(`From nullable: ${safeOption.valueOrElse(\"No string provided\")}`);","lang":"javascript","description":"Demonstrates creating 'some' and 'none' options, performing checks, safely unwrapping values with `valueOrElse`, and using `fromNullable`.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}