Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
negotiator-currency
Advanced tools
An HTTP content negotiator for node.js written in javascript.
Negotiator = require('negotiator')
availableMediaTypes = ['text/html', 'text/plain', 'application/json']
// The negotiator constructor receives a request object
negotiator = new Negotiator(request)
// Let's say Accept header is 'text/html, application/*;q=0.2, image/jpeg;q=0.8'
negotiator.preferredMediaTypes()
// -> ['text/html', 'image/jpeg', 'application/*']
negotiator.preferredMediaTypes(availableMediaTypes)
// -> ['text/html', 'application/json']
negotiator.preferredMediaType(availableMediaTypes)
// -> 'text/html'
You can check a working example at examples/accept.js
.
preferredMediaTypes(availableMediaTypes)
:
Returns an array of preferred media types ordered by priority from a list of available media types.
preferredMediaType(availableMediaType)
:
Returns the top preferred media type from a list of available media types.
Negotiator = require('negotiator')
negotiator = new Negotiator(request)
availableLanguages = 'en', 'es', 'fr'
// Let's say Accept-Language header is 'en;q=0.8, es, pt'
negotiator.preferredLanguages()
// -> ['es', 'pt', 'en']
negotiator.preferredLanguages(availableLanguages)
// -> ['es', 'en']
language = negotiator.preferredLanguage(availableLanguages)
// -> 'es'
You can check a working example at examples/language.js
.
(WARNING: This is not an already standard header, so browsers don't actually send it, nor is planned to be a standard header)
Negotiator = require('negotiator')
negotiator = new Negotiator(request)
availableCurrencies = 'usd', 'eur', 'aud'
// Let's say Accept-Currency header is 'usd;q=0.8, eur, chf'
negotiator.preferredCurrencies()
// -> ['usd', 'eur', 'chf']
negotiator.preferredCurrencies(availableCurrencies)
// -> ['eur', 'usd']
currency = negotiator.preferredCurrency(availableCurrencies)
// -> 'eur'
You can check a working example at examples/currency.js
.
preferredLanguages(availableLanguages)
:
Returns an array of preferred languages ordered by priority from a list of available languages.
preferredLanguage(availableLanguages)
:
Returns the top preferred language from a list of available languages.
Negotiator = require('negotiator')
availableCharsets = ['utf-8', 'iso-8859-1', 'iso-8859-5']
negotiator = new Negotiator(request)
// Let's say Accept-Charset header is 'utf-8, iso-8859-1;q=0.8, utf-7;q=0.2'
negotiator.preferredCharsets()
// -> ['utf-8', 'iso-8859-1', 'utf-7']
negotiator.preferredCharsets(availableCharsets)
// -> ['utf-8', 'iso-8859-1']
negotiator.preferredCharset(availableCharsets)
// -> 'utf-8'
You can check a working example at examples/charset.js
.
preferredCharsets(availableCharsets)
:
Returns an array of preferred charsets ordered by priority from a list of available charsets.
preferredCharset(availableCharsets)
:
Returns the top preferred charset from a list of available charsets.
Negotiator = require('negotiator').Negotiator
availableEncodings = ['identity', 'gzip']
negotiator = new Negotiator(request)
// Let's say Accept-Encoding header is 'gzip, compress;q=0.2, identity;q=0.5'
negotiator.preferredEncodings()
// -> ['gzip', 'identity', 'compress']
negotiator.preferredEncodings(availableEncodings)
// -> ['gzip', 'identity']
negotiator.preferredEncoding(availableEncodings)
// -> 'gzip'
You can check a working example at examples/encoding.js
.
preferredEncodings(availableEncodings)
:
Returns an array of preferred encodings ordered by priority from a list of available encodings.
preferredEncoding(availableEncodings)
:
Returns the top preferred encoding from a list of available encodings.
MIT
FAQs
HTTP content negotiation (plus currency)
We found that negotiator-currency demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer 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.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.