All Projects → EnixCoda → safe-touch

EnixCoda / safe-touch

Licence: other
⛓ Runtime optional chaining for JS

Programming Languages

typescript
32286 projects

Projects that are alternatives of or similar to safe-touch

validate-polish
Utility library for validation of PESEL, NIP, REGON, identity card etc. Aimed mostly at Polish enviroment. [Polish] Walidacja numerów pesel, nip, regon, dowodu osobistego.
Stars: ✭ 31 (-56.34%)
Mutual labels:  javascript-library, typescript-library
react-picture-annotation
A simple annotation component.
Stars: ✭ 53 (-25.35%)
Mutual labels:  javascript-library, typescript-library
rxjs-ninja
RxJS Operators for handling Observable strings, numbers, booleans and more
Stars: ✭ 68 (-4.23%)
Mutual labels:  javascript-library, typescript-library
Gojs
JavaScript diagramming library for interactive flowcharts, org charts, design tools, planning tools, visual languages.
Stars: ✭ 5,739 (+7983.1%)
Mutual labels:  javascript-library, typescript-library
necktie
Necktie – a simple DOM binding tool
Stars: ✭ 43 (-39.44%)
Mutual labels:  javascript-library, typescript-library
constant-time-js
Constant-time JavaScript functions
Stars: ✭ 43 (-39.44%)
Mutual labels:  javascript-library, typescript-library
imtool
🖼️ Client-side canvas-based image manipulation library.
Stars: ✭ 38 (-46.48%)
Mutual labels:  javascript-library, typescript-library
sqlweb
SqlWeb is an extension of JsStore which allows to use sql query for performing database operation in IndexedDB.
Stars: ✭ 38 (-46.48%)
Mutual labels:  javascript-library, typescript-library
animusjs
🎆 AnimusJS is the solution for combine JS and CSS animations.
Stars: ✭ 42 (-40.85%)
Mutual labels:  javascript-library
easevalidation
javascript validation library
Stars: ✭ 14 (-80.28%)
Mutual labels:  javascript-library
Amino.JS
A powerful JavaScript library for interacting with the Amino API 🌟
Stars: ✭ 25 (-64.79%)
Mutual labels:  javascript-library
html-chain
🔗 A super small javascript library to make html by chaining javascript functions
Stars: ✭ 32 (-54.93%)
Mutual labels:  javascript-library
ImagerJs
A JavaScript library for uploading images using drag & drop. Crop, rotate, resize, or shrink your image before uploading.
Stars: ✭ 101 (+42.25%)
Mutual labels:  javascript-library
puddle.js
An ASCII/Node based fluid simulation library.
Stars: ✭ 102 (+43.66%)
Mutual labels:  javascript-library
aws-amplify-react-custom-ui
Building a Custom UI Authentication For AWS Amplify
Stars: ✭ 21 (-70.42%)
Mutual labels:  javascript-library
jsonrpc-ts
A very flexible library for building JSON-RPC 2.0 endpoints
Stars: ✭ 19 (-73.24%)
Mutual labels:  typescript-library
Glize
📚 Glize is a clean and robust pure Javascript library.
Stars: ✭ 16 (-77.46%)
Mutual labels:  javascript-library
iFrameX
Iframe generator with dynamic content injection like HTML, Javascript, CSS, etc. and two ways communication, parent <-> iframe.
Stars: ✭ 18 (-74.65%)
Mutual labels:  javascript-library
blaver
A JavaScript library built on top of the Faker.JS library. It generates massive amounts of fake data in the browser and node.js.
Stars: ✭ 112 (+57.75%)
Mutual labels:  javascript-library
tarballjs
Javascript library to create or read tar files in the browser
Stars: ✭ 24 (-66.2%)
Mutual labels:  javascript-library

Safe Touch

Retrieving deeply buried properties is a common problem in JavaScript, it could crash your application if you try to access a property that doesn't exist.

const state = { user: { name: "EnixCoda" } };
console.log(state.user.name); // 'EnixCoda'
state.user = null;            // simulating logout
console.log(state.user.name); // Uncaught TypeError: Cannot read property 'name' of null

Safe touch is a safe way to access deeply buried properties.

const $state = safeTouch(state);      // retrieving properties from $state is always safe
console.log($state() === state);      // true; invoke to get the original value
{
  let { user: { name } } = $state;    // support native destructuring
  console.log(name());                // 'EnixCoda'
  console.log($state.user.name());    // 'EnixCoda'
}

Object.assign(state, { user: null })  // simulating logout
{
  let { user: { name } } = $state;    // support native destructuring
  console.log(name());                // undefined; no errors!
  console.log($state.user.name());    // undefined; no errors!
}

Playground

Available as safe-touch on npm.

> yarn add safe-touch

Why choose Safe Touch?

  • state && state.user && state.user.name is verbose.
  • wrapping with try ... catch is verbose and creates new code block.
  • lodash _.get has no TypeScript support.
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].