Product
Introducing SSO
Streamline your login process and enhance security by enabling Single Sign-On (SSO) on the Socket platform, now available for all customers on the Enterprise plan, supporting 20+ identity providers.
sort-route-addresses
Advanced tools
Readme
For the purposes of this algorithm, a route address is a string containing:
ALL
) prefix, followed by a space, followed by:/
, followed by::
followed by any combination of letters and numbers (a "param"), OR*
(a "wildcard"), ORIn other words, any Sails-compatible route path.
Given an unordered list of route addresses:
Find the maximum number of parts (maxParts
) in any address, by ignoring the optional verb prefix and initial forward slash and splitting each address on the remaining /
characters.
For each address, construct a string (rank
) by examining each part in the address from left to right and:
1
to the string for each static path component2
to the string for each param component3
to the string for each wildcard componentmaxParts
parts, pad the string with 0
s if no wildcards were encountered, or 4
s if wildcards were encountered.0
to the end of the string if the address has a specific verb prefix (i.e. not ALL
), and a 1
if it has a ALL
prefix or no prefix.5
at the beginning of the string if the path has no static components1.Sort the addresses by their rank
, with lesser ranks coming before greater ones.
RANK ADDRESS
---- -----
1000 GET /foo
1001 /foo
1101 /foo/bar
1111 /foo/bar/baz
1120 GET /foo/bar/:baz
1121 /foo/bar/:baz
1130 GET /foo/bar/*
1131 /foo/bar/*
1201 /foo/:bar
1211 /foo/:bar/baz
1221 /foo/:bar/:baz
1311 /foo/*/baz
1341 /foo/*
2101 /:foo/bar
2111 /:foo/bar/baz
2121 /:foo/bar/:baz
2211 /:foo/:bar/baz
3111 /*/bar/baz
3131 /*/baz/*
3141 /*/baz
52001 /:foo
52201 /:foo/:bar
52221 /:foo/:bar/:baz
52231 /:foo/:bar/*
52341 /:foo/*
53440 GET /*
53441 /*
1: This ensures that addresses like /*/baz/*
are ranked above ones like /:foo/:bar/:baz
-- the static baz
component implies that the author intends for */baz/*
to handle request URLs of at least three components, one of which is baz
; if /:foo/:bar/:baz/
were ranked higher in the list, it would swallow the subset of those URLs with exactly three components.
If you have a question, need professional support, or just want to talk Sails/Node.js with other folks in the community, click here.
To report a bug, click here.
Please observe the guidelines and conventions laid out in the Sails project contribution guide when opening issues or submitting pull requests.
Like the Sails framework, this package is free and open-source under the MIT License.
FAQs
Sort Sails/Express-style route addresses by inclusivity
The npm package sort-route-addresses receives a total of 10,629 weekly downloads. As such, sort-route-addresses popularity was classified as popular.
We found that sort-route-addresses demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 4 open source maintainers collaborating on the project.
Did you know?
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.
Product
Streamline your login process and enhance security by enabling Single Sign-On (SSO) on the Socket platform, now available for all customers on the Enterprise plan, supporting 20+ identity providers.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.