diff --git a/.eslintignore b/.eslintignore index b0ff90ab5..28fd088fa 100644 --- a/.eslintignore +++ b/.eslintignore @@ -8,8 +8,6 @@ lib/deep-equal/* lib/prelude.js lib/polyfill.js lib/tape-adapter.js -lib/tsd-jsdoc/* -lib/*/tests/* sandbox/* scripts/* tests/* diff --git a/cli/package-lock.json b/cli/package-lock.json index 273132494..ccf260d58 100644 --- a/cli/package-lock.json +++ b/cli/package-lock.json @@ -17,70 +17,6 @@ "lodash": "^4.17.21" } }, - "@protobufjs/aspromise": { - "version": "1.1.2", - "resolved": "https://registry.npmjs.org/@protobufjs/aspromise/-/aspromise-1.1.2.tgz", - "integrity": "sha512-j+gKExEuLmKwvz3OgROXtrJ2UG2x8Ch2YZUxahh+s1F2HZ+wAceUNLkvy6zKCPVRkU++ZWQrdxsUeQXmcg4uoQ==", - "dev": true - }, - "@protobufjs/base64": { - "version": "1.1.2", - "resolved": "https://registry.npmjs.org/@protobufjs/base64/-/base64-1.1.2.tgz", - "integrity": "sha512-AZkcAA5vnN/v4PDqKyMR5lx7hZttPDgClv83E//FMNhR2TMcLUhfRUBHCmSl0oi9zMgDDqRUJkSxO3wm85+XLg==", - "dev": true - }, - "@protobufjs/codegen": { - "version": "2.0.4", - "resolved": "https://registry.npmjs.org/@protobufjs/codegen/-/codegen-2.0.4.tgz", - "integrity": "sha512-YyFaikqM5sH0ziFZCN3xDC7zeGaB/d0IUb9CATugHWbd1FRFwWwt4ld4OYMPWu5a3Xe01mGAULCdqhMlPl29Jg==", - "dev": true - }, - "@protobufjs/eventemitter": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/@protobufjs/eventemitter/-/eventemitter-1.1.0.tgz", - "integrity": "sha512-j9ednRT81vYJ9OfVuXG6ERSTdEL1xVsNgqpkxMsbIabzSo3goCjDIveeGv5d03om39ML71RdmrGNjG5SReBP/Q==", - "dev": true - }, - "@protobufjs/fetch": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/@protobufjs/fetch/-/fetch-1.1.0.tgz", - "integrity": "sha512-lljVXpqXebpsijW71PZaCYeIcE5on1w5DlQy5WH6GLbFryLUrBD4932W/E2BSpfRJWseIL4v/KPgBFxDOIdKpQ==", - "dev": true, - "requires": { - "@protobufjs/aspromise": "^1.1.1", - "@protobufjs/inquire": "^1.1.0" - } - }, - "@protobufjs/float": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/@protobufjs/float/-/float-1.0.2.tgz", - "integrity": "sha512-Ddb+kVXlXst9d+R9PfTIxh1EdNkgoRe5tOX6t01f1lYWOvJnSPDBlG241QLzcyPdoNTsblLUdujGSE4RzrTZGQ==", - "dev": true - }, - "@protobufjs/inquire": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/@protobufjs/inquire/-/inquire-1.1.0.tgz", - "integrity": "sha512-kdSefcPdruJiFMVSbn801t4vFK7KB/5gd2fYvrxhuJYg8ILrmn9SKSX2tZdV6V+ksulWqS7aXjBcRXl3wHoD9Q==", - "dev": true - }, - "@protobufjs/path": { - "version": "1.1.2", - "resolved": "https://registry.npmjs.org/@protobufjs/path/-/path-1.1.2.tgz", - "integrity": "sha512-6JOcJ5Tm08dOHAbdR3GrvP+yUUfkjG5ePsHYczMFLq3ZmMkAD98cDgcT2iA1lJ9NVwFd4tH/iSSoe44YWkltEA==", - "dev": true - }, - "@protobufjs/pool": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/@protobufjs/pool/-/pool-1.1.0.tgz", - "integrity": "sha512-0kELaGSIDBKvcgS4zkjz1PeddatrjYcmMWOlAuAPwAeccUrPHdUqo/J6LiymHHEiJT5NrF1UVwxY14f+fy4WQw==", - "dev": true - }, - "@protobufjs/utf8": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/@protobufjs/utf8/-/utf8-1.1.0.tgz", - "integrity": "sha512-Vvn3zZrhQZkkBE8LSuW3em98c0FwgO4nxzv6OdSxPKJIEKY2bGbHn+mhGIPerzI4twdxaP8/0+06HBpwf345Lw==", - "dev": true - }, "@types/linkify-it": { "version": "3.0.2", "resolved": "https://registry.npmjs.org/@types/linkify-it/-/linkify-it-3.0.2.tgz", diff --git a/config/jsdoc.json b/config/jsdoc.json index 7b7d00511..a396c95ca 100644 --- a/config/jsdoc.json +++ b/config/jsdoc.json @@ -4,16 +4,7 @@ }, "source": { "include": [ - "./src/", - "./lib/aspromise/index.js", - "./lib/base64/index.js", - "./lib/codegen/index.js", - "./lib/eventemitter/index.js", - "./lib/fetch/index.js", - "./lib/inquire/index.js", - "./lib/path/index.js", - "./lib/pool/index.js", - "./lib/utf8/index.js" + "./src/" ], "exclude": [], "includePattern": ".+\\.js(doc)?$", diff --git a/index.d.ts b/index.d.ts index 9161111ed..d29116583 100644 --- a/index.d.ts +++ b/index.d.ts @@ -1274,9 +1274,10 @@ export class Reader { /** * Skips the next element of the specified wire type. * @param wireType Wire type received + * @param [depth] Depth of recursion to control nested calls; 0 if omitted * @returns `this` */ - public skipType(wireType: number): Reader; + public skipType(wireType: number, depth?: number): Reader; } /** Wire format reader using node buffers. */ @@ -1900,6 +1901,45 @@ export interface Constructor extends Function { /** Properties type. */ type Properties = { [P in keyof T]?: T[P] }; +/** + * Callback as used by {@link util.asPromise}. + * @param error Error, if any + * @param params Additional arguments + */ +type asPromiseCallback = (error: (Error|null), ...params: any[]) => void; + +/** + * Appends code to the function's body or finishes generation. + * @param [formatStringOrScope] Format string or, to finish the function, an object of additional scope variables, if any + * @param [formatParams] Format parameters + * @returns Itself or the generated function if finished + * @throws {Error} If format parameter counts do not match + */ +type Codegen = (formatStringOrScope?: (string|{ [k: string]: any }), ...formatParams: any[]) => (Codegen|Function); + +/** + * Event listener as used by {@link util.EventEmitter}. + * @param args Arguments + */ +type EventEmitterListener = (...args: any[]) => void; + +/** + * Node-style callback as used by {@link util.fetch}. + * @param error Error, if any, otherwise `null` + * @param [contents] File contents, if there hasn't been an error + */ +type FetchCallback = (error: Error, contents?: string) => void; + +/** Options as used by {@link util.fetch}. */ +export interface IFetchOptions { + + /** Whether expecting a binary response */ + binary?: boolean; + + /** If `true`, forces the use of XMLHttpRequest */ + xhr?: boolean; +} + /** * Any compatible Buffer instance. * This is a minimal stand-alone definition of a Buffer instance. The actual type is that exported by node's typings. @@ -1935,9 +1975,221 @@ type OneOfGetter = () => (string|undefined); */ type OneOfSetter = (value: (string|undefined)) => void; +/** + * An allocator as used by {@link util.pool}. + * @param size Buffer size + * @returns Buffer + */ +type PoolAllocator = (size: number) => Uint8Array; + +/** + * A slicer as used by {@link util.pool}. + * @param start Start offset + * @param end End offset + * @returns Buffer slice + */ +type PoolSlicer = (this: Uint8Array, start: number, end: number) => Uint8Array; + /** Various utility functions. */ export namespace util { + /** + * Returns a promise from a node-style callback function. + * @param fn Function to call + * @param ctx Function context + * @param params Function arguments + * @returns Promisified function + */ + function asPromise(fn: asPromiseCallback, ctx: any, ...params: any[]): Promise; + + /** A minimal base64 implementation for number arrays. */ + namespace base64 { + + /** + * Calculates the byte length of a base64 encoded string. + * @param string Base64 encoded string + * @returns Byte length + */ + function length(string: string): number; + + /** + * Encodes a buffer to a base64 encoded string. + * @param buffer Source buffer + * @param start Source start + * @param end Source end + * @returns Base64 encoded string + */ + function encode(buffer: Uint8Array, start: number, end: number): string; + + /** + * Decodes a base64 encoded string to a buffer. + * @param string Source string + * @param buffer Destination buffer + * @param offset Destination offset + * @returns Number of bytes written + * @throws {Error} If encoding is invalid + */ + function decode(string: string, buffer: Uint8Array, offset: number): number; + + /** + * Tests if the specified string appears to be base64 encoded. + * @param string String to test + * @returns `true` if probably base64 encoded, otherwise false + */ + function test(string: string): boolean; + } + + /** + * Begins generating a function. + * @param functionParams Function parameter names + * @param [functionName] Function name if not anonymous + * @returns Appender that appends code to the function's body + */ + function codegen(functionParams: string[], functionName?: string): Codegen; + + namespace codegen { + + /** When set to `true`, codegen will log generated code to console. Useful for debugging. */ + let verbose: boolean; + } + + /** + * Begins generating a function. + * @param [functionName] Function name if not anonymous + * @returns Appender that appends code to the function's body + */ + function codegen(functionName?: string): Codegen; + + /** A minimal event emitter. */ + class EventEmitter { + + /** Constructs a new event emitter instance. */ + constructor(); + + /** + * Registers an event listener. + * @param evt Event name + * @param fn Listener + * @param [ctx] Listener context + * @returns `this` + */ + public on(evt: string, fn: EventEmitterListener, ctx?: any): this; + + /** + * Removes an event listener or any matching listeners if arguments are omitted. + * @param [evt] Event name. Removes all listeners if omitted. + * @param [fn] Listener to remove. Removes all listeners of `evt` if omitted. + * @returns `this` + */ + public off(evt?: string, fn?: EventEmitterListener): this; + + /** + * Emits an event by calling its listeners with the specified arguments. + * @param evt Event name + * @param args Arguments + * @returns `this` + */ + public emit(evt: string, ...args: any[]): this; + } + + /** + * Fetches the contents of a file. + * @param filename File path or url + * @param options Fetch options + * @param callback Callback function + */ + function fetch(filename: string, options: IFetchOptions, callback: FetchCallback): void; + + /** + * Fetches the contents of a file. + * @param path File path or url + * @param callback Callback function + */ + function fetch(path: string, callback: FetchCallback): void; + + /** + * Fetches the contents of a file. + * @param path File path or url + * @param [options] Fetch options + * @returns Promise + */ + function fetch(path: string, options?: IFetchOptions): Promise<(string|Uint8Array)>; + + /** Reads / writes floats / doubles from / to buffers. */ + namespace float { + + /** + * Writes a 32 bit float to a buffer using little endian byte order. + * @param val Value to write + * @param buf Target buffer + * @param pos Target buffer offset + */ + function writeFloatLE(val: number, buf: Uint8Array, pos: number): void; + + /** + * Writes a 32 bit float to a buffer using big endian byte order. + * @param val Value to write + * @param buf Target buffer + * @param pos Target buffer offset + */ + function writeFloatBE(val: number, buf: Uint8Array, pos: number): void; + + /** + * Reads a 32 bit float from a buffer using little endian byte order. + * @param buf Source buffer + * @param pos Source buffer offset + * @returns Value read + */ + function readFloatLE(buf: Uint8Array, pos: number): number; + + /** + * Reads a 32 bit float from a buffer using big endian byte order. + * @param buf Source buffer + * @param pos Source buffer offset + * @returns Value read + */ + function readFloatBE(buf: Uint8Array, pos: number): number; + + /** + * Writes a 64 bit double to a buffer using little endian byte order. + * @param val Value to write + * @param buf Target buffer + * @param pos Target buffer offset + */ + function writeDoubleLE(val: number, buf: Uint8Array, pos: number): void; + + /** + * Writes a 64 bit double to a buffer using big endian byte order. + * @param val Value to write + * @param buf Target buffer + * @param pos Target buffer offset + */ + function writeDoubleBE(val: number, buf: Uint8Array, pos: number): void; + + /** + * Reads a 64 bit double from a buffer using little endian byte order. + * @param buf Source buffer + * @param pos Source buffer offset + * @returns Value read + */ + function readDoubleLE(buf: Uint8Array, pos: number): number; + + /** + * Reads a 64 bit double from a buffer using big endian byte order. + * @param buf Source buffer + * @param pos Source buffer offset + * @returns Value read + */ + function readDoubleBE(buf: Uint8Array, pos: number): number; + } + + /** + * Requires a module only if available. + * @param moduleName Module to require + * @returns Required module if available and not empty, otherwise `null` + */ + function inquire(moduleName: string): object; + /** Helper class for working with the low and high bits of a 64 bit value. */ class LongBits { @@ -2099,362 +2351,84 @@ export namespace util { * Converts a number or long to an 8 characters long hash string. * @param value Value to convert * @returns Hash - */ - function longToHash(value: (Long|number)): string; - - /** - * Converts an 8 characters long hash string to a long or number. - * @param hash Hash - * @param [unsigned=false] Whether unsigned or not - * @returns Original value - */ - function longFromHash(hash: string, unsigned?: boolean): (Long|number); - - /** - * Merges the properties of the source object into the destination object. - * @param dst Destination object - * @param src Source object - * @param [ifNotSet=false] Merges only if the key is not already set - * @returns Destination object - */ - function merge(dst: { [k: string]: any }, src: { [k: string]: any }, ifNotSet?: boolean): { [k: string]: any }; - - /** - * Converts the first character of a string to lower case. - * @param str String to convert - * @returns Converted string - */ - function lcFirst(str: string): string; - - /** - * Creates a custom error constructor. - * @param name Error name - * @returns Custom error constructor - */ - function newError(name: string): Constructor; - - /** Error subclass indicating a protocol specifc error. */ - class ProtocolError> extends Error { - - /** - * Constructs a new protocol error. - * @param message Error message - * @param [properties] Additional properties - */ - constructor(message: string, properties?: { [k: string]: any }); - - /** So far decoded message instance. */ - public instance: Message; - } - - /** - * Builds a getter for a oneof's present field name. - * @param fieldNames Field names - * @returns Unbound getter - */ - function oneOfGetter(fieldNames: string[]): OneOfGetter; - - /** - * Builds a setter for a oneof's present field name. - * @param fieldNames Field names - * @returns Unbound setter - */ - function oneOfSetter(fieldNames: string[]): OneOfSetter; - - /** - * Default conversion options used for {@link Message#toJSON} implementations. - * - * These options are close to proto3's JSON mapping with the exception that internal types like Any are handled just like messages. More precisely: - * - * - Longs become strings - * - Enums become string keys - * - Bytes become base64 encoded strings - * - (Sub-)Messages become plain objects - * - Maps become plain objects with all string keys - * - Repeated fields become arrays - * - NaN and Infinity for float and double fields become strings - * - * @see https://developers.google.com/protocol-buffers/docs/proto3?hl=en#json - */ - let toJSONOptions: IConversionOptions; - - /** Node's fs module if available. */ - let fs: { [k: string]: any }; - - /** - * Converts an object's values to an array. - * @param object Object to convert - * @returns Converted array - */ - function toArray(object: { [k: string]: any }): any[]; - - /** - * Converts an array of keys immediately followed by their respective value to an object, omitting undefined values. - * @param array Array to convert - * @returns Converted object - */ - function toObject(array: any[]): { [k: string]: any }; - - /** - * Tests whether the specified name is a reserved word in JS. - * @param name Name to test - * @returns `true` if reserved, otherwise `false` - */ - function isReserved(name: string): boolean; - - /** - * Returns a safe property accessor for the specified property name. - * @param prop Property name - * @returns Safe accessor - */ - function safeProp(prop: string): string; - - /** - * Converts the first character of a string to upper case. - * @param str String to convert - * @returns Converted string - */ - function ucFirst(str: string): string; - - /** - * Converts a string to camel case. - * @param str String to convert - * @returns Converted string - */ - function camelCase(str: string): string; - - /** - * Compares reflected fields by id. - * @param a First field - * @param b Second field - * @returns Comparison value - */ - function compareFieldsById(a: Field, b: Field): number; - - /** - * Decorator helper for types (TypeScript). - * @param ctor Constructor function - * @param [typeName] Type name, defaults to the constructor's name - * @returns Reflected type - */ - function decorateType>(ctor: Constructor, typeName?: string): Type; - - /** - * Decorator helper for enums (TypeScript). - * @param object Enum object - * @returns Reflected enum - */ - function decorateEnum(object: object): Enum; - - /** - * Sets the value of a property by property path. If a value already exists, it is turned to an array - * @param dst Destination object - * @param path dot '.' delimited path of the property to set - * @param value the value to set - * @param [ifNotSet] Sets the option only if it isn't currently set - * @returns Destination object - */ - function setProperty(dst: { [k: string]: any }, path: string, value: object, ifNotSet?: (boolean|undefined)): { [k: string]: any }; - - /** Decorator root (TypeScript). */ - let decorateRoot: Root; - - /** - * Returns a promise from a node-style callback function. - * @param fn Function to call - * @param ctx Function context - * @param params Function arguments - * @returns Promisified function - */ - function asPromise(fn: asPromiseCallback, ctx: any, ...params: any[]): Promise; - - /** A minimal base64 implementation for number arrays. */ - namespace base64 { - - /** - * Calculates the byte length of a base64 encoded string. - * @param string Base64 encoded string - * @returns Byte length - */ - function length(string: string): number; - - /** - * Encodes a buffer to a base64 encoded string. - * @param buffer Source buffer - * @param start Source start - * @param end Source end - * @returns Base64 encoded string - */ - function encode(buffer: Uint8Array, start: number, end: number): string; - - /** - * Decodes a base64 encoded string to a buffer. - * @param string Source string - * @param buffer Destination buffer - * @param offset Destination offset - * @returns Number of bytes written - * @throws {Error} If encoding is invalid - */ - function decode(string: string, buffer: Uint8Array, offset: number): number; - - /** - * Tests if the specified string appears to be base64 encoded. - * @param string String to test - * @returns `true` if probably base64 encoded, otherwise false - */ - function test(string: string): boolean; - } - - /** - * Begins generating a function. - * @param functionParams Function parameter names - * @param [functionName] Function name if not anonymous - * @returns Appender that appends code to the function's body - */ - function codegen(functionParams: string[], functionName?: string): Codegen; - - namespace codegen { - - /** When set to `true`, codegen will log generated code to console. Useful for debugging. */ - let verbose: boolean; - } - - /** - * Begins generating a function. - * @param [functionName] Function name if not anonymous - * @returns Appender that appends code to the function's body - */ - function codegen(functionName?: string): Codegen; - - /** A minimal event emitter. */ - class EventEmitter { - - /** Constructs a new event emitter instance. */ - constructor(); - - /** - * Registers an event listener. - * @param evt Event name - * @param fn Listener - * @param [ctx] Listener context - * @returns `this` - */ - public on(evt: string, fn: EventEmitterListener, ctx?: any): this; - - /** - * Removes an event listener or any matching listeners if arguments are omitted. - * @param [evt] Event name. Removes all listeners if omitted. - * @param [fn] Listener to remove. Removes all listeners of `evt` if omitted. - * @returns `this` - */ - public off(evt?: string, fn?: EventEmitterListener): this; - - /** - * Emits an event by calling its listeners with the specified arguments. - * @param evt Event name - * @param args Arguments - * @returns `this` - */ - public emit(evt: string, ...args: any[]): this; - } - - /** Reads / writes floats / doubles from / to buffers. */ - namespace float { - - /** - * Writes a 32 bit float to a buffer using little endian byte order. - * @param val Value to write - * @param buf Target buffer - * @param pos Target buffer offset - */ - function writeFloatLE(val: number, buf: Uint8Array, pos: number): void; - - /** - * Writes a 32 bit float to a buffer using big endian byte order. - * @param val Value to write - * @param buf Target buffer - * @param pos Target buffer offset - */ - function writeFloatBE(val: number, buf: Uint8Array, pos: number): void; + */ + function longToHash(value: (Long|number)): string; - /** - * Reads a 32 bit float from a buffer using little endian byte order. - * @param buf Source buffer - * @param pos Source buffer offset - * @returns Value read - */ - function readFloatLE(buf: Uint8Array, pos: number): number; + /** + * Converts an 8 characters long hash string to a long or number. + * @param hash Hash + * @param [unsigned=false] Whether unsigned or not + * @returns Original value + */ + function longFromHash(hash: string, unsigned?: boolean): (Long|number); - /** - * Reads a 32 bit float from a buffer using big endian byte order. - * @param buf Source buffer - * @param pos Source buffer offset - * @returns Value read - */ - function readFloatBE(buf: Uint8Array, pos: number): number; + /** + * Merges the properties of the source object into the destination object. + * @param dst Destination object + * @param src Source object + * @param [ifNotSet=false] Merges only if the key is not already set + * @returns Destination object + */ + function merge(dst: { [k: string]: any }, src: { [k: string]: any }, ifNotSet?: boolean): { [k: string]: any }; - /** - * Writes a 64 bit double to a buffer using little endian byte order. - * @param val Value to write - * @param buf Target buffer - * @param pos Target buffer offset - */ - function writeDoubleLE(val: number, buf: Uint8Array, pos: number): void; + /** + * Converts the first character of a string to lower case. + * @param str String to convert + * @returns Converted string + */ + function lcFirst(str: string): string; - /** - * Writes a 64 bit double to a buffer using big endian byte order. - * @param val Value to write - * @param buf Target buffer - * @param pos Target buffer offset - */ - function writeDoubleBE(val: number, buf: Uint8Array, pos: number): void; + /** + * Creates a custom error constructor. + * @param name Error name + * @returns Custom error constructor + */ + function newError(name: string): Constructor; - /** - * Reads a 64 bit double from a buffer using little endian byte order. - * @param buf Source buffer - * @param pos Source buffer offset - * @returns Value read - */ - function readDoubleLE(buf: Uint8Array, pos: number): number; + /** Error subclass indicating a protocol specifc error. */ + class ProtocolError> extends Error { /** - * Reads a 64 bit double from a buffer using big endian byte order. - * @param buf Source buffer - * @param pos Source buffer offset - * @returns Value read + * Constructs a new protocol error. + * @param message Error message + * @param [properties] Additional properties */ - function readDoubleBE(buf: Uint8Array, pos: number): number; - } + constructor(message: string, properties?: { [k: string]: any }); - /** - * Fetches the contents of a file. - * @param filename File path or url - * @param options Fetch options - * @param callback Callback function - */ - function fetch(filename: string, options: IFetchOptions, callback: FetchCallback): void; + /** So far decoded message instance. */ + public instance: Message; + } /** - * Fetches the contents of a file. - * @param path File path or url - * @param callback Callback function + * Builds a getter for a oneof's present field name. + * @param fieldNames Field names + * @returns Unbound getter */ - function fetch(path: string, callback: FetchCallback): void; + function oneOfGetter(fieldNames: string[]): OneOfGetter; /** - * Fetches the contents of a file. - * @param path File path or url - * @param [options] Fetch options - * @returns Promise + * Builds a setter for a oneof's present field name. + * @param fieldNames Field names + * @returns Unbound setter */ - function fetch(path: string, options?: IFetchOptions): Promise<(string|Uint8Array)>; + function oneOfSetter(fieldNames: string[]): OneOfSetter; /** - * Requires a module only if available. - * @param moduleName Module to require - * @returns Required module if available and not empty, otherwise `null` + * Default conversion options used for {@link Message#toJSON} implementations. + * + * These options are close to proto3's JSON mapping with the exception that internal types like Any are handled just like messages. More precisely: + * + * - Longs become strings + * - Enums become string keys + * - Bytes become base64 encoded strings + * - (Sub-)Messages become plain objects + * - Maps become plain objects with all string keys + * - Repeated fields become arrays + * - NaN and Infinity for float and double fields become strings + * + * @see https://developers.google.com/protocol-buffers/docs/proto3?hl=en#json */ - function inquire(moduleName: string): object; + let toJSONOptions: IConversionOptions; /** A minimal path module to resolve Unix, Windows and URL paths alike. */ namespace path { @@ -2520,6 +2494,87 @@ export namespace util { */ function write(string: string, buffer: Uint8Array, offset: number): number; } + + /** Node's fs module if available. */ + let fs: { [k: string]: any }; + + /** + * Converts an object's values to an array. + * @param object Object to convert + * @returns Converted array + */ + function toArray(object: { [k: string]: any }): any[]; + + /** + * Converts an array of keys immediately followed by their respective value to an object, omitting undefined values. + * @param array Array to convert + * @returns Converted object + */ + function toObject(array: any[]): { [k: string]: any }; + + /** + * Tests whether the specified name is a reserved word in JS. + * @param name Name to test + * @returns `true` if reserved, otherwise `false` + */ + function isReserved(name: string): boolean; + + /** + * Returns a safe property accessor for the specified property name. + * @param prop Property name + * @returns Safe accessor + */ + function safeProp(prop: string): string; + + /** + * Converts the first character of a string to upper case. + * @param str String to convert + * @returns Converted string + */ + function ucFirst(str: string): string; + + /** + * Converts a string to camel case. + * @param str String to convert + * @returns Converted string + */ + function camelCase(str: string): string; + + /** + * Compares reflected fields by id. + * @param a First field + * @param b Second field + * @returns Comparison value + */ + function compareFieldsById(a: Field, b: Field): number; + + /** + * Decorator helper for types (TypeScript). + * @param ctor Constructor function + * @param [typeName] Type name, defaults to the constructor's name + * @returns Reflected type + */ + function decorateType>(ctor: Constructor, typeName?: string): Type; + + /** + * Decorator helper for enums (TypeScript). + * @param object Enum object + * @returns Reflected enum + */ + function decorateEnum(object: object): Enum; + + /** + * Sets the value of a property by property path. If a value already exists, it is turned to an array + * @param dst Destination object + * @param path dot '.' delimited path of the property to set + * @param value the value to set + * @param [ifNotSet] Sets the option only if it isn't currently set + * @returns Destination object + */ + function setProperty(dst: { [k: string]: any }, path: string, value: object, ifNotSet?: (boolean|undefined)): { [k: string]: any }; + + /** Decorator root (TypeScript). */ + let decorateRoot: Root; } /** @@ -2743,57 +2798,3 @@ export class BufferWriter extends Writer { */ public finish(): Buffer; } - -/** - * Callback as used by {@link util.asPromise}. - * @param error Error, if any - * @param params Additional arguments - */ -type asPromiseCallback = (error: (Error|null), ...params: any[]) => void; - -/** - * Appends code to the function's body or finishes generation. - * @param [formatStringOrScope] Format string or, to finish the function, an object of additional scope variables, if any - * @param [formatParams] Format parameters - * @returns Itself or the generated function if finished - * @throws {Error} If format parameter counts do not match - */ -type Codegen = (formatStringOrScope?: (string|{ [k: string]: any }), ...formatParams: any[]) => (Codegen|Function); - -/** - * Event listener as used by {@link util.EventEmitter}. - * @param args Arguments - */ -type EventEmitterListener = (...args: any[]) => void; - -/** - * Node-style callback as used by {@link util.fetch}. - * @param error Error, if any, otherwise `null` - * @param [contents] File contents, if there hasn't been an error - */ -type FetchCallback = (error: Error, contents?: string) => void; - -/** Options as used by {@link util.fetch}. */ -export interface IFetchOptions { - - /** Whether expecting a binary response */ - binary?: boolean; - - /** If `true`, forces the use of XMLHttpRequest */ - xhr?: boolean; -} - -/** - * An allocator as used by {@link util.pool}. - * @param size Buffer size - * @returns Buffer - */ -type PoolAllocator = (size: number) => Uint8Array; - -/** - * A slicer as used by {@link util.pool}. - * @param start Start offset - * @param end End offset - * @returns Buffer slice - */ -type PoolSlicer = (this: Uint8Array, start: number, end: number) => Uint8Array; diff --git a/lib/aspromise/LICENSE b/lib/aspromise/LICENSE deleted file mode 100644 index be2b397e3..000000000 --- a/lib/aspromise/LICENSE +++ /dev/null @@ -1,26 +0,0 @@ -Copyright (c) 2016, Daniel Wirtz All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are -met: - -* Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. -* Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. -* Neither the name of its author, nor the names of its contributors - may be used to endorse or promote products derived from this software - without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/lib/aspromise/README.md b/lib/aspromise/README.md deleted file mode 100644 index c7ae36f0e..000000000 --- a/lib/aspromise/README.md +++ /dev/null @@ -1,13 +0,0 @@ -@protobufjs/aspromise -===================== -[![npm](https://img.shields.io/npm/v/@protobufjs/aspromise.svg)](https://www.npmjs.com/package/@protobufjs/aspromise) - -Returns a promise from a node-style callback function. - -API ---- - -* **asPromise(fn: `function`, ctx: `Object`, ...params: `*`): `Promise<*>`**
- Returns a promise from a node-style callback function. - -**License:** [BSD 3-Clause License](https://opensource.org/licenses/BSD-3-Clause) diff --git a/lib/aspromise/package.json b/lib/aspromise/package.json deleted file mode 100644 index e05eecdf8..000000000 --- a/lib/aspromise/package.json +++ /dev/null @@ -1,21 +0,0 @@ -{ - "name": "@protobufjs/aspromise", - "description": "Returns a promise from a node-style callback function.", - "version": "1.1.2", - "author": "Daniel Wirtz ", - "repository": { - "type": "git", - "url": "https://github.com/dcodeIO/protobuf.js.git" - }, - "license": "BSD-3-Clause", - "main": "index.js", - "types": "index.d.ts", - "devDependencies": { - "istanbul": "^0.4.5", - "tape": "^5.0.0" - }, - "scripts": { - "test": "tape tests/*.js", - "coverage": "istanbul cover node_modules/tape/bin/tape tests/*.js" - } -} \ No newline at end of file diff --git a/lib/base64/LICENSE b/lib/base64/LICENSE deleted file mode 100644 index be2b397e3..000000000 --- a/lib/base64/LICENSE +++ /dev/null @@ -1,26 +0,0 @@ -Copyright (c) 2016, Daniel Wirtz All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are -met: - -* Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. -* Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. -* Neither the name of its author, nor the names of its contributors - may be used to endorse or promote products derived from this software - without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/lib/base64/README.md b/lib/base64/README.md deleted file mode 100644 index b06cb0a27..000000000 --- a/lib/base64/README.md +++ /dev/null @@ -1,19 +0,0 @@ -@protobufjs/base64 -================== -[![npm](https://img.shields.io/npm/v/@protobufjs/base64.svg)](https://www.npmjs.com/package/@protobufjs/base64) - -A minimal base64 implementation for number arrays. - -API ---- - -* **base64.length(string: `string`): `number`**
- Calculates the byte length of a base64 encoded string. - -* **base64.encode(buffer: `Uint8Array`, start: `number`, end: `number`): `string`**
- Encodes a buffer to a base64 encoded string. - -* **base64.decode(string: `string`, buffer: `Uint8Array`, offset: `number`): `number`**
- Decodes a base64 encoded string to a buffer. - -**License:** [BSD 3-Clause License](https://opensource.org/licenses/BSD-3-Clause) diff --git a/lib/base64/package.json b/lib/base64/package.json deleted file mode 100644 index 722de8539..000000000 --- a/lib/base64/package.json +++ /dev/null @@ -1,21 +0,0 @@ -{ - "name": "@protobufjs/base64", - "description": "A minimal base64 implementation for number arrays.", - "version": "1.1.2", - "author": "Daniel Wirtz ", - "repository": { - "type": "git", - "url": "https://github.com/dcodeIO/protobuf.js.git" - }, - "license": "BSD-3-Clause", - "main": "index.js", - "types": "index.d.ts", - "devDependencies": { - "istanbul": "^0.4.5", - "tape": "^5.0.0" - }, - "scripts": { - "test": "tape tests/*.js", - "coverage": "istanbul cover node_modules/tape/bin/tape tests/*.js" - } -} \ No newline at end of file diff --git a/lib/codegen/LICENSE b/lib/codegen/LICENSE deleted file mode 100644 index be2b397e3..000000000 --- a/lib/codegen/LICENSE +++ /dev/null @@ -1,26 +0,0 @@ -Copyright (c) 2016, Daniel Wirtz All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are -met: - -* Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. -* Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. -* Neither the name of its author, nor the names of its contributors - may be used to endorse or promote products derived from this software - without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/lib/codegen/README.md b/lib/codegen/README.md deleted file mode 100644 index 577c43ed0..000000000 --- a/lib/codegen/README.md +++ /dev/null @@ -1,49 +0,0 @@ -@protobufjs/codegen -=================== -[![npm](https://img.shields.io/npm/v/@protobufjs/codegen.svg)](https://www.npmjs.com/package/@protobufjs/codegen) - -A minimalistic code generation utility. - -API ---- - -* **codegen([functionParams: `string[]`], [functionName: string]): `Codegen`**
- Begins generating a function. - -* **codegen.verbose = `false`**
- When set to true, codegen will log generated code to console. Useful for debugging. - -Invoking **codegen** returns an appender function that appends code to the function's body and returns itself: - -* **Codegen(formatString: `string`, [...formatParams: `any`]): Codegen**
- Appends code to the function's body. The format string can contain placeholders specifying the types of inserted format parameters: - - * `%d`: Number (integer or floating point value) - * `%f`: Floating point value - * `%i`: Integer value - * `%j`: JSON.stringify'ed value - * `%s`: String value - * `%%`: Percent sign
- -* **Codegen([scope: `Object.`]): `Function`**
- Finishes the function and returns it. - -* **Codegen.toString([functionNameOverride: `string`]): `string`**
- Returns the function as a string. - -Example -------- - -```js -var codegen = require("@protobufjs/codegen"); - -var add = codegen(["a", "b"], "add") // A function with parameters "a" and "b" named "add" - ("// awesome comment") // adds the line to the function's body - ("return a + b - c + %d", 1) // replaces %d with 1 and adds the line to the body - ({ c: 1 }); // adds "c" with a value of 1 to the function's scope - -console.log(add.toString()); // function add(a, b) { return a + b - c + 1 } -console.log(add(1, 2)); // calculates 1 + 2 - 1 + 1 = 3 -``` - -**License:** [BSD 3-Clause License](https://opensource.org/licenses/BSD-3-Clause) diff --git a/lib/codegen/package.json b/lib/codegen/package.json deleted file mode 100644 index 4e82f9562..000000000 --- a/lib/codegen/package.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "name": "@protobufjs/codegen", - "description": "A minimalistic code generation utility.", - "version": "2.0.4", - "author": "Daniel Wirtz ", - "repository": { - "type": "git", - "url": "https://github.com/dcodeIO/protobuf.js.git" - }, - "license": "BSD-3-Clause", - "main": "index.js", - "types": "index.d.ts" -} \ No newline at end of file diff --git a/lib/codegen/tests/index.js b/lib/codegen/tests/index.js deleted file mode 100644 index b189117d1..000000000 --- a/lib/codegen/tests/index.js +++ /dev/null @@ -1,13 +0,0 @@ -var codegen = require(".."); - -// new require("benchmark").Suite().add("add", function() { - -var add = codegen(["a", "b"], "add") - ("// awesome comment") - ("return a + b - c + %d", 1) - ({ c: 1 }); - -if (add(1, 2) !== 3) - throw Error("failed"); - -// }).on("cycle", function(event) { process.stdout.write(String(event.target) + "\n"); }).run(); diff --git a/lib/eventemitter/LICENSE b/lib/eventemitter/LICENSE deleted file mode 100644 index be2b397e3..000000000 --- a/lib/eventemitter/LICENSE +++ /dev/null @@ -1,26 +0,0 @@ -Copyright (c) 2016, Daniel Wirtz All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are -met: - -* Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. -* Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. -* Neither the name of its author, nor the names of its contributors - may be used to endorse or promote products derived from this software - without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/lib/eventemitter/README.md b/lib/eventemitter/README.md deleted file mode 100644 index 528e725e4..000000000 --- a/lib/eventemitter/README.md +++ /dev/null @@ -1,22 +0,0 @@ -@protobufjs/eventemitter -======================== -[![npm](https://img.shields.io/npm/v/@protobufjs/eventemitter.svg)](https://www.npmjs.com/package/@protobufjs/eventemitter) - -A minimal event emitter. - -API ---- - -* **new EventEmitter()**
- Constructs a new event emitter instance. - -* **EventEmitter#on(evt: `string`, fn: `function`, [ctx: `Object`]): `EventEmitter`**
- Registers an event listener. - -* **EventEmitter#off([evt: `string`], [fn: `function`]): `EventEmitter`**
- Removes an event listener or any matching listeners if arguments are omitted. - -* **EventEmitter#emit(evt: `string`, ...args: `*`): `EventEmitter`**
- Emits an event by calling its listeners with the specified arguments. - -**License:** [BSD 3-Clause License](https://opensource.org/licenses/BSD-3-Clause) diff --git a/lib/eventemitter/package.json b/lib/eventemitter/package.json deleted file mode 100644 index e1765d056..000000000 --- a/lib/eventemitter/package.json +++ /dev/null @@ -1,21 +0,0 @@ -{ - "name": "@protobufjs/eventemitter", - "description": "A minimal event emitter.", - "version": "1.1.0", - "author": "Daniel Wirtz ", - "repository": { - "type": "git", - "url": "https://github.com/dcodeIO/protobuf.js.git" - }, - "license": "BSD-3-Clause", - "main": "index.js", - "types": "index.d.ts", - "devDependencies": { - "istanbul": "^0.4.5", - "tape": "^5.0.0" - }, - "scripts": { - "test": "tape tests/*.js", - "coverage": "istanbul cover node_modules/tape/bin/tape tests/*.js" - } -} \ No newline at end of file diff --git a/lib/fetch/LICENSE b/lib/fetch/LICENSE deleted file mode 100644 index be2b397e3..000000000 --- a/lib/fetch/LICENSE +++ /dev/null @@ -1,26 +0,0 @@ -Copyright (c) 2016, Daniel Wirtz All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are -met: - -* Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. -* Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. -* Neither the name of its author, nor the names of its contributors - may be used to endorse or promote products derived from this software - without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/lib/fetch/README.md b/lib/fetch/README.md deleted file mode 100644 index 1ebf4d4f5..000000000 --- a/lib/fetch/README.md +++ /dev/null @@ -1,13 +0,0 @@ -@protobufjs/fetch -================= -[![npm](https://img.shields.io/npm/v/@protobufjs/fetch.svg)](https://www.npmjs.com/package/@protobufjs/fetch) - -Fetches the contents of a file accross node and browsers. - -API ---- - -* **fetch(path: `string`, [options: { binary: boolean } ], [callback: `function(error: ?Error, [contents: string])`]): `Promise|undefined`** - Fetches the contents of a file. - -**License:** [BSD 3-Clause License](https://opensource.org/licenses/BSD-3-Clause) diff --git a/lib/fetch/package.json b/lib/fetch/package.json deleted file mode 100644 index 6e31f2a10..000000000 --- a/lib/fetch/package.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "name": "@protobufjs/fetch", - "description": "Fetches the contents of a file accross node and browsers.", - "version": "1.1.1", - "author": "Daniel Wirtz ", - "repository": { - "type": "git", - "url": "https://github.com/dcodeIO/protobuf.js.git" - }, - "dependencies": { - "@protobufjs/aspromise": "^1.1.1", - "@protobufjs/inquire": "^1.1.0" - }, - "license": "BSD-3-Clause", - "main": "index.js", - "types": "index.d.ts", - "devDependencies": { - "istanbul": "^0.4.5", - "tape": "^5.0.0" - }, - "scripts": { - "test": "tape tests/*.js", - "coverage": "istanbul cover node_modules/tape/bin/tape tests/*.js" - } -} \ No newline at end of file diff --git a/lib/float/LICENSE b/lib/float/LICENSE deleted file mode 100644 index be2b397e3..000000000 --- a/lib/float/LICENSE +++ /dev/null @@ -1,26 +0,0 @@ -Copyright (c) 2016, Daniel Wirtz All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are -met: - -* Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. -* Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. -* Neither the name of its author, nor the names of its contributors - may be used to endorse or promote products derived from this software - without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/lib/float/README.md b/lib/float/README.md deleted file mode 100644 index c55d28566..000000000 --- a/lib/float/README.md +++ /dev/null @@ -1,102 +0,0 @@ -@protobufjs/float -================= -[![npm](https://img.shields.io/npm/v/@protobufjs/float.svg)](https://www.npmjs.com/package/@protobufjs/float) - -Reads / writes floats / doubles from / to buffers in both modern and ancient browsers. Fast. - -API ---- - -* **writeFloatLE(val: `number`, buf: `Uint8Array`, pos: `number`)**
- Writes a 32 bit float to a buffer using little endian byte order. - -* **writeFloatBE(val: `number`, buf: `Uint8Array`, pos: `number`)**
- Writes a 32 bit float to a buffer using big endian byte order. - -* **readFloatLE(buf: `Uint8Array`, pos: `number`): `number`**
- Reads a 32 bit float from a buffer using little endian byte order. - -* **readFloatBE(buf: `Uint8Array`, pos: `number`): `number`**
- Reads a 32 bit float from a buffer using big endian byte order. - -* **writeDoubleLE(val: `number`, buf: `Uint8Array`, pos: `number`)**
- Writes a 64 bit double to a buffer using little endian byte order. - -* **writeDoubleBE(val: `number`, buf: `Uint8Array`, pos: `number`)**
- Writes a 64 bit double to a buffer using big endian byte order. - -* **readDoubleLE(buf: `Uint8Array`, pos: `number`): `number`**
- Reads a 64 bit double from a buffer using little endian byte order. - -* **readDoubleBE(buf: `Uint8Array`, pos: `number`): `number`**
- Reads a 64 bit double from a buffer using big endian byte order. - -Performance ------------ -There is a simple benchmark included comparing raw read/write performance of this library (float), float's fallback for old browsers, the [ieee754](https://www.npmjs.com/package/ieee754) module and node's [buffer](https://nodejs.org/api/buffer.html). On an i7-2600k running node 6.9.1 it yields: - -``` -benchmarking writeFloat performance ... - -float x 42,741,625 ops/sec ±1.75% (81 runs sampled) -float (fallback) x 11,272,532 ops/sec ±1.12% (85 runs sampled) -ieee754 x 8,653,337 ops/sec ±1.18% (84 runs sampled) -buffer x 12,412,414 ops/sec ±1.41% (83 runs sampled) -buffer (noAssert) x 13,471,149 ops/sec ±1.09% (84 runs sampled) - - float was fastest - float (fallback) was 73.5% slower - ieee754 was 79.6% slower - buffer was 70.9% slower - buffer (noAssert) was 68.3% slower - -benchmarking readFloat performance ... - -float x 44,382,729 ops/sec ±1.70% (84 runs sampled) -float (fallback) x 20,925,938 ops/sec ±0.86% (87 runs sampled) -ieee754 x 17,189,009 ops/sec ±1.01% (87 runs sampled) -buffer x 10,518,437 ops/sec ±1.04% (83 runs sampled) -buffer (noAssert) x 11,031,636 ops/sec ±1.15% (87 runs sampled) - - float was fastest - float (fallback) was 52.5% slower - ieee754 was 61.0% slower - buffer was 76.1% slower - buffer (noAssert) was 75.0% slower - -benchmarking writeDouble performance ... - -float x 38,624,906 ops/sec ±0.93% (83 runs sampled) -float (fallback) x 10,457,811 ops/sec ±1.54% (85 runs sampled) -ieee754 x 7,681,130 ops/sec ±1.11% (83 runs sampled) -buffer x 12,657,876 ops/sec ±1.03% (83 runs sampled) -buffer (noAssert) x 13,372,795 ops/sec ±0.84% (85 runs sampled) - - float was fastest - float (fallback) was 73.1% slower - ieee754 was 80.1% slower - buffer was 67.3% slower - buffer (noAssert) was 65.3% slower - -benchmarking readDouble performance ... - -float x 40,527,888 ops/sec ±1.05% (84 runs sampled) -float (fallback) x 18,696,480 ops/sec ±0.84% (86 runs sampled) -ieee754 x 14,074,028 ops/sec ±1.04% (87 runs sampled) -buffer x 10,092,367 ops/sec ±1.15% (84 runs sampled) -buffer (noAssert) x 10,623,793 ops/sec ±0.96% (84 runs sampled) - - float was fastest - float (fallback) was 53.8% slower - ieee754 was 65.3% slower - buffer was 75.1% slower - buffer (noAssert) was 73.8% slower -``` - -To run it yourself: - -``` -$> npm run bench -``` - -**License:** [BSD 3-Clause License](https://opensource.org/licenses/BSD-3-Clause) diff --git a/lib/float/bench/index.js b/lib/float/bench/index.js deleted file mode 100644 index 911f4617b..000000000 --- a/lib/float/bench/index.js +++ /dev/null @@ -1,87 +0,0 @@ -"use strict"; - -var float = require(".."), - ieee754 = require("ieee754"), - newSuite = require("./suite"); - -var F32 = Float32Array; -var F64 = Float64Array; -delete global.Float32Array; -delete global.Float64Array; -var floatFallback = float({}); -global.Float32Array = F32; -global.Float64Array = F64; - -var buf = new Buffer(8); - -newSuite("writeFloat") -.add("float", function() { - float.writeFloatLE(0.1, buf, 0); -}) -.add("float (fallback)", function() { - floatFallback.writeFloatLE(0.1, buf, 0); -}) -.add("ieee754", function() { - ieee754.write(buf, 0.1, 0, true, 23, 4); -}) -.add("buffer", function() { - buf.writeFloatLE(0.1, 0); -}) -.add("buffer (noAssert)", function() { - buf.writeFloatLE(0.1, 0, true); -}) -.run(); - -newSuite("readFloat") -.add("float", function() { - float.readFloatLE(buf, 0); -}) -.add("float (fallback)", function() { - floatFallback.readFloatLE(buf, 0); -}) -.add("ieee754", function() { - ieee754.read(buf, 0, true, 23, 4); -}) -.add("buffer", function() { - buf.readFloatLE(0); -}) -.add("buffer (noAssert)", function() { - buf.readFloatLE(0, true); -}) -.run(); - -newSuite("writeDouble") -.add("float", function() { - float.writeDoubleLE(0.1, buf, 0); -}) -.add("float (fallback)", function() { - floatFallback.writeDoubleLE(0.1, buf, 0); -}) -.add("ieee754", function() { - ieee754.write(buf, 0.1, 0, true, 52, 8); -}) -.add("buffer", function() { - buf.writeDoubleLE(0.1, 0); -}) -.add("buffer (noAssert)", function() { - buf.writeDoubleLE(0.1, 0, true); -}) -.run(); - -newSuite("readDouble") -.add("float", function() { - float.readDoubleLE(buf, 0); -}) -.add("float (fallback)", function() { - floatFallback.readDoubleLE(buf, 0); -}) -.add("ieee754", function() { - ieee754.read(buf, 0, true, 52, 8); -}) -.add("buffer", function() { - buf.readDoubleLE(0); -}) -.add("buffer (noAssert)", function() { - buf.readDoubleLE(0, true); -}) -.run(); diff --git a/lib/float/bench/suite.js b/lib/float/bench/suite.js deleted file mode 100644 index 28cbc1a28..000000000 --- a/lib/float/bench/suite.js +++ /dev/null @@ -1,46 +0,0 @@ -"use strict"; -module.exports = newSuite; - -var benchmark = require("benchmark"), - chalk = require("chalk"); - -var padSize = 20; - -function newSuite(name) { - var benches = []; - return new benchmark.Suite(name) - .on("add", function(event) { - benches.push(event.target); - }) - .on("start", function() { - process.stdout.write("benchmarking " + name + " performance ...\n\n"); - }) - .on("cycle", function(event) { - process.stdout.write(String(event.target) + "\n"); - }) - .on("complete", function() { - if (benches.length > 1) { - var fastest = this.filter("fastest"), // eslint-disable-line no-invalid-this - fastestHz = getHz(fastest[0]); - process.stdout.write("\n" + chalk.white(pad(fastest[0].name, padSize)) + " was " + chalk.green("fastest") + "\n"); - benches.forEach(function(bench) { - if (fastest.indexOf(bench) === 0) - return; - var hz = hz = getHz(bench); - var percent = (1 - hz / fastestHz) * 100; - process.stdout.write(chalk.white(pad(bench.name, padSize)) + " was " + chalk.red(percent.toFixed(1) + "% slower") + "\n"); - }); - } - process.stdout.write("\n"); - }); -} - -function getHz(bench) { - return 1 / (bench.stats.mean + bench.stats.moe); -} - -function pad(str, len, l) { - while (str.length < len) - str = l ? str + " " : " " + str; - return str; -} diff --git a/lib/float/package.json b/lib/float/package.json deleted file mode 100644 index 98ae51d24..000000000 --- a/lib/float/package.json +++ /dev/null @@ -1,26 +0,0 @@ -{ - "name": "@protobufjs/float", - "description": "Reads / writes floats / doubles from / to buffers in both modern and ancient browsers.", - "version": "1.0.2", - "author": "Daniel Wirtz ", - "repository": { - "type": "git", - "url": "https://github.com/dcodeIO/protobuf.js.git" - }, - "dependencies": {}, - "license": "BSD-3-Clause", - "main": "index.js", - "types": "index.d.ts", - "devDependencies": { - "benchmark": "^2.1.4", - "chalk": "^4.0.0", - "ieee754": "^1.1.8", - "istanbul": "^0.4.5", - "tape": "^5.0.0" - }, - "scripts": { - "test": "tape tests/*.js", - "coverage": "istanbul cover node_modules/tape/bin/tape tests/*.js", - "bench": "node bench" - } -} \ No newline at end of file diff --git a/lib/inquire/LICENSE b/lib/inquire/LICENSE deleted file mode 100644 index be2b397e3..000000000 --- a/lib/inquire/LICENSE +++ /dev/null @@ -1,26 +0,0 @@ -Copyright (c) 2016, Daniel Wirtz All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are -met: - -* Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. -* Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. -* Neither the name of its author, nor the names of its contributors - may be used to endorse or promote products derived from this software - without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/lib/inquire/README.md b/lib/inquire/README.md deleted file mode 100644 index 3eabd864f..000000000 --- a/lib/inquire/README.md +++ /dev/null @@ -1,13 +0,0 @@ -@protobufjs/inquire -=================== -[![npm](https://img.shields.io/npm/v/@protobufjs/inquire.svg)](https://www.npmjs.com/package/@protobufjs/inquire) - -Requires a module only if available and hides the require call from bundlers. - -API ---- - -* **inquire(moduleName: `string`): `?Object`**
- Requires a module only if available. - -**License:** [BSD 3-Clause License](https://opensource.org/licenses/BSD-3-Clause) diff --git a/lib/inquire/package.json b/lib/inquire/package.json deleted file mode 100644 index 564a99bad..000000000 --- a/lib/inquire/package.json +++ /dev/null @@ -1,21 +0,0 @@ -{ - "name": "@protobufjs/inquire", - "description": "Requires a module only if available and hides the require call from bundlers.", - "version": "1.1.0", - "author": "Daniel Wirtz ", - "repository": { - "type": "git", - "url": "https://github.com/dcodeIO/protobuf.js.git" - }, - "license": "BSD-3-Clause", - "main": "index.js", - "types": "index.d.ts", - "devDependencies": { - "istanbul": "^0.4.5", - "tape": "^5.0.0" - }, - "scripts": { - "test": "tape tests/*.js", - "coverage": "istanbul cover node_modules/tape/bin/tape tests/*.js" - } -} \ No newline at end of file diff --git a/lib/inquire/tests/index.js b/lib/inquire/tests/index.js deleted file mode 100644 index 4a555ca22..000000000 --- a/lib/inquire/tests/index.js +++ /dev/null @@ -1,20 +0,0 @@ -var tape = require("tape"); - -var inquire = require(".."); - -tape.test("inquire", function(test) { - - test.equal(inquire("buffer").Buffer, Buffer, "should be able to require \"buffer\""); - - test.equal(inquire("%invalid"), null, "should not be able to require \"%invalid\""); - - test.equal(inquire("./tests/data/emptyObject"), null, "should return null when requiring a module exporting an empty object"); - - test.equal(inquire("./tests/data/emptyArray"), null, "should return null when requiring a module exporting an empty array"); - - test.same(inquire("./tests/data/object"), { a: 1 }, "should return the object if a non-empty object"); - - test.same(inquire("./tests/data/array"), [ 1 ], "should return the module if a non-empty array"); - - test.end(); -}); diff --git a/lib/path/LICENSE b/lib/path/LICENSE deleted file mode 100644 index be2b397e3..000000000 --- a/lib/path/LICENSE +++ /dev/null @@ -1,26 +0,0 @@ -Copyright (c) 2016, Daniel Wirtz All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are -met: - -* Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. -* Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. -* Neither the name of its author, nor the names of its contributors - may be used to endorse or promote products derived from this software - without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/lib/path/README.md b/lib/path/README.md deleted file mode 100644 index 1c1a2ba2f..000000000 --- a/lib/path/README.md +++ /dev/null @@ -1,19 +0,0 @@ -@protobufjs/path -================ -[![npm](https://img.shields.io/npm/v/@protobufjs/path.svg)](https://www.npmjs.com/package/@protobufjs/path) - -A minimal path module to resolve Unix, Windows and URL paths alike. - -API ---- - -* **path.isAbsolute(path: `string`): `boolean`**
- Tests if the specified path is absolute. - -* **path.normalize(path: `string`): `string`**
- Normalizes the specified path. - -* **path.resolve(originPath: `string`, includePath: `string`, [alreadyNormalized=false: `boolean`]): `string`**
- Resolves the specified include path against the specified origin path. - -**License:** [BSD 3-Clause License](https://opensource.org/licenses/BSD-3-Clause) diff --git a/lib/path/package.json b/lib/path/package.json deleted file mode 100644 index c93bb856b..000000000 --- a/lib/path/package.json +++ /dev/null @@ -1,21 +0,0 @@ -{ - "name": "@protobufjs/path", - "description": "A minimal path module to resolve Unix, Windows and URL paths alike.", - "version": "1.1.2", - "author": "Daniel Wirtz ", - "repository": { - "type": "git", - "url": "https://github.com/dcodeIO/protobuf.js.git" - }, - "license": "BSD-3-Clause", - "main": "index.js", - "types": "index.d.ts", - "devDependencies": { - "istanbul": "^0.4.5", - "tape": "^5.0.0" - }, - "scripts": { - "test": "tape tests/*.js", - "coverage": "istanbul cover node_modules/tape/bin/tape tests/*.js" - } -} \ No newline at end of file diff --git a/lib/pool/LICENSE b/lib/pool/LICENSE deleted file mode 100644 index be2b397e3..000000000 --- a/lib/pool/LICENSE +++ /dev/null @@ -1,26 +0,0 @@ -Copyright (c) 2016, Daniel Wirtz All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are -met: - -* Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. -* Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. -* Neither the name of its author, nor the names of its contributors - may be used to endorse or promote products derived from this software - without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/lib/pool/README.md b/lib/pool/README.md deleted file mode 100644 index 9fb0e9734..000000000 --- a/lib/pool/README.md +++ /dev/null @@ -1,13 +0,0 @@ -@protobufjs/pool -================ -[![npm](https://img.shields.io/npm/v/@protobufjs/pool.svg)](https://www.npmjs.com/package/@protobufjs/pool) - -A general purpose buffer pool. - -API ---- - -* **pool(alloc: `function(size: number): Uint8Array`, slice: `function(this: Uint8Array, start: number, end: number): Uint8Array`, [size=8192: `number`]): `function(size: number): Uint8Array`**
- Creates a pooled allocator. - -**License:** [BSD 3-Clause License](https://opensource.org/licenses/BSD-3-Clause) diff --git a/lib/pool/package.json b/lib/pool/package.json deleted file mode 100644 index 4c4208381..000000000 --- a/lib/pool/package.json +++ /dev/null @@ -1,21 +0,0 @@ -{ - "name": "@protobufjs/pool", - "description": "A general purpose buffer pool.", - "version": "1.1.0", - "author": "Daniel Wirtz ", - "repository": { - "type": "git", - "url": "https://github.com/dcodeIO/protobuf.js.git" - }, - "license": "BSD-3-Clause", - "main": "index.js", - "types": "index.d.ts", - "devDependencies": { - "istanbul": "^0.4.5", - "tape": "^5.0.0" - }, - "scripts": { - "test": "tape tests/*.js", - "coverage": "istanbul cover node_modules/tape/bin/tape tests/*.js" - } -} diff --git a/lib/utf8/LICENSE b/lib/utf8/LICENSE deleted file mode 100644 index be2b397e3..000000000 --- a/lib/utf8/LICENSE +++ /dev/null @@ -1,26 +0,0 @@ -Copyright (c) 2016, Daniel Wirtz All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are -met: - -* Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. -* Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. -* Neither the name of its author, nor the names of its contributors - may be used to endorse or promote products derived from this software - without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/lib/utf8/README.md b/lib/utf8/README.md deleted file mode 100644 index c936d9b04..000000000 --- a/lib/utf8/README.md +++ /dev/null @@ -1,20 +0,0 @@ -@protobufjs/utf8 -================ -[![npm](https://img.shields.io/npm/v/@protobufjs/utf8.svg)](https://www.npmjs.com/package/@protobufjs/utf8) - -A minimal UTF8 implementation for number arrays. - -API ---- - -* **utf8.length(string: `string`): `number`**
- Calculates the UTF8 byte length of a string. - -* **utf8.read(buffer: `Uint8Array`, start: `number`, end: `number`): `string`**
- Reads UTF8 bytes as a string. - -* **utf8.write(string: `string`, buffer: `Uint8Array`, offset: `number`): `number`**
- Writes a string as UTF8 bytes. - - -**License:** [BSD 3-Clause License](https://opensource.org/licenses/BSD-3-Clause) diff --git a/lib/utf8/package.json b/lib/utf8/package.json deleted file mode 100644 index 0eeb53a41..000000000 --- a/lib/utf8/package.json +++ /dev/null @@ -1,21 +0,0 @@ -{ - "name": "@protobufjs/utf8", - "description": "A minimal UTF8 implementation for number arrays.", - "version": "1.1.0", - "author": "Daniel Wirtz ", - "repository": { - "type": "git", - "url": "https://github.com/dcodeIO/protobuf.js.git" - }, - "license": "BSD-3-Clause", - "main": "index.js", - "types": "index.d.ts", - "devDependencies": { - "istanbul": "^0.4.5", - "tape": "^5.0.0" - }, - "scripts": { - "test": "tape tests/*.js", - "coverage": "istanbul cover node_modules/tape/bin/tape tests/*.js" - } -} diff --git a/package-lock.json b/package-lock.json index dda891972..430ca15bf 100644 --- a/package-lock.json +++ b/package-lock.json @@ -579,60 +579,6 @@ "fastq": "^1.6.0" } }, - "@protobufjs/aspromise": { - "version": "1.1.2", - "resolved": "https://registry.npmjs.org/@protobufjs/aspromise/-/aspromise-1.1.2.tgz", - "integrity": "sha512-j+gKExEuLmKwvz3OgROXtrJ2UG2x8Ch2YZUxahh+s1F2HZ+wAceUNLkvy6zKCPVRkU++ZWQrdxsUeQXmcg4uoQ==" - }, - "@protobufjs/base64": { - "version": "1.1.2", - "resolved": "https://registry.npmjs.org/@protobufjs/base64/-/base64-1.1.2.tgz", - "integrity": "sha512-AZkcAA5vnN/v4PDqKyMR5lx7hZttPDgClv83E//FMNhR2TMcLUhfRUBHCmSl0oi9zMgDDqRUJkSxO3wm85+XLg==" - }, - "@protobufjs/codegen": { - "version": "2.0.4", - "resolved": "https://registry.npmjs.org/@protobufjs/codegen/-/codegen-2.0.4.tgz", - "integrity": "sha512-YyFaikqM5sH0ziFZCN3xDC7zeGaB/d0IUb9CATugHWbd1FRFwWwt4ld4OYMPWu5a3Xe01mGAULCdqhMlPl29Jg==" - }, - "@protobufjs/eventemitter": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/@protobufjs/eventemitter/-/eventemitter-1.1.0.tgz", - "integrity": "sha512-j9ednRT81vYJ9OfVuXG6ERSTdEL1xVsNgqpkxMsbIabzSo3goCjDIveeGv5d03om39ML71RdmrGNjG5SReBP/Q==" - }, - "@protobufjs/fetch": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/@protobufjs/fetch/-/fetch-1.1.0.tgz", - "integrity": "sha512-lljVXpqXebpsijW71PZaCYeIcE5on1w5DlQy5WH6GLbFryLUrBD4932W/E2BSpfRJWseIL4v/KPgBFxDOIdKpQ==", - "requires": { - "@protobufjs/aspromise": "^1.1.1", - "@protobufjs/inquire": "^1.1.0" - } - }, - "@protobufjs/float": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/@protobufjs/float/-/float-1.0.2.tgz", - "integrity": "sha512-Ddb+kVXlXst9d+R9PfTIxh1EdNkgoRe5tOX6t01f1lYWOvJnSPDBlG241QLzcyPdoNTsblLUdujGSE4RzrTZGQ==" - }, - "@protobufjs/inquire": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/@protobufjs/inquire/-/inquire-1.1.0.tgz", - "integrity": "sha512-kdSefcPdruJiFMVSbn801t4vFK7KB/5gd2fYvrxhuJYg8ILrmn9SKSX2tZdV6V+ksulWqS7aXjBcRXl3wHoD9Q==" - }, - "@protobufjs/path": { - "version": "1.1.2", - "resolved": "https://registry.npmjs.org/@protobufjs/path/-/path-1.1.2.tgz", - "integrity": "sha512-6JOcJ5Tm08dOHAbdR3GrvP+yUUfkjG5ePsHYczMFLq3ZmMkAD98cDgcT2iA1lJ9NVwFd4tH/iSSoe44YWkltEA==" - }, - "@protobufjs/pool": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/@protobufjs/pool/-/pool-1.1.0.tgz", - "integrity": "sha512-0kELaGSIDBKvcgS4zkjz1PeddatrjYcmMWOlAuAPwAeccUrPHdUqo/J6LiymHHEiJT5NrF1UVwxY14f+fy4WQw==" - }, - "@protobufjs/utf8": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/@protobufjs/utf8/-/utf8-1.1.0.tgz", - "integrity": "sha512-Vvn3zZrhQZkkBE8LSuW3em98c0FwgO4nxzv6OdSxPKJIEKY2bGbHn+mhGIPerzI4twdxaP8/0+06HBpwf345Lw==" - }, "@types/linkify-it": { "version": "3.0.2", "resolved": "https://registry.npmjs.org/@types/linkify-it/-/linkify-it-3.0.2.tgz", diff --git a/package.json b/package.json index 39dd068d7..83b346c40 100644 --- a/package.json +++ b/package.json @@ -31,7 +31,7 @@ "bench": "node bench", "build": "npm run build:bundle && npm run build:types", "build:bundle": "gulp --gulpfile scripts/gulpfile.js", - "build:types": "node cli/bin/pbts --main --global protobuf --out index.d.ts src/ lib/aspromise/index.js lib/base64/index.js lib/codegen/index.js lib/eventemitter/index.js lib/float/index.js lib/fetch/index.js lib/inquire/index.js lib/path/index.js lib/pool/index.js lib/utf8/index.js", + "build:types": "node cli/bin/pbts --main --global protobuf --out index.d.ts src/", "changelog": "node scripts/changelog -w", "coverage": "npm run coverage:test && npm run coverage:report", "coverage:test": "nyc --silent tape -r ./lib/tape-adapter tests/*.js tests/node/*.js", @@ -51,16 +51,6 @@ "make": "npm run lint:sources && npm run build && npm run lint:types && node ./scripts/gentests.js && npm test" }, "dependencies": { - "@protobufjs/aspromise": "^1.1.2", - "@protobufjs/base64": "^1.1.2", - "@protobufjs/codegen": "^2.0.4", - "@protobufjs/eventemitter": "^1.1.0", - "@protobufjs/fetch": "^1.1.0", - "@protobufjs/float": "^1.0.2", - "@protobufjs/inquire": "^1.1.0", - "@protobufjs/path": "^1.1.2", - "@protobufjs/pool": "^1.1.0", - "@protobufjs/utf8": "^1.1.0", "@types/node": ">=13.7.0", "long": "^5.0.0" }, diff --git a/src/util.js b/src/util.js index a77feaeb3..5c9a49171 100644 --- a/src/util.js +++ b/src/util.js @@ -11,9 +11,9 @@ var roots = require("./roots"); var Type, // cyclic Enum; -util.codegen = require("@protobufjs/codegen"); -util.fetch = require("@protobufjs/fetch"); -util.path = require("@protobufjs/path"); +util.codegen = require("./util/codegen"); +util.fetch = require("./util/fetch"); +util.path = require("./util/path"); /** * Node's fs module if available. diff --git a/lib/aspromise/index.d.ts b/src/util/aspromise.d.ts similarity index 100% rename from lib/aspromise/index.d.ts rename to src/util/aspromise.d.ts diff --git a/lib/aspromise/index.js b/src/util/aspromise.js similarity index 100% rename from lib/aspromise/index.js rename to src/util/aspromise.js diff --git a/lib/base64/index.d.ts b/src/util/base64.d.ts similarity index 100% rename from lib/base64/index.d.ts rename to src/util/base64.d.ts diff --git a/lib/base64/index.js b/src/util/base64.js similarity index 100% rename from lib/base64/index.js rename to src/util/base64.js diff --git a/lib/codegen/index.d.ts b/src/util/codegen.d.ts similarity index 100% rename from lib/codegen/index.d.ts rename to src/util/codegen.d.ts diff --git a/lib/codegen/index.js b/src/util/codegen.js similarity index 100% rename from lib/codegen/index.js rename to src/util/codegen.js diff --git a/lib/eventemitter/index.d.ts b/src/util/eventemitter.d.ts similarity index 100% rename from lib/eventemitter/index.d.ts rename to src/util/eventemitter.d.ts diff --git a/lib/eventemitter/index.js b/src/util/eventemitter.js similarity index 100% rename from lib/eventemitter/index.js rename to src/util/eventemitter.js diff --git a/lib/fetch/index.d.ts b/src/util/fetch.d.ts similarity index 100% rename from lib/fetch/index.d.ts rename to src/util/fetch.d.ts diff --git a/lib/fetch/index.js b/src/util/fetch.js similarity index 97% rename from lib/fetch/index.js rename to src/util/fetch.js index 03431d4ca..06d1f6f7b 100644 --- a/lib/fetch/index.js +++ b/src/util/fetch.js @@ -1,8 +1,8 @@ "use strict"; module.exports = fetch; -var asPromise = require("@protobufjs/aspromise"), - inquire = require("@protobufjs/inquire"); +var asPromise = require("./aspromise"), + inquire = require("./inquire"); var fs = inquire("fs"); diff --git a/lib/float/index.d.ts b/src/util/float.d.ts similarity index 100% rename from lib/float/index.d.ts rename to src/util/float.d.ts diff --git a/lib/float/index.js b/src/util/float.js similarity index 100% rename from lib/float/index.js rename to src/util/float.js diff --git a/lib/inquire/index.d.ts b/src/util/inquire.d.ts similarity index 100% rename from lib/inquire/index.d.ts rename to src/util/inquire.d.ts diff --git a/lib/inquire/index.js b/src/util/inquire.js similarity index 100% rename from lib/inquire/index.js rename to src/util/inquire.js diff --git a/src/util/minimal.js b/src/util/minimal.js index 62d683326..60a5bf563 100644 --- a/src/util/minimal.js +++ b/src/util/minimal.js @@ -2,25 +2,25 @@ var util = exports; // used to return a Promise where callback is omitted -util.asPromise = require("@protobufjs/aspromise"); +util.asPromise = require("./aspromise"); // converts to / from base64 encoded strings -util.base64 = require("@protobufjs/base64"); +util.base64 = require("./base64"); // base class of rpc.Service -util.EventEmitter = require("@protobufjs/eventemitter"); +util.EventEmitter = require("./eventemitter"); // float handling accross browsers -util.float = require("@protobufjs/float"); +util.float = require("./float"); // requires modules optionally and hides the call from bundlers -util.inquire = require("@protobufjs/inquire"); +util.inquire = require("./inquire"); // converts to / from utf8 encoded strings -util.utf8 = require("@protobufjs/utf8"); +util.utf8 = require("./utf8"); // provides a node-like buffer pool in the browser -util.pool = require("@protobufjs/pool"); +util.pool = require("./pool"); // utility to work with the low and high bits of a 64 bit value util.LongBits = require("./longbits"); diff --git a/lib/path/index.d.ts b/src/util/path.d.ts similarity index 100% rename from lib/path/index.d.ts rename to src/util/path.d.ts diff --git a/lib/path/index.js b/src/util/path.js similarity index 100% rename from lib/path/index.js rename to src/util/path.js diff --git a/lib/pool/index.d.ts b/src/util/pool.d.ts similarity index 100% rename from lib/pool/index.d.ts rename to src/util/pool.d.ts diff --git a/lib/pool/index.js b/src/util/pool.js similarity index 100% rename from lib/pool/index.js rename to src/util/pool.js diff --git a/lib/utf8/index.d.ts b/src/util/utf8.d.ts similarity index 100% rename from lib/utf8/index.d.ts rename to src/util/utf8.d.ts diff --git a/lib/utf8/index.js b/src/util/utf8.js similarity index 100% rename from lib/utf8/index.js rename to src/util/utf8.js diff --git a/tests/api_writer-reader.js b/tests/api_writer-reader.js index ffb013097..faacb94fa 100644 --- a/tests/api_writer-reader.js +++ b/tests/api_writer-reader.js @@ -91,7 +91,7 @@ tape.test("writer & reader", function(test) { test.ok(expect("bool", true, [1]), "should write true as a varint of length 1 and read it back equally"); test.ok(expect("bool", false, [0]), "should write false as a varint of length 1 and read it back equally"); - // string, see also lib_utf8 + // string, see also util_utf8 test.ok(expect("string", "123", [3,49,50,51]), "should write \"123\" as a string prefixed with its length as a varint and read it back equally"); test.ok(expect("string", "", [0]), "should write \"\" as a string prefixed with its length as a varint and read it back equally"); diff --git a/lib/fetch/tests/data/file.txt b/tests/data/util_fetch/file.txt similarity index 100% rename from lib/fetch/tests/data/file.txt rename to tests/data/util_fetch/file.txt diff --git a/lib/inquire/tests/data/array.js b/tests/data/util_inquire/array.js similarity index 100% rename from lib/inquire/tests/data/array.js rename to tests/data/util_inquire/array.js diff --git a/lib/inquire/tests/data/emptyArray.js b/tests/data/util_inquire/emptyArray.js similarity index 100% rename from lib/inquire/tests/data/emptyArray.js rename to tests/data/util_inquire/emptyArray.js diff --git a/lib/inquire/tests/data/emptyObject.js b/tests/data/util_inquire/emptyObject.js similarity index 100% rename from lib/inquire/tests/data/emptyObject.js rename to tests/data/util_inquire/emptyObject.js diff --git a/lib/inquire/tests/data/object.js b/tests/data/util_inquire/object.js similarity index 100% rename from lib/inquire/tests/data/object.js rename to tests/data/util_inquire/object.js diff --git a/lib/utf8/tests/data/surrogate_pair_bug.txt b/tests/data/util_utf8/surrogate_pair_bug.txt similarity index 100% rename from lib/utf8/tests/data/surrogate_pair_bug.txt rename to tests/data/util_utf8/surrogate_pair_bug.txt diff --git a/lib/utf8/tests/data/utf8.txt b/tests/data/util_utf8/utf8.txt similarity index 100% rename from lib/utf8/tests/data/utf8.txt rename to tests/data/util_utf8/utf8.txt diff --git a/tests/lib_aspromise.js b/tests/lib_aspromise.js deleted file mode 100644 index 249e7b478..000000000 --- a/tests/lib_aspromise.js +++ /dev/null @@ -1,2 +0,0 @@ -if (typeof Promise !== "undefined") - require("../lib/aspromise/tests"); diff --git a/tests/lib_base64.js b/tests/lib_base64.js deleted file mode 100644 index 7760c52e9..000000000 --- a/tests/lib_base64.js +++ /dev/null @@ -1 +0,0 @@ -require("../lib/base64/tests"); diff --git a/tests/lib_codegen.js b/tests/lib_codegen.js deleted file mode 100644 index dae088d94..000000000 --- a/tests/lib_codegen.js +++ /dev/null @@ -1,8 +0,0 @@ -var tape = require("tape"); - -var protobuf = require(".."); - -tape.test("codegen", function(test) { - test.equal(protobuf.util.codegen.verbose, false, "should not be verbose by default"); - test.end(); -}); diff --git a/tests/lib_eventemitter.js b/tests/lib_eventemitter.js deleted file mode 100644 index bbd0cca08..000000000 --- a/tests/lib_eventemitter.js +++ /dev/null @@ -1 +0,0 @@ -require("../lib/eventemitter/tests"); diff --git a/tests/lib_inquire.js b/tests/lib_inquire.js deleted file mode 100644 index 75e2ccfc6..000000000 --- a/tests/lib_inquire.js +++ /dev/null @@ -1,4 +0,0 @@ -var protobuf = require(".."); - -if (protobuf.util.isNode) - require("../lib/inquire/tests"); diff --git a/tests/lib_path.js b/tests/lib_path.js deleted file mode 100644 index ff7c112ac..000000000 --- a/tests/lib_path.js +++ /dev/null @@ -1 +0,0 @@ -require("../lib/path/tests"); diff --git a/tests/lib_pool.js b/tests/lib_pool.js deleted file mode 100644 index dc8ac69b8..000000000 --- a/tests/lib_pool.js +++ /dev/null @@ -1,2 +0,0 @@ -if (typeof Uint8Array !== "undefined") - require("../lib/pool/tests"); diff --git a/tests/node/lib_fetch.js b/tests/node/lib_fetch.js deleted file mode 100644 index 03231be07..000000000 --- a/tests/node/lib_fetch.js +++ /dev/null @@ -1 +0,0 @@ -require("../../lib/fetch/tests"); // requires fs diff --git a/tests/node/lib_float.js b/tests/node/lib_float.js deleted file mode 100644 index 038f0c674..000000000 --- a/tests/node/lib_float.js +++ /dev/null @@ -1 +0,0 @@ -require("../../lib/float/tests"); // requires node for modified global envs diff --git a/tests/node/lib_utf8.js b/tests/node/lib_utf8.js deleted file mode 100644 index 0a721d172..000000000 --- a/tests/node/lib_utf8.js +++ /dev/null @@ -1 +0,0 @@ -require("../../lib/utf8/tests"); // requires fs to load the test file diff --git a/lib/aspromise/tests/index.js b/tests/util_aspromise.js similarity index 98% rename from lib/aspromise/tests/index.js rename to tests/util_aspromise.js index cfdb258a6..7bb639ef1 100644 --- a/lib/aspromise/tests/index.js +++ b/tests/util_aspromise.js @@ -1,6 +1,6 @@ var tape = require("tape"); -var asPromise = require(".."); +var asPromise = require("../src/util/aspromise"); tape.test("aspromise", function(test) { diff --git a/lib/base64/tests/index.js b/tests/util_base64.js similarity index 96% rename from lib/base64/tests/index.js rename to tests/util_base64.js index 6ede32c26..d9d9ff104 100644 --- a/lib/base64/tests/index.js +++ b/tests/util_base64.js @@ -1,6 +1,6 @@ var tape = require("tape"); -var base64 = require(".."); +var base64 = require("../src/util/base64"); var strings = { "": "", diff --git a/tests/util_codegen.js b/tests/util_codegen.js new file mode 100644 index 000000000..a9566991a --- /dev/null +++ b/tests/util_codegen.js @@ -0,0 +1,17 @@ +var tape = require("tape"); + +var protobuf = require(".."); +var codegen = require("../src/util/codegen"); + +tape.test("codegen", function(test) { + test.equal(protobuf.util.codegen.verbose, false, "should not be verbose by default"); + + var add = codegen(["a", "b"], "add") + ("// awesome comment") + ("return a + b - c + %d", 1) + ({ c: 1 }); + + test.equal(add(1, 2), 3, "should generate a working function"); + + test.end(); +}); diff --git a/lib/eventemitter/tests/index.js b/tests/util_eventemitter.js similarity index 96% rename from lib/eventemitter/tests/index.js rename to tests/util_eventemitter.js index 390958fd8..39f2ee04e 100644 --- a/lib/eventemitter/tests/index.js +++ b/tests/util_eventemitter.js @@ -1,6 +1,6 @@ var tape = require("tape"); -var EventEmitter = require(".."); +var EventEmitter = require("../src/util/eventemitter"); tape.test("eventemitter", function(test) { diff --git a/lib/fetch/tests/index.js b/tests/util_fetch.js similarity index 95% rename from lib/fetch/tests/index.js rename to tests/util_fetch.js index 81b3e4875..acd3dc33e 100644 --- a/lib/fetch/tests/index.js +++ b/tests/util_fetch.js @@ -1,6 +1,6 @@ var tape = require("tape"); -var fetch = require(".."); +var fetch = require("../src/util/fetch"); tape.test("fetch", function(test) { @@ -22,7 +22,7 @@ tape.test("fetch", function(test) { test.test(test.name + " - string", function(test) { test.plan(2); - fetch(require.resolve("./data/file.txt"), function(err, contents) { + fetch(require.resolve("./data/util_fetch/file.txt"), function(err, contents) { test.notOk(err, "should not return an error"); test.equal(contents, "file.txt", "should return contents as a string"); }); @@ -30,7 +30,7 @@ tape.test("fetch", function(test) { test.test(test.name + " - binary", function(test) { test.plan(2); - fetch(require.resolve("./data/file.txt"), { binary: true }, function(err, contents) { + fetch(require.resolve("./data/util_fetch/file.txt"), { binary: true }, function(err, contents) { test.notOk(err, "should not return an error"); test.same(contents, new Buffer("file.txt", "utf8"), "should return contents as a Buffer"); }); diff --git a/lib/float/tests/index.js b/tests/util_float.js similarity index 98% rename from lib/float/tests/index.js rename to tests/util_float.js index 62f08275f..73d153689 100644 --- a/lib/float/tests/index.js +++ b/tests/util_float.js @@ -1,6 +1,6 @@ var tape = require("tape"); -var float = require(".."); +var float = require("../src/util/float"); tape.test("float", function(test) { diff --git a/tests/util_inquire.js b/tests/util_inquire.js new file mode 100644 index 000000000..90cda67e2 --- /dev/null +++ b/tests/util_inquire.js @@ -0,0 +1,20 @@ +var tape = require("tape"); + +var inquire = require("../src/util/inquire"); + +tape.test("inquire", function(test) { + + test.equal(inquire("buffer").Buffer, Buffer, "should be able to require \"buffer\""); + + test.equal(inquire("%invalid"), null, "should not be able to require \"%invalid\""); + + test.equal(inquire("../../tests/data/util_inquire/emptyObject"), null, "should return null when requiring a module exporting an empty object"); + + test.equal(inquire("../../tests/data/util_inquire/emptyArray"), null, "should return null when requiring a module exporting an empty array"); + + test.same(inquire("../../tests/data/util_inquire/object"), { a: 1 }, "should return the object if a non-empty object"); + + test.same(inquire("../../tests/data/util_inquire/array"), [ 1 ], "should return the module if a non-empty array"); + + test.end(); +}); diff --git a/lib/path/tests/index.js b/tests/util_path.js similarity index 98% rename from lib/path/tests/index.js rename to tests/util_path.js index 6b6155667..fe39370cf 100644 --- a/lib/path/tests/index.js +++ b/tests/util_path.js @@ -1,6 +1,6 @@ var tape = require("tape"); -var path = require(".."); +var path = require("../src/util/path"); tape.test("path", function(test) { diff --git a/lib/pool/tests/index.js b/tests/util_pool.js similarity index 97% rename from lib/pool/tests/index.js rename to tests/util_pool.js index 59aa73f6b..c5973e9c4 100644 --- a/lib/pool/tests/index.js +++ b/tests/util_pool.js @@ -1,6 +1,6 @@ var tape = require("tape"); -var pool = require(".."); +var pool = require("../src/util/pool"); tape.test("pool", function(test) { diff --git a/lib/utf8/tests/index.js b/tests/util_utf8.js similarity index 95% rename from lib/utf8/tests/index.js rename to tests/util_utf8.js index c436c2af2..af7c42528 100644 --- a/lib/utf8/tests/index.js +++ b/tests/util_utf8.js @@ -1,11 +1,11 @@ var tape = require("tape"); -var utf8 = require(".."); +var utf8 = require("../src/util/utf8"); -var data = require("fs").readFileSync(require.resolve("./data/utf8.txt")), +var data = require("fs").readFileSync(require.resolve("./data/util_utf8/utf8.txt")), dataStr = data.toString("utf8"); -var surrogatePairErr = require("fs").readFileSync(require.resolve("./data/surrogate_pair_bug.txt")), +var surrogatePairErr = require("fs").readFileSync(require.resolve("./data/util_utf8/surrogate_pair_bug.txt")), surrogatePairErrStr = data.toString("utf8"); tape.test("utf8", function(test) {