pathval icon indicating copy to clipboard operation
pathval copied to clipboard

Feature suggestion: alternate path separator to '.'

Open Offirmo opened this issue 10 months ago • 4 comments

I'm trying to auto-generate package.json files:

The new "exports" syntax has dots . in the key itself.

I tried using pathval and obviously couldn't set a deep export entry: setPathValue(pkg_json, 'exports..', './index.js');

I ended up coding my own utility which allows an alternate separator | and will automatically pick it if the key starts with it: setPathValue(pkg_json, '|exports|.', './index.js');

I understand that my use case may not be the one from this package.

This is a friendly sharing + helping future users. Feel free to mark this issue as resolved.

Offirmo avatar Apr 16 '25 03:04 Offirmo

And thanks for the lib and for chai 👏

Offirmo avatar Apr 16 '25 03:04 Offirmo

i wonder if we should make it possible to pass an array of parts, setPathValue(obj, ['foo', '.', 'bar']) etc

43081j avatar Apr 16 '25 08:04 43081j

@43081j good idea, but in my personal use case, I wanted the key/value to be storable in a JSON, ex.

{
  overrides: {
    package_json: {
      '|exports|.', './index.js',
    },
  },
},

hence the need for (string -> string)

Once again, I understand that my use case may be very specific.

Offirmo avatar Apr 16 '25 09:04 Offirmo

we already supported escaped dots it seems!

you can do this:

setPathValue(obj, 'exports.\\.');

. to separate keys, \\. is a key itself

43081j avatar Apr 16 '25 12:04 43081j