Skip to content
/ make-path Public

Defines and enforces an array-based "path" convention."

Notifications You must be signed in to change notification settings

akbr/make-path

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 

Repository files navigation

makePath 〰️

Defines and enforces an array-based "path" convention.

A path is an array intended to be interpreted as a list of keys. Useful for nesting into javascript objects.

API

makePath(input) => path

Valid input:

  • a string (splits on periods);
  • a number;
  • an array (simply returned).

Invalid input returns an empty path.

Usage

makePath("id"); // ["id"]
makePath("users.0.name"); // ["users", "0", "name"]
makePath(1); // [1]
makePath(["foo", "bar"]); // ["foo", "bar"]
makePath({foo:"bar"}); // []

Changelog

1.0.1 - Invalid input now returns an empty path.

About

Defines and enforces an array-based "path" convention."

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published