5.0.0 • Published 5 years ago

@dmail/project-structure v5.0.0

Weekly downloads
6
License
-
Repository
github
Last release
5 years ago

project-structure

npm package build codecov

Associate data to pathname using pattern.

Example

import { pathnameToMeta } from "@dmail/project-structure"

const metaDescription = {
  "/*.js": {
    extension: "js",
  },
  "/*.json": {
    extension: "json",
  },
  "/file.js": {
    foo: true,
  },
}

pathnameToMeta({ pathname: "/file.js", metaDescription }) // { extension: "js", foo: true }
pathnameToMeta({ pathname: "/file.json", metaDescription }) // { extension: "json" }

Pathname pattern matching

This repository use a special specification to match a pathname and a pattern. The concept is inspired from https://github.com/WICG/import-maps#specifier-remapping-examples. Import map speficiation gives a special meaning to trailing slash and is considering to add more powerful approach to match a pathname.

I need a more powerful approach. You can get an idea of how pattern matching behaves thanks to the following examples:

Pattern matching for /folder/.

pathnamematch
/folderfalse
/folder/true
/folder/file.jstrue

Pattern matching for /folder/*.js.

pathnamematch
/folderfalse
/folder/false
/folder/file.jstrue
/folder/data.jsonfalse

Pattern matching for /**/folder/*.js.

pathnamematch
/folder/file.jstrue
/foo/folder/file.jstrue
/folder/data.jsonfalse