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

@jsenv/url-meta

Package Overview
Dependencies
Maintainers
0
Versions
32
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@jsenv/url-meta

Associate value to urls using pattern matching.

  • 8.5.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
0
Created
Source

url meta

Associate value to urls using pattern matching.

import { URL_META } from "@jsenv/url-meta";

// conditionally associates url and values
const associations = {
  color: {
    "file:///*": "black",
    "file:///*.js": "red",
  },
};
const getUrlColor = (url) => {
  const { color } = URL_META.applyAssociations({ url, associations });
  return color;
};
console.log(`file.json color is ${getUrlColor("file:///file.json")}`);
console.log(`file.js color is ${getUrlColor("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 ./pattern_matching.md

associations

associations below translates into: "files are visible except thoose in .git/ directory"

const associations = {
  visible: {
    "**/*/": true,
    "**/.git/": false,
  },
};

associations allows to group patterns per property which are easy to read and compose. All keys in associations must be absolute urls, this can be done with resolveAssociations.

resolveAssociations

resolveAssociations is a function resolving associations keys that may contain relative urls against an url.

import { URL_META } from "@jsenv/url-meta";

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

FAQs

Package last updated on 20 Aug 2024

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