update
This commit is contained in:
@@ -0,0 +1,3 @@
|
||||
declare function sign(x: number): number;
|
||||
|
||||
export = sign;
|
||||
@@ -0,0 +1,40 @@
|
||||
# Changelog
|
||||
|
||||
All notable changes to this project will be documented in this file.
|
||||
|
||||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
|
||||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||
|
||||
## [v2.0.2](https://github.com/inspect-js/hasOwn/compare/v2.0.1...v2.0.2) - 2024-03-10
|
||||
|
||||
### Commits
|
||||
|
||||
- [types] use shared config [`68e9d4d`](https://github.com/inspect-js/hasOwn/commit/68e9d4dab6facb4f05f02c6baea94a3f2a4e44b2)
|
||||
- [actions] remove redundant finisher; use reusable workflow [`241a68e`](https://github.com/inspect-js/hasOwn/commit/241a68e13ea1fe52bec5ba7f74144befc31fae7b)
|
||||
- [Tests] increase coverage [`4125c0d`](https://github.com/inspect-js/hasOwn/commit/4125c0d6121db56ae30e38346dfb0c000b04f0a7)
|
||||
- [Tests] skip `npm ls` in old node due to TS [`01b9282`](https://github.com/inspect-js/hasOwn/commit/01b92822f9971dea031eafdd14767df41d61c202)
|
||||
- [types] improve predicate type [`d340f85`](https://github.com/inspect-js/hasOwn/commit/d340f85ce02e286ef61096cbbb6697081d40a12b)
|
||||
- [Dev Deps] update `tape` [`70089fc`](https://github.com/inspect-js/hasOwn/commit/70089fcf544e64acc024cbe60f5a9b00acad86de)
|
||||
- [Tests] use `@arethetypeswrong/cli` [`50b272c`](https://github.com/inspect-js/hasOwn/commit/50b272c829f40d053a3dd91c9796e0ac0b2af084)
|
||||
|
||||
## [v2.0.1](https://github.com/inspect-js/hasOwn/compare/v2.0.0...v2.0.1) - 2024-02-10
|
||||
|
||||
### Commits
|
||||
|
||||
- [types] use a handwritten d.ts file; fix exported type [`012b989`](https://github.com/inspect-js/hasOwn/commit/012b9898ccf91dc441e2ebf594ff70270a5fda58)
|
||||
- [Dev Deps] update `@types/function-bind`, `@types/mock-property`, `@types/tape`, `aud`, `mock-property`, `npmignore`, `tape`, `typescript` [`977a56f`](https://github.com/inspect-js/hasOwn/commit/977a56f51a1f8b20566f3c471612137894644025)
|
||||
- [meta] add `sideEffects` flag [`3a60b7b`](https://github.com/inspect-js/hasOwn/commit/3a60b7bf42fccd8c605e5f145a6fcc83b13cb46f)
|
||||
|
||||
## [v2.0.0](https://github.com/inspect-js/hasOwn/compare/v1.0.1...v2.0.0) - 2023-10-19
|
||||
|
||||
### Commits
|
||||
|
||||
- revamped implementation, tests, readme [`72bf8b3`](https://github.com/inspect-js/hasOwn/commit/72bf8b338e77a638f0a290c63ffaed18339c36b4)
|
||||
- [meta] revamp package.json [`079775f`](https://github.com/inspect-js/hasOwn/commit/079775fb1ec72c1c6334069593617a0be3847458)
|
||||
- Only apps should have lockfiles [`6640e23`](https://github.com/inspect-js/hasOwn/commit/6640e233d1bb8b65260880f90787637db157d215)
|
||||
|
||||
## v1.0.1 - 2023-10-10
|
||||
|
||||
### Commits
|
||||
|
||||
- Initial commit [`8dbfde6`](https://github.com/inspect-js/hasOwn/commit/8dbfde6e8fb0ebb076fab38d138f2984eb340a62)
|
||||
@@ -0,0 +1,242 @@
|
||||
/*!
|
||||
* router
|
||||
* Copyright(c) 2013 Roman Shtylman
|
||||
* Copyright(c) 2014-2022 Douglas Christopher Wilson
|
||||
* MIT Licensed
|
||||
*/
|
||||
|
||||
'use strict'
|
||||
|
||||
/**
|
||||
* Module dependencies.
|
||||
* @private
|
||||
*/
|
||||
|
||||
const debug = require('debug')('router:route')
|
||||
const Layer = require('./layer')
|
||||
const { METHODS } = require('node:http')
|
||||
|
||||
/**
|
||||
* Module variables.
|
||||
* @private
|
||||
*/
|
||||
|
||||
const slice = Array.prototype.slice
|
||||
const flatten = Array.prototype.flat
|
||||
const methods = METHODS.map((method) => method.toLowerCase())
|
||||
|
||||
/**
|
||||
* Expose `Route`.
|
||||
*/
|
||||
|
||||
module.exports = Route
|
||||
|
||||
/**
|
||||
* Initialize `Route` with the given `path`,
|
||||
*
|
||||
* @param {String} path
|
||||
* @api private
|
||||
*/
|
||||
|
||||
function Route (path) {
|
||||
debug('new %o', path)
|
||||
this.path = path
|
||||
this.stack = []
|
||||
|
||||
// route handlers for various http methods
|
||||
this.methods = Object.create(null)
|
||||
}
|
||||
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
|
||||
Route.prototype._handlesMethod = function _handlesMethod (method) {
|
||||
if (this.methods._all) {
|
||||
return true
|
||||
}
|
||||
|
||||
// normalize name
|
||||
let name = typeof method === 'string'
|
||||
? method.toLowerCase()
|
||||
: method
|
||||
|
||||
if (name === 'head' && !this.methods.head) {
|
||||
name = 'get'
|
||||
}
|
||||
|
||||
return Boolean(this.methods[name])
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {array} supported HTTP methods
|
||||
* @private
|
||||
*/
|
||||
|
||||
Route.prototype._methods = function _methods () {
|
||||
const methods = Object.keys(this.methods)
|
||||
|
||||
// append automatic head
|
||||
if (this.methods.get && !this.methods.head) {
|
||||
methods.push('head')
|
||||
}
|
||||
|
||||
for (let i = 0; i < methods.length; i++) {
|
||||
// make upper case
|
||||
methods[i] = methods[i].toUpperCase()
|
||||
}
|
||||
|
||||
return methods
|
||||
}
|
||||
|
||||
/**
|
||||
* dispatch req, res into this route
|
||||
*
|
||||
* @private
|
||||
*/
|
||||
|
||||
Route.prototype.dispatch = function dispatch (req, res, done) {
|
||||
let idx = 0
|
||||
const stack = this.stack
|
||||
let sync = 0
|
||||
|
||||
if (stack.length === 0) {
|
||||
return done()
|
||||
}
|
||||
|
||||
let method = typeof req.method === 'string'
|
||||
? req.method.toLowerCase()
|
||||
: req.method
|
||||
|
||||
if (method === 'head' && !this.methods.head) {
|
||||
method = 'get'
|
||||
}
|
||||
|
||||
req.route = this
|
||||
|
||||
next()
|
||||
|
||||
function next (err) {
|
||||
// signal to exit route
|
||||
if (err && err === 'route') {
|
||||
return done()
|
||||
}
|
||||
|
||||
// signal to exit router
|
||||
if (err && err === 'router') {
|
||||
return done(err)
|
||||
}
|
||||
|
||||
// no more matching layers
|
||||
if (idx >= stack.length) {
|
||||
return done(err)
|
||||
}
|
||||
|
||||
// max sync stack
|
||||
if (++sync > 100) {
|
||||
return setImmediate(next, err)
|
||||
}
|
||||
|
||||
let layer
|
||||
let match
|
||||
|
||||
// find next matching layer
|
||||
while (match !== true && idx < stack.length) {
|
||||
layer = stack[idx++]
|
||||
match = !layer.method || layer.method === method
|
||||
}
|
||||
|
||||
// no match
|
||||
if (match !== true) {
|
||||
return done(err)
|
||||
}
|
||||
|
||||
if (err) {
|
||||
layer.handleError(err, req, res, next)
|
||||
} else {
|
||||
layer.handleRequest(req, res, next)
|
||||
}
|
||||
|
||||
sync = 0
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a handler for all HTTP verbs to this route.
|
||||
*
|
||||
* Behaves just like middleware and can respond or call `next`
|
||||
* to continue processing.
|
||||
*
|
||||
* You can use multiple `.all` call to add multiple handlers.
|
||||
*
|
||||
* function check_something(req, res, next){
|
||||
* next()
|
||||
* }
|
||||
*
|
||||
* function validate_user(req, res, next){
|
||||
* next()
|
||||
* }
|
||||
*
|
||||
* route
|
||||
* .all(validate_user)
|
||||
* .all(check_something)
|
||||
* .get(function(req, res, next){
|
||||
* res.send('hello world')
|
||||
* })
|
||||
*
|
||||
* @param {array|function} handler
|
||||
* @return {Route} for chaining
|
||||
* @api public
|
||||
*/
|
||||
|
||||
Route.prototype.all = function all (handler) {
|
||||
const callbacks = flatten.call(slice.call(arguments), Infinity)
|
||||
|
||||
if (callbacks.length === 0) {
|
||||
throw new TypeError('argument handler is required')
|
||||
}
|
||||
|
||||
for (let i = 0; i < callbacks.length; i++) {
|
||||
const fn = callbacks[i]
|
||||
|
||||
if (typeof fn !== 'function') {
|
||||
throw new TypeError('argument handler must be a function')
|
||||
}
|
||||
|
||||
const layer = Layer('/', {}, fn)
|
||||
layer.method = undefined
|
||||
|
||||
this.methods._all = true
|
||||
this.stack.push(layer)
|
||||
}
|
||||
|
||||
return this
|
||||
}
|
||||
|
||||
methods.forEach(function (method) {
|
||||
Route.prototype[method] = function (handler) {
|
||||
const callbacks = flatten.call(slice.call(arguments), Infinity)
|
||||
|
||||
if (callbacks.length === 0) {
|
||||
throw new TypeError('argument handler is required')
|
||||
}
|
||||
|
||||
for (let i = 0; i < callbacks.length; i++) {
|
||||
const fn = callbacks[i]
|
||||
|
||||
if (typeof fn !== 'function') {
|
||||
throw new TypeError('argument handler must be a function')
|
||||
}
|
||||
|
||||
debug('%s %s', method, this.path)
|
||||
|
||||
const layer = Layer('/', {}, fn)
|
||||
layer.method = method
|
||||
|
||||
this.methods[method] = true
|
||||
this.stack.push(layer)
|
||||
}
|
||||
|
||||
return this
|
||||
}
|
||||
})
|
||||
@@ -0,0 +1,3 @@
|
||||
declare function isFinite(x: unknown): x is number | bigint;
|
||||
|
||||
export = isFinite;
|
||||
@@ -0,0 +1,290 @@
|
||||
"use strict";
|
||||
var Buffer = require("safer-buffer").Buffer;
|
||||
|
||||
// UTF-7 codec, according to https://tools.ietf.org/html/rfc2152
|
||||
// See also below a UTF-7-IMAP codec, according to http://tools.ietf.org/html/rfc3501#section-5.1.3
|
||||
|
||||
exports.utf7 = Utf7Codec;
|
||||
exports.unicode11utf7 = 'utf7'; // Alias UNICODE-1-1-UTF-7
|
||||
function Utf7Codec(codecOptions, iconv) {
|
||||
this.iconv = iconv;
|
||||
};
|
||||
|
||||
Utf7Codec.prototype.encoder = Utf7Encoder;
|
||||
Utf7Codec.prototype.decoder = Utf7Decoder;
|
||||
Utf7Codec.prototype.bomAware = true;
|
||||
|
||||
|
||||
// -- Encoding
|
||||
|
||||
var nonDirectChars = /[^A-Za-z0-9'\(\),-\.\/:\? \n\r\t]+/g;
|
||||
|
||||
function Utf7Encoder(options, codec) {
|
||||
this.iconv = codec.iconv;
|
||||
}
|
||||
|
||||
Utf7Encoder.prototype.write = function(str) {
|
||||
// Naive implementation.
|
||||
// Non-direct chars are encoded as "+<base64>-"; single "+" char is encoded as "+-".
|
||||
return Buffer.from(str.replace(nonDirectChars, function(chunk) {
|
||||
return "+" + (chunk === '+' ? '' :
|
||||
this.iconv.encode(chunk, 'utf16-be').toString('base64').replace(/=+$/, ''))
|
||||
+ "-";
|
||||
}.bind(this)));
|
||||
}
|
||||
|
||||
Utf7Encoder.prototype.end = function() {
|
||||
}
|
||||
|
||||
|
||||
// -- Decoding
|
||||
|
||||
function Utf7Decoder(options, codec) {
|
||||
this.iconv = codec.iconv;
|
||||
this.inBase64 = false;
|
||||
this.base64Accum = '';
|
||||
}
|
||||
|
||||
var base64Regex = /[A-Za-z0-9\/+]/;
|
||||
var base64Chars = [];
|
||||
for (var i = 0; i < 256; i++)
|
||||
base64Chars[i] = base64Regex.test(String.fromCharCode(i));
|
||||
|
||||
var plusChar = '+'.charCodeAt(0),
|
||||
minusChar = '-'.charCodeAt(0),
|
||||
andChar = '&'.charCodeAt(0);
|
||||
|
||||
Utf7Decoder.prototype.write = function(buf) {
|
||||
var res = "", lastI = 0,
|
||||
inBase64 = this.inBase64,
|
||||
base64Accum = this.base64Accum;
|
||||
|
||||
// The decoder is more involved as we must handle chunks in stream.
|
||||
|
||||
for (var i = 0; i < buf.length; i++) {
|
||||
if (!inBase64) { // We're in direct mode.
|
||||
// Write direct chars until '+'
|
||||
if (buf[i] == plusChar) {
|
||||
res += this.iconv.decode(buf.slice(lastI, i), "ascii"); // Write direct chars.
|
||||
lastI = i+1;
|
||||
inBase64 = true;
|
||||
}
|
||||
} else { // We decode base64.
|
||||
if (!base64Chars[buf[i]]) { // Base64 ended.
|
||||
if (i == lastI && buf[i] == minusChar) {// "+-" -> "+"
|
||||
res += "+";
|
||||
} else {
|
||||
var b64str = base64Accum + this.iconv.decode(buf.slice(lastI, i), "ascii");
|
||||
res += this.iconv.decode(Buffer.from(b64str, 'base64'), "utf16-be");
|
||||
}
|
||||
|
||||
if (buf[i] != minusChar) // Minus is absorbed after base64.
|
||||
i--;
|
||||
|
||||
lastI = i+1;
|
||||
inBase64 = false;
|
||||
base64Accum = '';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!inBase64) {
|
||||
res += this.iconv.decode(buf.slice(lastI), "ascii"); // Write direct chars.
|
||||
} else {
|
||||
var b64str = base64Accum + this.iconv.decode(buf.slice(lastI), "ascii");
|
||||
|
||||
var canBeDecoded = b64str.length - (b64str.length % 8); // Minimal chunk: 2 quads -> 2x3 bytes -> 3 chars.
|
||||
base64Accum = b64str.slice(canBeDecoded); // The rest will be decoded in future.
|
||||
b64str = b64str.slice(0, canBeDecoded);
|
||||
|
||||
res += this.iconv.decode(Buffer.from(b64str, 'base64'), "utf16-be");
|
||||
}
|
||||
|
||||
this.inBase64 = inBase64;
|
||||
this.base64Accum = base64Accum;
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
Utf7Decoder.prototype.end = function() {
|
||||
var res = "";
|
||||
if (this.inBase64 && this.base64Accum.length > 0)
|
||||
res = this.iconv.decode(Buffer.from(this.base64Accum, 'base64'), "utf16-be");
|
||||
|
||||
this.inBase64 = false;
|
||||
this.base64Accum = '';
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
// UTF-7-IMAP codec.
|
||||
// RFC3501 Sec. 5.1.3 Modified UTF-7 (http://tools.ietf.org/html/rfc3501#section-5.1.3)
|
||||
// Differences:
|
||||
// * Base64 part is started by "&" instead of "+"
|
||||
// * Direct characters are 0x20-0x7E, except "&" (0x26)
|
||||
// * In Base64, "," is used instead of "/"
|
||||
// * Base64 must not be used to represent direct characters.
|
||||
// * No implicit shift back from Base64 (should always end with '-')
|
||||
// * String must end in non-shifted position.
|
||||
// * "-&" while in base64 is not allowed.
|
||||
|
||||
|
||||
exports.utf7imap = Utf7IMAPCodec;
|
||||
function Utf7IMAPCodec(codecOptions, iconv) {
|
||||
this.iconv = iconv;
|
||||
};
|
||||
|
||||
Utf7IMAPCodec.prototype.encoder = Utf7IMAPEncoder;
|
||||
Utf7IMAPCodec.prototype.decoder = Utf7IMAPDecoder;
|
||||
Utf7IMAPCodec.prototype.bomAware = true;
|
||||
|
||||
|
||||
// -- Encoding
|
||||
|
||||
function Utf7IMAPEncoder(options, codec) {
|
||||
this.iconv = codec.iconv;
|
||||
this.inBase64 = false;
|
||||
this.base64Accum = Buffer.alloc(6);
|
||||
this.base64AccumIdx = 0;
|
||||
}
|
||||
|
||||
Utf7IMAPEncoder.prototype.write = function(str) {
|
||||
var inBase64 = this.inBase64,
|
||||
base64Accum = this.base64Accum,
|
||||
base64AccumIdx = this.base64AccumIdx,
|
||||
buf = Buffer.alloc(str.length*5 + 10), bufIdx = 0;
|
||||
|
||||
for (var i = 0; i < str.length; i++) {
|
||||
var uChar = str.charCodeAt(i);
|
||||
if (0x20 <= uChar && uChar <= 0x7E) { // Direct character or '&'.
|
||||
if (inBase64) {
|
||||
if (base64AccumIdx > 0) {
|
||||
bufIdx += buf.write(base64Accum.slice(0, base64AccumIdx).toString('base64').replace(/\//g, ',').replace(/=+$/, ''), bufIdx);
|
||||
base64AccumIdx = 0;
|
||||
}
|
||||
|
||||
buf[bufIdx++] = minusChar; // Write '-', then go to direct mode.
|
||||
inBase64 = false;
|
||||
}
|
||||
|
||||
if (!inBase64) {
|
||||
buf[bufIdx++] = uChar; // Write direct character
|
||||
|
||||
if (uChar === andChar) // Ampersand -> '&-'
|
||||
buf[bufIdx++] = minusChar;
|
||||
}
|
||||
|
||||
} else { // Non-direct character
|
||||
if (!inBase64) {
|
||||
buf[bufIdx++] = andChar; // Write '&', then go to base64 mode.
|
||||
inBase64 = true;
|
||||
}
|
||||
if (inBase64) {
|
||||
base64Accum[base64AccumIdx++] = uChar >> 8;
|
||||
base64Accum[base64AccumIdx++] = uChar & 0xFF;
|
||||
|
||||
if (base64AccumIdx == base64Accum.length) {
|
||||
bufIdx += buf.write(base64Accum.toString('base64').replace(/\//g, ','), bufIdx);
|
||||
base64AccumIdx = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this.inBase64 = inBase64;
|
||||
this.base64AccumIdx = base64AccumIdx;
|
||||
|
||||
return buf.slice(0, bufIdx);
|
||||
}
|
||||
|
||||
Utf7IMAPEncoder.prototype.end = function() {
|
||||
var buf = Buffer.alloc(10), bufIdx = 0;
|
||||
if (this.inBase64) {
|
||||
if (this.base64AccumIdx > 0) {
|
||||
bufIdx += buf.write(this.base64Accum.slice(0, this.base64AccumIdx).toString('base64').replace(/\//g, ',').replace(/=+$/, ''), bufIdx);
|
||||
this.base64AccumIdx = 0;
|
||||
}
|
||||
|
||||
buf[bufIdx++] = minusChar; // Write '-', then go to direct mode.
|
||||
this.inBase64 = false;
|
||||
}
|
||||
|
||||
return buf.slice(0, bufIdx);
|
||||
}
|
||||
|
||||
|
||||
// -- Decoding
|
||||
|
||||
function Utf7IMAPDecoder(options, codec) {
|
||||
this.iconv = codec.iconv;
|
||||
this.inBase64 = false;
|
||||
this.base64Accum = '';
|
||||
}
|
||||
|
||||
var base64IMAPChars = base64Chars.slice();
|
||||
base64IMAPChars[','.charCodeAt(0)] = true;
|
||||
|
||||
Utf7IMAPDecoder.prototype.write = function(buf) {
|
||||
var res = "", lastI = 0,
|
||||
inBase64 = this.inBase64,
|
||||
base64Accum = this.base64Accum;
|
||||
|
||||
// The decoder is more involved as we must handle chunks in stream.
|
||||
// It is forgiving, closer to standard UTF-7 (for example, '-' is optional at the end).
|
||||
|
||||
for (var i = 0; i < buf.length; i++) {
|
||||
if (!inBase64) { // We're in direct mode.
|
||||
// Write direct chars until '&'
|
||||
if (buf[i] == andChar) {
|
||||
res += this.iconv.decode(buf.slice(lastI, i), "ascii"); // Write direct chars.
|
||||
lastI = i+1;
|
||||
inBase64 = true;
|
||||
}
|
||||
} else { // We decode base64.
|
||||
if (!base64IMAPChars[buf[i]]) { // Base64 ended.
|
||||
if (i == lastI && buf[i] == minusChar) { // "&-" -> "&"
|
||||
res += "&";
|
||||
} else {
|
||||
var b64str = base64Accum + this.iconv.decode(buf.slice(lastI, i), "ascii").replace(/,/g, '/');
|
||||
res += this.iconv.decode(Buffer.from(b64str, 'base64'), "utf16-be");
|
||||
}
|
||||
|
||||
if (buf[i] != minusChar) // Minus may be absorbed after base64.
|
||||
i--;
|
||||
|
||||
lastI = i+1;
|
||||
inBase64 = false;
|
||||
base64Accum = '';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!inBase64) {
|
||||
res += this.iconv.decode(buf.slice(lastI), "ascii"); // Write direct chars.
|
||||
} else {
|
||||
var b64str = base64Accum + this.iconv.decode(buf.slice(lastI), "ascii").replace(/,/g, '/');
|
||||
|
||||
var canBeDecoded = b64str.length - (b64str.length % 8); // Minimal chunk: 2 quads -> 2x3 bytes -> 3 chars.
|
||||
base64Accum = b64str.slice(canBeDecoded); // The rest will be decoded in future.
|
||||
b64str = b64str.slice(0, canBeDecoded);
|
||||
|
||||
res += this.iconv.decode(Buffer.from(b64str, 'base64'), "utf16-be");
|
||||
}
|
||||
|
||||
this.inBase64 = inBase64;
|
||||
this.base64Accum = base64Accum;
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
Utf7IMAPDecoder.prototype.end = function() {
|
||||
var res = "";
|
||||
if (this.inBase64 && this.base64Accum.length > 0)
|
||||
res = this.iconv.decode(Buffer.from(this.base64Accum, 'base64'), "utf16-be");
|
||||
|
||||
this.inBase64 = false;
|
||||
this.base64Accum = '';
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user