@9oelm/maybe 中文文档教程

发布于 4年前 浏览 27 项目主页 更新于 3年前

maybe

npm i --save @9oelm/maybe

yarn add @9oelm/maybe

只是我个人用于处理 nullundefined 的工具。

Usage

import { maybe } from '@9oelm/maybe'

const mayBeNullOrUndefined: HTMLElement | null = document.querySelector('#maybe-exists');

const text: string = 
  maybe(maybeNullOrUndefined)
  .then(({ innerText }) => innerText)
  .otherwise(`please fill out text first`);

// omit .then to just receive the defined value itself
const someHTMLElementOrMyFallbackHtmlElement: HTMLElement = 
  maybe(mayBeNullOrUndefined).otherwise(document.createElement('div'))

maybe

npm i --save @9oelm/maybe

yarn add @9oelm/maybe

Just my personal util for handling null and undefined.

Usage

import { maybe } from '@9oelm/maybe'

const mayBeNullOrUndefined: HTMLElement | null = document.querySelector('#maybe-exists');

const text: string = 
  maybe(maybeNullOrUndefined)
  .then(({ innerText }) => innerText)
  .otherwise(`please fill out text first`);

// omit .then to just receive the defined value itself
const someHTMLElementOrMyFallbackHtmlElement: HTMLElement = 
  maybe(mayBeNullOrUndefined).otherwise(document.createElement('div'))
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文