question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Provide JS Modules export?

See original GitHub issue

Hi @sindresorhus!

This module is pretty popular, and its functionality is fairly segmented (get vs set). I’m willing to bet a decent number of people are only using this to safely retrieve the value at a dotted path (not set).

Given that assumption, I was wondering if you’d be open to providing a JS Modules version where { set, get } are named exports? I’d be happy to open a PR, though I’d need to know what solution you’d prefer for transpiling modules to commonjs (I’m biased).

Cheers!

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

6reactions
sindresorhuscommented, Mar 16, 2019

If they are going to be “named exports”, I think it would make sense to make them named something like import {getProperty, deleteProperty} from 'dot-props';. Thoughts?

3reactions
saibotsivadcommented, Apr 15, 2019

Just another perspective: I actually use the import { get } from 'dot-prop' a lot in a large API project, and it seems pretty readable to me. An example route handler might look like:

import { get } from 'dot-prop'

export default async ({ mediator, query, security }) => {
    if (get(security, 'security/public-mobile-app')) {
        query.state = 'published'
    }

    return {
        status: 200,
        body: {
            data: await mediator.call('controller/players/find', { query })
        }
    }
}

Coming from projects that use lodash with the _ a lot, I feel like _.get( is just as readable as get( but I am all for making names more wordy:

import { getProperty } from 'dot-prop'

export default async ({ mediator, query, security }) => {
    if (getProperty(security, 'security/public-mobile-app')) {
Read more comments on GitHub >

github_iconTop Results From Across the Web

Understanding module.exports and exports in Node.js
In this article, I'll examine how to work with modules in Node.js, focusing on how to export and consume them.
Read more >
module.exports – How to Export in Node.js and JavaScript
Each file in a Node.js project is treated as a module that can export values to be used by other modules. module.exports is...
Read more >
export - JavaScript - MDN Web Docs
The export declaration is used to export values from a JavaScript module. Exported values can then be imported into other programs with the ......
Read more >
Node.js Export Module - TutorialsTeacher
The module.exports is a special object which is included in every JavaScript file in the Node.js application by default. The module is a...
Read more >
Node.js Module Exports - Demystified - Stackify
Module exports are the instruction that tells Node.js which bits of code (functions, objects, strings, etc.) to “export” from a given file so ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found