{"id":16217384,"url":"https://github.com/sukima/maybe-simple","last_synced_at":"2025-04-07T23:17:06.167Z","repository":{"id":57292807,"uuid":"93414232","full_name":"sukima/maybe-simple","owner":"sukima","description":"Simple Maybe monad with invoke and nested object properties support","archived":false,"fork":false,"pushed_at":"2019-04-25T16:09:23.000Z","size":20,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-01T07:02:51.858Z","etag":null,"topics":["javascript","monad","node-module","umd","utility","yarnpkg"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sukima.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-06-05T14:45:12.000Z","updated_at":"2019-04-25T16:09:24.000Z","dependencies_parsed_at":"2022-08-27T16:50:51.247Z","dependency_job_id":null,"html_url":"https://github.com/sukima/maybe-simple","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sukima%2Fmaybe-simple","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sukima%2Fmaybe-simple/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sukima%2Fmaybe-simple/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sukima%2Fmaybe-simple/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sukima","download_url":"https://codeload.github.com/sukima/maybe-simple/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247744329,"owners_count":20988784,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["javascript","monad","node-module","umd","utility","yarnpkg"],"created_at":"2024-10-10T11:44:52.007Z","updated_at":"2025-04-07T23:17:06.151Z","avatar_url":"https://github.com/sukima.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Yet Another Maybe Monad\n\nDesigned as a simple drop in module. This monad includes support for deep\nobject properties lookup and ability to invoke functions on objects.\n\n**But why?** Most Maybe monad libraries are full featured and heavy. They try\nto mimic Haskel. And many work on values and not object properties. When\nworking in JS I find I often want a simple *optional* like construct which will\nlet me deal with objects that violate the Law of Demeter (typically a nested\nobject from an API. I need a simple way to grab data deep down in a safe way\nwithout having JS blowup with undefined problems. Rails has a `try`, Swift has\noptionals, CoffeeScript has a `?` guard, but JS has *nothing* (pun intended).\n\nIf this is too much you can accomplish much of this with 20 lines of code.\nCheck out the [compact version](https://tritarget.org/#maybe.js).\n\n## Install\n\n#### NPM\n\n```console\n$ npm install --save maybe-simple\n```\n\n#### Yarn\n\n```console\n$ yarn add maybe-simple\n```\n\n#### Usage\n\n```js\nvar Maybe = require('maybe-simple');\n```\n\n\u003ca name=\"Maybe\"\u003e\u003c/a\u003e\n\n## Maybe\n**Kind**: global class  \n\n* [Maybe](#Maybe)\n    * [new Maybe(obj, selctor, def)](#new_Maybe_new)\n    * _instance_\n        * [.isNothing()](#Maybe+isNothing) ⇒ \u003ccode\u003eboolean\u003c/code\u003e\n        * [.setDefaultValue(def)](#Maybe+setDefaultValue) ↩︎\n        * [.value(def)](#Maybe+value) ⇒ \u003ccode\u003e\\*\u003c/code\u003e\n        * [.bind(fn)](#Maybe+bind) ⇒ [\u003ccode\u003eMaybe\u003c/code\u003e](#Maybe)\n        * [.nothing(fn)](#Maybe+nothing) ⇒ [\u003ccode\u003eMaybe\u003c/code\u003e](#Maybe)\n        * [.get(selector)](#Maybe+get) ⇒ [\u003ccode\u003eMaybe\u003c/code\u003e](#Maybe)\n        * [.invoke(selector)](#Maybe+invoke) ⇒ [\u003ccode\u003eMaybe\u003c/code\u003e](#Maybe)\n        * [.isEqual(other)](#Maybe+isEqual) ⇒ \u003ccode\u003eboolean\u003c/code\u003e\n        * [.toString(def)](#Maybe+toString) ⇒ \u003ccode\u003estring\u003c/code\u003e\n        * [.toJSONString(def, replacer, space)](#Maybe+toJSONString) ⇒ \u003ccode\u003estring\u003c/code\u003e\n    * _static_\n        * [.safeRead(obj, selector)](#Maybe.safeRead) ⇒ \u003ccode\u003e\\*\u003c/code\u003e\n\n\u003ca name=\"new_Maybe_new\"\u003e\u003c/a\u003e\n\n### new Maybe(obj, selctor, def)\nMaybe monad can be created with or without the new keyword.\nThis wraps an object and allows a deep selector (optional) and a default\nvalue (optional). It is safe to wrap another Maybe object.\n\n\n| Param | Type | Description |\n| --- | --- | --- |\n| obj | \u003ccode\u003e\\*\u003c/code\u003e | the original value. Can be anything. |\n| selctor | \u003ccode\u003estring\u003c/code\u003e | (optional) used to safely pick a deep value from obj. |\n| def | \u003ccode\u003e\\*\u003c/code\u003e | (optional) a default value if obj or any level of the selector resolves to nothing. |\n\n**Example**  \n```js\nvar example = { foo: { bar: { baz: 'foobarbaz' } } };\nvar x = new Maybe(example, 'foo.bar.baz'); // new is optional\nvar y = Maybe(example, 'foo.nosuchthing.baz');\nx.value() // =\u003e 'foobarbaz'\ny.value() // =\u003e null\n```\n\u003ca name=\"Maybe+isNothing\"\u003e\u003c/a\u003e\n\n### maybe.isNothing() ⇒ \u003ccode\u003eboolean\u003c/code\u003e\nCheck if the value resolves to nothing.\n\n**Kind**: instance method of [\u003ccode\u003eMaybe\u003c/code\u003e](#Maybe)  \n\u003ca name=\"Maybe+setDefaultValue\"\u003e\u003c/a\u003e\n\n### maybe.setDefaultValue(def) ↩︎\nSets the default returned from value() when this Maybe is nothing.\n\n**Kind**: instance method of [\u003ccode\u003eMaybe\u003c/code\u003e](#Maybe)  \n**Chainable**  \n\n| Param | Type | Description |\n| --- | --- | --- |\n| def | \u003ccode\u003e\\*\u003c/code\u003e | a default value |\n\n**Example**  \n```js\nMaybe(null)\n  .setDefaultValue('foobar')\n  .value(); // =\u003e 'foobar'\n```\n\u003ca name=\"Maybe+value\"\u003e\u003c/a\u003e\n\n### maybe.value(def) ⇒ \u003ccode\u003e\\*\u003c/code\u003e\nConvert the Maybe to a resolved value. Either the value or the deafult if\nthis Maybe is nothing.\n\n**Kind**: instance method of [\u003ccode\u003eMaybe\u003c/code\u003e](#Maybe)  \n**Returns**: \u003ccode\u003e\\*\u003c/code\u003e - a value, the default value, or null  \n\n| Param | Type | Description |\n| --- | --- | --- |\n| def | \u003ccode\u003e\\*\u003c/code\u003e | (optional) use as default value overridding any previous defaults. |\n\n\u003ca name=\"Maybe+bind\"\u003e\u003c/a\u003e\n\n### maybe.bind(fn) ⇒ [\u003ccode\u003eMaybe\u003c/code\u003e](#Maybe)\nPerform a transformation or action unless the value is nothing. This is\nthe main way to interface with a Maybe. The functions' return value will\nbe the new value propagated through the chain. Returning undefined (a\nfunction with no return value) does not mutate the previous value (no-op).\nReturn null if you want to the Maybe to be nothing.\n\n**Kind**: instance method of [\u003ccode\u003eMaybe\u003c/code\u003e](#Maybe)  \n**Returns**: [\u003ccode\u003eMaybe\u003c/code\u003e](#Maybe) - a Maybe object  \n\n| Param | Type | Description |\n| --- | --- | --- |\n| fn | \u003ccode\u003efunction\u003c/code\u003e | a function to execute if this Maybe is not nothing. |\n\n**Example**  \n```js\nMaybe('foo')\n  .bind(function(v) { return v + 'bar'; })\n  .bind(function(v) { console.log(v); }) // foobar\n  .bind(function(v) { return v + 'baz'; })\n  .value(); // =\u003e 'foobarbaz'\n\nMaybe('foo')\n  .bind(function(v) { return null; })\n  .bind(function(v) { return v + 'baz'; })\n  .value(); // =\u003e null\n```\n\u003ca name=\"Maybe+nothing\"\u003e\u003c/a\u003e\n\n### maybe.nothing(fn) ⇒ [\u003ccode\u003eMaybe\u003c/code\u003e](#Maybe)\nExecute/mutate with the function if this Maybe is nothing.\n\n**Kind**: instance method of [\u003ccode\u003eMaybe\u003c/code\u003e](#Maybe)  \n**Returns**: [\u003ccode\u003eMaybe\u003c/code\u003e](#Maybe) - a Maybe object  \n\n| Param | Type | Description |\n| --- | --- | --- |\n| fn | \u003ccode\u003efunction\u003c/code\u003e | a function to execute if this Maybe is nothing. |\n\n**Example**  \n```js\nMaybe(null)\n  .bind(function(v) { return v + 'foo'; })\n  .nothing(function() { return 'bar'; })\n  .bind(function(v) { return v + 'foo'; })\n  .value(); // =\u003e 'barfoo'\n```\n\u003ca name=\"Maybe+get\"\u003e\u003c/a\u003e\n\n### maybe.get(selector) ⇒ [\u003ccode\u003eMaybe\u003c/code\u003e](#Maybe)\nHelper to return a selector from a value object.\n\n**Kind**: instance method of [\u003ccode\u003eMaybe\u003c/code\u003e](#Maybe)  \n**Returns**: [\u003ccode\u003eMaybe\u003c/code\u003e](#Maybe) - a Maybe object  \n\n| Param | Type | Description |\n| --- | --- | --- |\n| selector | \u003ccode\u003estring\u003c/code\u003e | the property selector to get from the value. |\n\n**Example**  \n```js\nMaybe({ foo: { bar: 'baz' } })\n  .get('foo.bar')\n  .value(); // 'baz'\n```\n\u003ca name=\"Maybe+invoke\"\u003e\u003c/a\u003e\n\n### maybe.invoke(selector) ⇒ [\u003ccode\u003eMaybe\u003c/code\u003e](#Maybe)\nInvoke a method with args on the object if Maybe is not nothing.\n\n**Kind**: instance method of [\u003ccode\u003eMaybe\u003c/code\u003e](#Maybe)  \n**Returns**: [\u003ccode\u003eMaybe\u003c/code\u003e](#Maybe) - a Maybe object  \n\n| Param | Type | Description |\n| --- | --- | --- |\n| selector | \u003ccode\u003estring\u003c/code\u003e | the property selector to get from the value. |\n\n**Example**  \n```js\nMaybe(['foo', 'bar', 'baz'])\n  .invoke('join', ', ')\n  .value(); // =\u003e 'foo, bar, baz'\n```\n\u003ca name=\"Maybe+isEqual\"\u003e\u003c/a\u003e\n\n### maybe.isEqual(other) ⇒ \u003ccode\u003eboolean\u003c/code\u003e\nCompare two Maybe objects. Maybes considered nothing are equal.\n\n**Kind**: instance method of [\u003ccode\u003eMaybe\u003c/code\u003e](#Maybe)  \n\n| Param | Type | Description |\n| --- | --- | --- |\n| other | \u003ccode\u003e\\*\u003c/code\u003e | The other value to compare. |\n\n\u003ca name=\"Maybe+toString\"\u003e\u003c/a\u003e\n\n### maybe.toString(def) ⇒ \u003ccode\u003estring\u003c/code\u003e\nCoerce the value to a string.\n\n**Kind**: instance method of [\u003ccode\u003eMaybe\u003c/code\u003e](#Maybe)  \n**Returns**: \u003ccode\u003estring\u003c/code\u003e - a String  \n\n| Param | Type | Description |\n| --- | --- | --- |\n| def | \u003ccode\u003e\\*\u003c/code\u003e | (optional) use as default value overridding any previous |\n\n**Example**  \n```js\nMaybe([1, 2, 3])\n  .toString(); // =\u003e '1,2,3'\n```\n\u003ca name=\"Maybe+toJSONString\"\u003e\u003c/a\u003e\n\n### maybe.toJSONString(def, replacer, space) ⇒ \u003ccode\u003estring\u003c/code\u003e\nCoerce the value to JSON.\n\n**Kind**: instance method of [\u003ccode\u003eMaybe\u003c/code\u003e](#Maybe)  \n**Returns**: \u003ccode\u003estring\u003c/code\u003e - a JSON encoded String  \n\n| Param | Type | Description |\n| --- | --- | --- |\n| def | \u003ccode\u003e\\*\u003c/code\u003e | (optional) use as default value overridding any previous |\n| replacer | \u003ccode\u003efunction\u003c/code\u003e | (optional) See JSON.stringify() |\n| space | \u003ccode\u003enumber\u003c/code\u003e | (optional) See JSON.stringify() |\n\n**Example**  \n```js\nMaybe({ foo: { bar: 'baz' } })\n  .toJSON(); // =\u003e '{foo:{bar:\"baz\"}}'\nMaybe(null)\n  .toJSON(); // =\u003e '{}'\n```\n\u003ca name=\"Maybe.safeRead\"\u003e\u003c/a\u003e\n\n### Maybe.safeRead(obj, selector) ⇒ \u003ccode\u003e\\*\u003c/code\u003e\nA utility function to safely recurse through an object based on a selector.\nif any value in the chain resolves to nothing then this will simple return\nnull. Used internally to look up values when constructing a Maybe object.\n\n**Kind**: static method of [\u003ccode\u003eMaybe\u003c/code\u003e](#Maybe)  \n**Returns**: \u003ccode\u003e\\*\u003c/code\u003e - any value or null.  \n\n| Param | Type | Description |\n| --- | --- | --- |\n| obj | \u003ccode\u003eobject\u003c/code\u003e | the object to traverse. |\n| selector | \u003ccode\u003estring\u003c/code\u003e | the selector to pick from the obj. |\n\n**Example**  \n```js\nvar obj = { foo: { bar: { baz: 'foobar' } } };\nMaybe.safeRead(obj, 'foo.bar.baz'); // =\u003e 'foobar'\n```\n\u003ca name=\"Maybe\"\u003e\u003c/a\u003e\n\n## Maybe\n**Kind**: global class  \n\n* [Maybe](#Maybe)\n    * [new Maybe(obj, selctor, def)](#new_Maybe_new)\n    * _instance_\n        * [.isNothing()](#Maybe+isNothing) ⇒ \u003ccode\u003eboolean\u003c/code\u003e\n        * [.setDefaultValue(def)](#Maybe+setDefaultValue) ↩︎\n        * [.value(def)](#Maybe+value) ⇒ \u003ccode\u003e\\*\u003c/code\u003e\n        * [.bind(fn)](#Maybe+bind) ⇒ [\u003ccode\u003eMaybe\u003c/code\u003e](#Maybe)\n        * [.nothing(fn)](#Maybe+nothing) ⇒ [\u003ccode\u003eMaybe\u003c/code\u003e](#Maybe)\n        * [.get(selector)](#Maybe+get) ⇒ [\u003ccode\u003eMaybe\u003c/code\u003e](#Maybe)\n        * [.invoke(selector)](#Maybe+invoke) ⇒ [\u003ccode\u003eMaybe\u003c/code\u003e](#Maybe)\n        * [.isEqual(other)](#Maybe+isEqual) ⇒ \u003ccode\u003eboolean\u003c/code\u003e\n        * [.toString(def)](#Maybe+toString) ⇒ \u003ccode\u003estring\u003c/code\u003e\n        * [.toJSONString(def, replacer, space)](#Maybe+toJSONString) ⇒ \u003ccode\u003estring\u003c/code\u003e\n    * _static_\n        * [.safeRead(obj, selector)](#Maybe.safeRead) ⇒ \u003ccode\u003e\\*\u003c/code\u003e\n\n\u003ca name=\"new_Maybe_new\"\u003e\u003c/a\u003e\n\n### new Maybe(obj, selctor, def)\nMaybe monad can be created with or without the new keyword.\nThis wraps an object and allows a deep selector (optional) and a default\nvalue (optional). It is safe to wrap another Maybe object.\n\n\n| Param | Type | Description |\n| --- | --- | --- |\n| obj | \u003ccode\u003e\\*\u003c/code\u003e | the original value. Can be anything. |\n| selctor | \u003ccode\u003estring\u003c/code\u003e | (optional) used to safely pick a deep value from obj. |\n| def | \u003ccode\u003e\\*\u003c/code\u003e | (optional) a default value if obj or any level of the selector resolves to nothing. |\n\n**Example**  \n```js\nvar example = { foo: { bar: { baz: 'foobarbaz' } } };\nvar x = new Maybe(example, 'foo.bar.baz'); // new is optional\nvar y = Maybe(example, 'foo.nosuchthing.baz');\nx.value() // =\u003e 'foobarbaz'\ny.value() // =\u003e null\n```\n\u003ca name=\"Maybe+isNothing\"\u003e\u003c/a\u003e\n\n### maybe.isNothing() ⇒ \u003ccode\u003eboolean\u003c/code\u003e\nCheck if the value resolves to nothing.\n\n**Kind**: instance method of [\u003ccode\u003eMaybe\u003c/code\u003e](#Maybe)  \n\u003ca name=\"Maybe+setDefaultValue\"\u003e\u003c/a\u003e\n\n### maybe.setDefaultValue(def) ↩︎\nSets the default returned from value() when this Maybe is nothing.\n\n**Kind**: instance method of [\u003ccode\u003eMaybe\u003c/code\u003e](#Maybe)  \n**Chainable**  \n\n| Param | Type | Description |\n| --- | --- | --- |\n| def | \u003ccode\u003e\\*\u003c/code\u003e | a default value |\n\n**Example**  \n```js\nMaybe(null)\n  .setDefaultValue('foobar')\n  .value(); // =\u003e 'foobar'\n```\n\u003ca name=\"Maybe+value\"\u003e\u003c/a\u003e\n\n### maybe.value(def) ⇒ \u003ccode\u003e\\*\u003c/code\u003e\nConvert the Maybe to a resolved value. Either the value or the deafult if\nthis Maybe is nothing.\n\n**Kind**: instance method of [\u003ccode\u003eMaybe\u003c/code\u003e](#Maybe)  \n**Returns**: \u003ccode\u003e\\*\u003c/code\u003e - a value, the default value, or null  \n\n| Param | Type | Description |\n| --- | --- | --- |\n| def | \u003ccode\u003e\\*\u003c/code\u003e | (optional) use as default value overridding any previous defaults. |\n\n\u003ca name=\"Maybe+bind\"\u003e\u003c/a\u003e\n\n### maybe.bind(fn) ⇒ [\u003ccode\u003eMaybe\u003c/code\u003e](#Maybe)\nPerform a transformation or action unless the value is nothing. This is\nthe main way to interface with a Maybe. The functions' return value will\nbe the new value propagated through the chain. Returning undefined (a\nfunction with no return value) does not mutate the previous value (no-op).\nReturn null if you want to the Maybe to be nothing.\n\n**Kind**: instance method of [\u003ccode\u003eMaybe\u003c/code\u003e](#Maybe)  \n**Returns**: [\u003ccode\u003eMaybe\u003c/code\u003e](#Maybe) - a Maybe object  \n\n| Param | Type | Description |\n| --- | --- | --- |\n| fn | \u003ccode\u003efunction\u003c/code\u003e | a function to execute if this Maybe is not nothing. |\n\n**Example**  \n```js\nMaybe('foo')\n  .bind(function(v) { return v + 'bar'; })\n  .bind(function(v) { console.log(v); }) // foobar\n  .bind(function(v) { return v + 'baz'; })\n  .value(); // =\u003e 'foobarbaz'\n\nMaybe('foo')\n  .bind(function(v) { return null; })\n  .bind(function(v) { return v + 'baz'; })\n  .value(); // =\u003e null\n```\n\u003ca name=\"Maybe+nothing\"\u003e\u003c/a\u003e\n\n### maybe.nothing(fn) ⇒ [\u003ccode\u003eMaybe\u003c/code\u003e](#Maybe)\nExecute/mutate with the function if this Maybe is nothing.\n\n**Kind**: instance method of [\u003ccode\u003eMaybe\u003c/code\u003e](#Maybe)  \n**Returns**: [\u003ccode\u003eMaybe\u003c/code\u003e](#Maybe) - a Maybe object  \n\n| Param | Type | Description |\n| --- | --- | --- |\n| fn | \u003ccode\u003efunction\u003c/code\u003e | a function to execute if this Maybe is nothing. |\n\n**Example**  \n```js\nMaybe(null)\n  .bind(function(v) { return v + 'foo'; })\n  .nothing(function() { return 'bar'; })\n  .bind(function(v) { return v + 'foo'; })\n  .value(); // =\u003e 'barfoo'\n```\n\u003ca name=\"Maybe+get\"\u003e\u003c/a\u003e\n\n### maybe.get(selector) ⇒ [\u003ccode\u003eMaybe\u003c/code\u003e](#Maybe)\nHelper to return a selector from a value object.\n\n**Kind**: instance method of [\u003ccode\u003eMaybe\u003c/code\u003e](#Maybe)  \n**Returns**: [\u003ccode\u003eMaybe\u003c/code\u003e](#Maybe) - a Maybe object  \n\n| Param | Type | Description |\n| --- | --- | --- |\n| selector | \u003ccode\u003estring\u003c/code\u003e | the property selector to get from the value. |\n\n**Example**  \n```js\nMaybe({ foo: { bar: 'baz' } })\n  .get('foo.bar')\n  .value(); // 'baz'\n```\n\u003ca name=\"Maybe+invoke\"\u003e\u003c/a\u003e\n\n### maybe.invoke(selector) ⇒ [\u003ccode\u003eMaybe\u003c/code\u003e](#Maybe)\nInvoke a method with args on the object if Maybe is not nothing.\n\n**Kind**: instance method of [\u003ccode\u003eMaybe\u003c/code\u003e](#Maybe)  \n**Returns**: [\u003ccode\u003eMaybe\u003c/code\u003e](#Maybe) - a Maybe object  \n\n| Param | Type | Description |\n| --- | --- | --- |\n| selector | \u003ccode\u003estring\u003c/code\u003e | the property selector to get from the value. |\n\n**Example**  \n```js\nMaybe(['foo', 'bar', 'baz'])\n  .invoke('join', ', ')\n  .value(); // =\u003e 'foo, bar, baz'\n```\n\u003ca name=\"Maybe+isEqual\"\u003e\u003c/a\u003e\n\n### maybe.isEqual(other) ⇒ \u003ccode\u003eboolean\u003c/code\u003e\nCompare two Maybe objects. Maybes considered nothing are equal.\n\n**Kind**: instance method of [\u003ccode\u003eMaybe\u003c/code\u003e](#Maybe)  \n\n| Param | Type | Description |\n| --- | --- | --- |\n| other | \u003ccode\u003e\\*\u003c/code\u003e | The other value to compare. |\n\n\u003ca name=\"Maybe+toString\"\u003e\u003c/a\u003e\n\n### maybe.toString(def) ⇒ \u003ccode\u003estring\u003c/code\u003e\nCoerce the value to a string.\n\n**Kind**: instance method of [\u003ccode\u003eMaybe\u003c/code\u003e](#Maybe)  \n**Returns**: \u003ccode\u003estring\u003c/code\u003e - a String  \n\n| Param | Type | Description |\n| --- | --- | --- |\n| def | \u003ccode\u003e\\*\u003c/code\u003e | (optional) use as default value overridding any previous |\n\n**Example**  \n```js\nMaybe([1, 2, 3])\n  .toString(); // =\u003e '1,2,3'\n```\n\u003ca name=\"Maybe+toJSONString\"\u003e\u003c/a\u003e\n\n### maybe.toJSONString(def, replacer, space) ⇒ \u003ccode\u003estring\u003c/code\u003e\nCoerce the value to JSON.\n\n**Kind**: instance method of [\u003ccode\u003eMaybe\u003c/code\u003e](#Maybe)  \n**Returns**: \u003ccode\u003estring\u003c/code\u003e - a JSON encoded String  \n\n| Param | Type | Description |\n| --- | --- | --- |\n| def | \u003ccode\u003e\\*\u003c/code\u003e | (optional) use as default value overridding any previous |\n| replacer | \u003ccode\u003efunction\u003c/code\u003e | (optional) See JSON.stringify() |\n| space | \u003ccode\u003enumber\u003c/code\u003e | (optional) See JSON.stringify() |\n\n**Example**  \n```js\nMaybe({ foo: { bar: 'baz' } })\n  .toJSON(); // =\u003e '{foo:{bar:\"baz\"}}'\nMaybe(null)\n  .toJSON(); // =\u003e '{}'\n```\n\u003ca name=\"Maybe.safeRead\"\u003e\u003c/a\u003e\n\n### Maybe.safeRead(obj, selector) ⇒ \u003ccode\u003e\\*\u003c/code\u003e\nA utility function to safely recurse through an object based on a selector.\nif any value in the chain resolves to nothing then this will simple return\nnull. Used internally to look up values when constructing a Maybe object.\n\n**Kind**: static method of [\u003ccode\u003eMaybe\u003c/code\u003e](#Maybe)  \n**Returns**: \u003ccode\u003e\\*\u003c/code\u003e - any value or null.  \n\n| Param | Type | Description |\n| --- | --- | --- |\n| obj | \u003ccode\u003eobject\u003c/code\u003e | the object to traverse. |\n| selector | \u003ccode\u003estring\u003c/code\u003e | the selector to pick from the obj. |\n\n**Example**  \n```js\nvar obj = { foo: { bar: { baz: 'foobar' } } };\nMaybe.safeRead(obj, 'foo.bar.baz'); // =\u003e 'foobar'\n```\n\n## License\n\n```\nCopyright (c) 2017 Devin Weaver\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsukima%2Fmaybe-simple","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsukima%2Fmaybe-simple","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsukima%2Fmaybe-simple/lists"}