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

hapi-locale-17

Package Overview
Dependencies
Maintainers
3
Versions
36
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

hapi-locale-17 - npm Package Compare versions

Comparing version 2.0.26 to 2.0.28

.github/workflows/main.yml

23

package.json
{
"name": "hapi-locale-17",
"version": "2.0.26",
"version": "2.0.28",
"description": "Locale and language detection for Hapi v17",

@@ -10,3 +10,3 @@ "main": "src/index.js",

"type": "git",
"url": "git://github.com/frankthelen/hapi-locale-17"
"url": "git://github.com/funny-bytes/hapi-locale-17"
},

@@ -22,3 +22,3 @@ "keywords": [

"lint": "eslint . --ignore-path ./.eslintignore",
"test": "NODE_ENV=test nyc --reporter=lcov --reporter=text-summary mocha --exit --recursive test",
"test": "jest --coverage test/*",
"coveralls": "nyc report --reporter=lcovonly && cat ./coverage/lcov.info | coveralls",

@@ -31,9 +31,7 @@ "preversion": "npm run lint && npm test"

"devDependencies": {
"chai": "^4.2.0",
"chai-as-promised": "^7.1.1",
"coveralls": "^3.1.0",
"eslint": "^7.16.0",
"coveralls": "^3.1.1",
"eslint": "^7.32.0",
"eslint-config-airbnb-base": "^14.2.1",
"eslint-plugin-import": "^2.22.1",
"eslint-plugin-promise": "^4.2.1",
"eslint-plugin-import": "^2.24.2",
"eslint-plugin-promise": "^5.1.0",
"eslint-plugin-should-promised": "^2.0.0",

@@ -43,7 +41,4 @@ "hapi18": "npm:@hapi/hapi@^18.4.0",

"hapi20": "npm:@hapi/hapi@^20.0.3",
"mocha": "^8.2.1",
"nyc": "^15.1.0",
"semver": "^7.3.4",
"sinon": "^9.2.2",
"sinon-chai": "^3.5.0"
"jest": "^27.1.0",
"semver": "^7.3.5"
},

@@ -50,0 +45,0 @@ "peerDependencies": {

@@ -5,6 +5,6 @@ # hapi-locale-17

[![Build Status](https://travis-ci.org/frankthelen/hapi-locale-17.svg?branch=master)](https://travis-ci.org/frankthelen/hapi-locale-17)
[![Coverage Status](https://coveralls.io/repos/github/frankthelen/hapi-locale-17/badge.svg?branch=master)](https://coveralls.io/github/frankthelen/hapi-locale-17?branch=master)
[![devDependencies Status](https://david-dm.org/frankthelen/hapi-locale-17/status.svg)](https://david-dm.org/frankthelen/hapi-locale-17)
[![Maintainability](https://api.codeclimate.com/v1/badges/2b21f79b2657870c146f/maintainability)](https://codeclimate.com/github/frankthelen/hapi-locale-17/maintainability)
![main workflow](https://github.com/funny-bytes/hapi-locale-17/actions/workflows/main.yml/badge.svg)
[![Coverage Status](https://coveralls.io/repos/github/funny-bytes/hapi-locale-17/badge.svg?branch=master)](https://coveralls.io/github/funny-bytes/hapi-locale-17?branch=master)
[![dependencies Status](https://david-dm.org/funny-bytes/hapi-locale-17/status.svg)](https://david-dm.org/funny-bytes/hapi-locale-17)
[![Maintainability](https://api.codeclimate.com/v1/badges/2b21f79b2657870c146f/maintainability)](https://codeclimate.com/github/funny-bytes/hapi-locale-17/maintainability)
[![node](https://img.shields.io/node/v/hapi-locale-17.svg)]()

@@ -11,0 +11,0 @@ [![code style](https://img.shields.io/badge/code_style-airbnb-brightgreen.svg)](https://github.com/airbnb/javascript)

@@ -1,5 +0,1 @@

const chai = require('chai');
const chaiAsPromised = require('chai-as-promised');
const sinon = require('sinon');
const sinonChai = require('sinon-chai');
const parser = require('accept-language-parser'); // to be mocked

@@ -9,10 +5,2 @@ const semver = require('semver');

chai.use(chaiAsPromised);
chai.use(sinonChai);
global.chai = chai;
global.sinon = sinon;
global.expect = chai.expect;
global.should = chai.should();
const nodeVersion = process.version;

@@ -27,3 +15,3 @@ const hapiVersions = semver.satisfies(nodeVersion, '>=12.x.x')

describe(`${hapiVersion}`, async () => {
describe(`${hapiVersion}`, () => {
async function setup(options = {}) {

@@ -56,3 +44,3 @@ const server = new Hapi.Server({

describe('hapi-locale-17 with `locales` option', async () => {
describe('hapi-locale-17 with `locales` option', () => {
let server;

@@ -70,74 +58,82 @@

it('should provide `request.getLocale()` with supported `de`', () => server
.inject({
url: '/test',
headers: {
'Accept-Language': 'de-DE,de;q=0.9,en-GB;q=0.8,en-US;q=0.7,en;q=0.6',
},
})
.should.be.fulfilled
.then((response) => expect(response.request.getLocale()).to.be.equal('de')));
it('should provide `request.getLocale()` with supported `de`', async () => {
const response = await server
.inject({
url: '/test',
headers: {
'Accept-Language': 'de-DE,de;q=0.9,en-GB;q=0.8,en-US;q=0.7,en;q=0.6',
},
});
const lcl = response.request.getLocale();
expect(lcl).toEqual('de');
});
it('should provide `request.getLocale()` with supported `de` / query param', () => server
.inject({
url: '/test?locale=de',
headers: {
'Accept-Language': 'en-GB;q=0.8,en-US;q=0.7,en;q=0.6',
},
})
.should.be.fulfilled
.then((response) => expect(response.request.getLocale()).to.be.equal('de')));
it('should provide `request.getLocale()` with supported `de` / query param', async () => {
const response = await server
.inject({
url: '/test?locale=de',
headers: {
'Accept-Language': 'en-GB;q=0.8,en-US;q=0.7,en;q=0.6',
},
});
expect(response.request.getLocale()).toEqual('de');
});
it('should provide `request.getLocale()` with supported `de` / path param', () => server
.inject({
url: '/media/de',
headers: {
'Accept-Language': 'en-GB;q=0.8,en-US;q=0.7,en;q=0.6',
},
})
.should.be.fulfilled
.then((response) => expect(response.request.getLocale()).to.be.equal('de')));
it('should provide `request.getLocale()` with supported `de` / path param', async () => {
const response = await server
.inject({
url: '/media/de',
headers: {
'Accept-Language': 'en-GB;q=0.8,en-US;q=0.7,en;q=0.6',
},
});
expect(response.request.getLocale()).toEqual('de');
});
it('should provide `request.getLocale()` with default `es` / query param with unsupported locale', () => server
.inject({
url: '/test?locale=tr',
headers: {
'Accept-Language': 'q=0.9,en-GB;q=0.8,en-US;q=0.7,en;q=0.6',
},
})
.should.be.fulfilled
.then((response) => expect(response.request.getLocale()).to.be.equal('es')));
it('should provide `request.getLocale()` with default `es` / query param with unsupported locale', async () => {
const response = await server
.inject({
url: '/test?locale=tr',
headers: {
'Accept-Language': 'q=0.9,en-GB;q=0.8,en-US;q=0.7,en;q=0.6',
},
});
expect(response.request.getLocale()).toEqual('es');
});
it('should provide `request.getLocale()` with default `es` / path param with unsupported locale', () => server
.inject({
url: '/media/tr',
headers: {
'Accept-Language': 'q=0.9,en-GB;q=0.8,en-US;q=0.7,en;q=0.6',
},
})
.should.be.fulfilled
.then((response) => expect(response.request.getLocale()).to.be.equal('es')));
it('should provide `request.getLocale()` with default `es` / path param with unsupported locale', async () => {
const response = await server
.inject({
url: '/media/tr',
headers: {
'Accept-Language': 'q=0.9,en-GB;q=0.8,en-US;q=0.7,en;q=0.6',
},
});
expect(response.request.getLocale()).toEqual('es');
});
it('should provide `request.getLocale()` with default `es` / no indocation', () => server
.inject({
url: '/test',
})
.should.be.fulfilled
.then((response) => expect(response.request.getLocale()).to.be.equal('es')));
it('should provide `request.getLocale()` with default `es` / no indocation', async () => {
const response = await server
.inject({
url: '/test',
});
expect(response.request.getLocale()).toEqual('es');
});
it('should provide `request.getLocale()` with default `es` / invalid header', () => server
.inject({
url: '/test',
headers: {
'Accept-Language': 'cq#brw/hdbjhfd,bkaq8ö?347r;z12lekw:vmcöar-fvic',
},
})
.should.be.fulfilled
.then((response) => expect(response.request.getLocale()).to.be.equal('es')));
it('should provide `request.getLocale()` with default `es` / invalid header', async () => {
const response = await server
.inject({
url: '/test',
headers: {
'Accept-Language': 'cq#brw/hdbjhfd,bkaq8ö?347r;z12lekw:vmcöar-fvic',
},
});
expect(response.request.getLocale()).toEqual('es');
});
});
describe('hapi-locale-17 with `method` option', async () => {
describe('hapi-locale-17 with `method` option', () => {
let server;
before(async () => {
beforeAll(async () => {
server = await setup({

@@ -149,21 +145,22 @@ locales: ['de', 'en'],

after(async () => {
afterAll(async () => {
await server.stop();
});
it('should provide user-defined `request.getLang()`', () => server
.inject({
url: '/test',
headers: {
'Accept-Language': 'en-GB;q=0.8,en-US;q=0.7,en;q=0.6',
},
})
.should.be.fulfilled
.then((response) => expect(response.request.getLang()).to.be.equal('en')));
it('should provide user-defined `request.getLang()`', async () => {
const response = await server
.inject({
url: '/test',
headers: {
'Accept-Language': 'en-GB;q=0.8,en-US;q=0.7,en;q=0.6',
},
});
expect(response.request.getLang()).toEqual('en');
});
});
describe('hapi-locale-17 with `query` option', async () => {
describe('hapi-locale-17 with `query` option', () => {
let server;
before(async () => {
beforeAll(async () => {
server = await setup({

@@ -177,21 +174,22 @@ locales: ['de', 'en'],

after(async () => {
afterAll(async () => {
await server.stop();
});
it('should accept user-defined query param `lang`', () => server
.inject({
url: '/test?lang=de',
headers: {
'Accept-Language': 'en-GB;q=0.8,en-US;q=0.7,en;q=0.6',
},
})
.should.be.fulfilled
.then((response) => expect(response.request.getLang()).to.be.equal('de')));
it('should accept user-defined query param `lang`', async () => {
const response = await server
.inject({
url: '/test?lang=de',
headers: {
'Accept-Language': 'en-GB;q=0.8,en-US;q=0.7,en;q=0.6',
},
});
expect(response.request.getLang()).toEqual('de');
});
});
describe('hapi-locale-17 with `path` option', async () => {
describe('hapi-locale-17 with `path` option', () => {
let server;
before(async () => {
beforeAll(async () => {
server = await setup({

@@ -205,21 +203,22 @@ locales: ['de', 'en'],

after(async () => {
afterAll(async () => {
await server.stop();
});
it('should accept user-defined path param `lang`', () => server
.inject({
url: '/media2/de',
headers: {
'Accept-Language': 'en-GB;q=0.8,en-US;q=0.7,en;q=0.6',
},
})
.should.be.fulfilled
.then((response) => expect(response.request.getLang()).to.be.equal('de')));
it('should accept user-defined path param `lang`', async () => {
const response = await server
.inject({
url: '/media2/de',
headers: {
'Accept-Language': 'en-GB;q=0.8,en-US;q=0.7,en;q=0.6',
},
});
expect(response.request.getLang()).toEqual('de');
});
});
describe('hapi-locale-17 with locale option `en-US`', async () => {
describe('hapi-locale-17 with locale option `en-US`', () => {
let server;
before(async () => {
beforeAll(async () => {
server = await setup({

@@ -230,53 +229,58 @@ locales: ['en-US', 'es'],

after(async () => {
afterAll(async () => {
await server.stop();
});
it('should accept locale `en-US`', () => server
.inject({
url: '/test',
headers: {
'Accept-Language': 'en-GB;q=0.8,en-US;q=0.7,en;q=0.6',
},
})
.should.be.fulfilled
.then((response) => expect(response.request.getLocale()).to.be.equal('en-US')));
it('should accept locale `en-US`', async () => {
const response = await server
.inject({
url: '/test',
headers: {
'Accept-Language': 'en-GB;q=0.8,en-US;q=0.7,en;q=0.6',
},
});
expect(response.request.getLocale()).toEqual('en-US');
});
it('should accept locale `en-US` / query param', () => server
.inject({
url: '/test?locale=en',
headers: {
'Accept-Language': 'es-ES,es;q=0.9,en-GB;q=0.8,en-US;q=0.7,en;q=0.6',
},
})
.should.be.fulfilled
.then((response) => expect(response.request.getLocale()).to.be.equal('en-US')));
it('should accept locale `en-US` / query param', async () => {
const response = await server
.inject({
url: '/test?locale=en',
headers: {
'Accept-Language': 'es-ES,es;q=0.9,en-GB;q=0.8,en-US;q=0.7,en;q=0.6',
},
});
expect(response.request.getLocale()).toEqual('en-US');
});
});
describe('hapi-locale-17 with error thrown by `accept-language-parser`', async () => {
describe('hapi-locale-17 with error thrown by `accept-language-parser`', () => {
let server;
before(async () => {
beforeAll(async () => {
server = await setup({
locales: ['en', 'es'],
});
sinon.stub(parser, 'pick').throws('Error');
jest.spyOn(parser, 'pick').mockImplementation(() => {
throw new Error('Error');
});
});
after(async () => {
afterAll(async () => {
await server.stop();
parser.pick.restore();
parser.pick.mockRestore();
});
it('should not fail and return default locale', () => server
.inject({
url: '/test',
headers: {
'Accept-Language': 'en-GB;q=0.8,en-US;q=0.7,en;q=0.6',
},
})
.should.be.fulfilled
.then((response) => expect(response.request.getLocale()).to.be.equal('en')));
it('should not fail and return default locale', async () => {
const response = await server
.inject({
url: '/test',
headers: {
'Accept-Language': 'en-GB;q=0.8,en-US;q=0.7,en;q=0.6',
},
});
expect(response.request.getLocale()).toEqual('en');
});
});
});
});

Sorry, the diff of this file is not supported yet

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