1.0.11 • Published 1 year ago
quick-status v1.0.11
Quick-Status codes for Node.js
Utility to interact with HTTP status codes.
Example usage
IntelliSense will help quick seaching for status codes and messages.
const qs = require('quick-status');
//import { qs } from 'quick-status';
//...
try {
console.log(qs.INSUFFICIENT_SPACE_ON_RESOURCE_419); //output: 419
console.log(qs.no.419); //=> 419
console.log(qs.msg.INSUFFICIENT_SPACE_ON_RESOURCE_419); //=> 'Insufficient Space on Resource'
console.log(qs.msg.no.419); //=> 'Insufficient Space on Resource'
throw new Error(qs.msg.INSUFFICIENT_SPACE_ON_RESOURCE_419);
//send 'Insufficient Space on Resource' to constructor of Error class
} catch (err) { //if typescript use: catch(err: any)
console.log(err.message); //=>: 'Insufficient Space on Resource'
console.log(qs.msg.getCode(err.message)); //=> 419
console.log(qs.msg.slugify(err.message)); //=> 'Insufficient_Space_on_Resource'
console.log(qs.msg.SLUGIFY(err.message)); //=> 'INSUFFICIENT_SPACE_ON_RESOURCE'
console.log(qs.msg.slugify(err.message, '/')); //=> 'Insufficient/Space/on/Resource'
console.log(qs.msg.SLUGIFY(err.message, '/')); //=> 'INSUFFICIENT/SPACE/ON/RESOURCE'
throw err;
}
Example usage
If you would not like to use qs for object name, you may use QuickStatus Class(Singleton) and naming it by yourself.
import QuickStatus from 'quick-status';
const yourVarName = new QuickStatus().getReadOnlyCode();
console.log(yourVarName.INSUFFICIENT_SPACE_ON_RESOURCE_419);