Skip to content

Commit 6dc9851

Browse files
committed
license added
1 parent 70f510b commit 6dc9851

File tree

5 files changed

+41
-15
lines changed

5 files changed

+41
-15
lines changed

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2025 Rashedin Islam
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

__tests__/getStatusMessage.test.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,25 @@ describe('getStatusMessage', () => {
1010
expect(getStatusMessage(StatusCodes.INSUFFICIENT_STORAGE)).toBe(
1111
'Insufficient Storage'
1212
);
13-
expect(getStatusMessage(StatusCodes.MOVED_PERMANENTLY)).toBe('Moved Permanently');
14-
expect(getStatusMessage(StatusCodes.PERMANENT_REDIRECT)).toBe('Permanent Redirect');
13+
expect(getStatusMessage(StatusCodes.MOVED_PERMANENTLY)).toBe(
14+
'Moved Permanently'
15+
);
16+
expect(getStatusMessage(StatusCodes.PERMANENT_REDIRECT)).toBe(
17+
'Permanent Redirect'
18+
);
1519
});
1620

17-
18-
// check if it returns a long message
19-
it('should return a long message if long = true', () => {
21+
// check if it returns a detailed message
22+
it('should return a detailed message if detailed = true', () => {
2023
expect(getStatusMessage(StatusCodes.OK, true)).toMatch(/successful/i);
2124
expect(getStatusMessage(StatusCodes.CREATED, true)).toMatch(
22-
/successfully/i
25+
/has been created/i
2326
);
2427
expect(getStatusMessage(StatusCodes.NOT_FOUND, true)).toMatch(
25-
/cannot find/i
28+
/cannot locate/i
2629
);
2730
expect(getStatusMessage(StatusCodes.INSUFFICIENT_STORAGE, true)).toMatch(
28-
/unable to store/i
31+
/cannot store/i
2932
);
3033
expect(getStatusMessage(StatusCodes.MOVED_PERMANENTLY, true)).toMatch(
3134
/permanently moved /i
@@ -35,7 +38,6 @@ describe('getStatusMessage', () => {
3538
);
3639
});
3740

38-
3941
// check if it returns a "Unknown Status" for invalid code
4042
it('should return a "Unknown Status" for invalid code', () => {
4143
expect(getStatusMessage(999 as any)).toBe('Unknown Status');

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"require": "./dist/statusMessages.cjs",
2222
"types": "./dist/statusMessages.d.ts"
2323
},
24-
"./messages-long": {
24+
"./messages-detailed": {
2525
"import": "./dist/detailedStatusMessages.js",
2626
"require": "./dist/detailedStatusMessages.cjs",
2727
"types": "./dist/detailedStatusMessages.d.ts"

src/detailedStatusMessages.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
// generate long status message if required
2+
// generate detailed status message if required
33

44
export const DetailedStatusMessages = {
55
// --- 1xx: Informational ---

src/getStatusMessage.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
// import shortMessages from './shortStatusMessages';
2-
import { LongStatusMessages } from './detailedStatusMessages';
32
import type { StatusCode } from './statusCodes';
43
import { StatusMessages } from './statusMessages';
4+
import { DetailedStatusMessages } from './detailedStatusMessages';
55

6-
export function getStatusMessage(statusCode: StatusCode, long = false): string {
7-
return long
8-
? LongStatusMessages[statusCode] ?? 'Unknown Status'
6+
export function getStatusMessage(
7+
statusCode: StatusCode,
8+
detailed = false
9+
): string {
10+
return detailed
11+
? DetailedStatusMessages[statusCode] ?? 'Unknown Status'
912
: StatusMessages[statusCode] ?? 'Unknown Status';
1013
}

0 commit comments

Comments
 (0)