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

pattern-key-compare

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pattern-key-compare

PATTERN_KEY_COMPARE implementation

  • 2.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
8.6K
decreased by-23.71%
Maintainers
1
Weekly downloads
 
Created
Source

pattern-key-compare

NPM version NPM downloads Codecov

Implementation of PATTERN_KEY_COMPARE of Node.js resolver algorithm.

It implements the updated algorithm:

PATTERN_KEY_COMPARE(keyA, keyB)

  1. Assert: keyA contains only a single "*".
  2. Assert: keyB contains only a single "*".
  3. Let baseLengthA be the index of "*" in keyA plus one.
  4. Let baseLengthB be the index of "*" in keyB plus one.
  5. If baseLengthA is greater than baseLengthB, return -1.
  6. If baseLengthB is greater than baseLengthA, return 1.
  7. If the length of keyA is greater than the length of keyB, return -1.
  8. If the length of keyB is greater than the length of keyA, return 1.
  9. Return 0.

Notes

Assert: keyA/B ends with "/" or contains only a single "*"

Note that this is not correct as nowadays it supports file extensions. e.g.:

  • #a/b.js
  • ./foo/*.js

Install

# npm
npm install pattern-key-compare

# yarn
yarn add pattern-key-compare

# pnpm
pnpm add pattern-key-compare

# rush
rush add -p pattern-key-compare

Usage

import { patternKeyCompare } from 'pattern-key-compare'

[...].sort(patternKeyCompare)

Keywords

FAQs

Package last updated on 03 Jan 2023

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