Git Product home page Git Product logo

safelyread's Introduction

Fabrício Monteiro

Frontend Software Engineer @ Flieber, Inc

Twitter Badge Linkedin Badge Gmail Badge YouTube Badge

Hey there! I'm Fabs (or Fabrício if you can spell it 😅)

I am a code-crazy developer, enthusiast of good development practices, tech lover and tech content creator - when I have some time ⏳.

I love learning and applying all the knowledge I get about web and mobile development into the projects I participate.

"[...] because the people who are crazy enough to think they can change the world, are the ones who do."

safelyread's People

Contributors

fabmont avatar

Stargazers

 avatar

Watchers

 avatar  avatar

safelyread's Issues

Log function arguments for better debugging experience.

console.error(

It would make a better debugging experience to log the function's arguments so the dev can tell what went wrong. Also, it is a good idea to console.error an Error object instead of a string so that the developer has access to tha stacktrace.

Maybe:

const err = new Error(`The function passed to the fourth parameter of safelyRead crashed')
  Called with ${JSON.stringify(arguments)}
`;

console.error(err);

Lib can't be ran standalone in the browser

When trying to run the main file index.js in the browser without a bundler (webpack, etc), the 'require' function and 'process.env.NODE_ENV' are undefined. Maybe add a bundler?

I'm using microbundle in my packages with the following relevant fields on package.json:

{
  "source": "src/index.ts",
  "main": "dist/index.umd.js",
  "module": "dist/index.js",
  "scripts": {
    "build": "microbundle -f esm,umd --target node,web --strict --name safelyRead",
  },
}

This will output a umd and a module file. The UMD file works everywhere and webpack loves the module file because it allowes treeshaking.

Maybe remove lodash.get dependency!?

Maybe remove lodash.get dependency and implement the get function ourselves is a good ideal to prevent us from having to update this library everytime lodash.get changes.

A get implementation using ES5, which runs everywhere:

function get (object, path, value) {
  const pathArray = Array.isArray(path) ? path : path.split('.').filter(key => key);

  const pathArrayFlat = Array.prototype.concat.apply(
    [],
    pathArray.map(part => typeof part === 'string' ? part.split('.') : part)
  );

  return pathArrayFlat.reduce((obj, key) => obj && obj[key], object) || value;
}

What do you think?

--

By the way, I got the function above from here and rewrote it to stop using flatMap since it doesn't run everywhere.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.