cloudfunctions/SegmentPortraitPic/node_modules/bson/src/objectid.ts
(开头部分) 9KB这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。
import { Buffer } from 'buffer';
import { ensureBuffer } from './ensure_buffer';
import { BSONTypeError } from './error';
import { deprecate, isUint8Array, randomBytes } from './parser/utils';
// Regular expression that checks for hex value
const checkForHexRegExp = new RegExp('^[0-9a-fA-F]{24}$');
// Unique sequence for the current process (initialized on first use)
let PROCESS_UNIQUE: Uint8Array | null = null;
/** @public */
export interface ObjectIdLike {
id: string | Buffer;
__id?: string;
toHexString(): string;
}
/** @public */
export interface ObjectIdExtended {
$oid: string;
}
const kId = Symbol('id');
/**
* A class representation of the BSON ObjectId type.
* @public
*/
export class ObjectId {
_bsontype!: 'ObjectId';
/** @internal */
static index = Math.floor(Math.random() * 0xffffff);
static cacheHexString: boolean;
/** ObjectId Bytes @internal */
private [kId]: Buffer;
/** ObjectId hexString cache @internal */
private __id?: string;
/**
* Create an ObjectId type
*
* @param inputId - Can be a 24 character hex string, 12 byte binary Buffer, or a number.
*/
constructor(inputId?: string | number | ObjectId | ObjectIdLike | Buffer | Uint8Array) {
if (!(this instanceof ObjectId)) return new ObjectId(inputId);
// workingId is set based on type of input and whether valid id exists for the input
let workingId;
if (typeof inputId === 'object' && inputId && 'id' in inputId) {
if (typeof inputId.id !== 'string' && !ArrayBuffer.isView(inputId.id)) {
throw new BSONTypeError(
'Argument passed in must have an id that is of type string or Buffer'
);
}
if ('toHexString' in inputId && typeof inputId.toHexString === 'function') {
workingId = Buffer.from(inputId.toHexString(), 'hex');
后面还有 290 行代码,购买后查看完整代码
24 小时内免费解锁 3 个项目,之后 1 积分/个。 规则说明
AI 解读
登录后可用,每次 10 积分,解读结果公开显示在下面。
还没有人解读过这个文件。
