Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@jsenv/url-meta

Package Overview
Dependencies
Maintainers
2
Versions
32
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@jsenv/url-meta

Associate data to urls using patterns

  • 6.2.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
237
decreased by-64.41%
Maintainers
2
Weekly downloads
 
Created
Source

url-meta npm package github ci codecov coverage

@jsenv/url-meta allows to associate value to urls using pattern matching.

import { urlToMeta } from "@jsenv/url-meta"

// conditionally associates url and values
const structuredMetaMap = {
  color: {
    "file:///*": "black",
    "file:///*.js": "red",
  },
}
const urlToColor = (url) => {
  return urlToMeta({ url, structuredMetaMap }).color
}
console.log(`file.json color is ${urlToColor("file:///file.json")}`)
console.log(`file.js color is ${urlToColor("file:///file.js")}`)

Code above logs

file.json color is black
file.js color is red

Common pattern example

patternDescription
**/Everything
*/**/Inside a directory
**/.*/Inside directory starting with a dot
**/node_modules/Inside any node_modules directory
node_modules/Inside root node_modules directory
**/*.mapEnding with .map
**/*.test.*Contains .test.
*Inside the root directory only
*/*Inside a directory of depth 1

Read more at ./docs/pattern_matching.md

metaMap and structuredMetaMap

metaMap and structuredMetaMap below translates into: "files are visible except thoose in .git/ directory"

const metaMap = {
  "**/*": { visible: true },
  "**/.git/": { visible: false },
}
const structuredMetaMap = {
  visible: {
    "**/*/": true,
    "**/.git/": false,
  },
}

structuredMetaMap allows to group patterns per property which are easier to read and compose. All keys in structuredMetaMap must be resolved against an url, this can be done with normalizeStructuredMetaMap.

normalizeStructuredMetaMap

normalizeStructuredMetaMap is a function resolving structuredMetaMap keys against an url.

import { normalizeStructuredMetaMap } from "@jsenv/url-meta"

const structuredMetaMapNormalized = normalizeStructuredMetaMap(
  {
    visible: {
      "**/*/": true,
      "**/.git/": false,
    },
  },
  "file:///Users/directory/",
)
console.log(JSON.stringify(structuredMetaMapNormalized, null, "  "))
{
  "visible": {
    "file:///Users/directory/**/*/": true,
    "file:///Users/directory/**/.git/": false
  }
}

Installation

npm install @jsenv/url-meta

Can be used in browsers and Node.js.

FAQs

Package last updated on 28 Jan 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc