forked from public/fvtt-cthulhu-eternal
Initial import with skill sheet working
This commit is contained in:
158
node_modules/level-transcoder/lib/encoding.d.ts
generated
vendored
Normal file
158
node_modules/level-transcoder/lib/encoding.d.ts
generated
vendored
Normal file
@ -0,0 +1,158 @@
|
||||
import { BufferFormat, ViewFormat, UTF8Format } from './formats'
|
||||
|
||||
/**
|
||||
* Encodes {@link TIn} to {@link TFormat} and decodes
|
||||
* {@link TFormat} to {@link TOut}.
|
||||
*/
|
||||
export abstract class Encoding<TIn, TFormat, TOut> implements IEncoding<TIn, TFormat, TOut> {
|
||||
constructor (options: IEncoding<TIn, TFormat, TOut>)
|
||||
|
||||
encode: (data: TIn) => TFormat
|
||||
decode: (data: TFormat) => TOut
|
||||
name: string
|
||||
format: 'buffer' | 'view' | 'utf8'
|
||||
createViewTranscoder (): ViewFormat<TIn, TOut>
|
||||
createBufferTranscoder (): BufferFormat<TIn, TOut>
|
||||
createUTF8Transcoder (): UTF8Format<TIn, TOut>
|
||||
|
||||
/**
|
||||
* Common name, computed from {@link name}. If this encoding is a
|
||||
* transcoder encoding, {@link name} will be for example 'json+view'
|
||||
* and {@link commonName} will be just 'json'. Else {@link name}
|
||||
* will equal {@link commonName}.
|
||||
*/
|
||||
get commonName (): string
|
||||
}
|
||||
|
||||
export interface IEncoding<TIn, TFormat, TOut> {
|
||||
/**
|
||||
* Encode data.
|
||||
*/
|
||||
encode: (data: TIn) => TFormat
|
||||
|
||||
/**
|
||||
* Decode data.
|
||||
*/
|
||||
decode: (data: TFormat) => TOut
|
||||
|
||||
/**
|
||||
* Unique name.
|
||||
*/
|
||||
name: string
|
||||
|
||||
/**
|
||||
* The name of the (lower-level) encoding used by the return value of
|
||||
* {@link encode}. One of 'buffer', 'view', 'utf8'.
|
||||
*/
|
||||
format: 'buffer' | 'view' | 'utf8'
|
||||
|
||||
/**
|
||||
* Create a new encoding that transcodes {@link TFormat} from / to a view.
|
||||
*/
|
||||
createViewTranscoder?: (() => ViewFormat<TIn, TOut>) | undefined
|
||||
|
||||
/**
|
||||
* Create a new encoding that transcodes {@link TFormat} from / to a buffer.
|
||||
*/
|
||||
createBufferTranscoder?: (() => BufferFormat<TIn, TOut>) | undefined
|
||||
|
||||
/**
|
||||
* Create a new encoding that transcodes {@link TFormat} from / to a UTF-8 string.
|
||||
*/
|
||||
createUTF8Transcoder?: (() => UTF8Format<TIn, TOut>) | undefined
|
||||
}
|
||||
|
||||
export interface IExternalEncoding<TIn, TFormat, TOut> {
|
||||
/**
|
||||
* Encode data.
|
||||
*/
|
||||
encode: (data: TIn) => TFormat
|
||||
|
||||
/**
|
||||
* Decode data.
|
||||
*/
|
||||
decode: (data: TFormat) => TOut
|
||||
|
||||
/**
|
||||
* Unique name.
|
||||
*/
|
||||
name?: string | undefined
|
||||
|
||||
/**
|
||||
* Legacy `level-codec` option that means the same as `format: 'buffer'`
|
||||
* if true or `format: 'utf8'` if false.
|
||||
*/
|
||||
buffer?: boolean | undefined
|
||||
|
||||
/**
|
||||
* Legacy `level-codec` alias for {@link name}. Used only when the
|
||||
* {@link name} option is undefined.
|
||||
*/
|
||||
type?: any
|
||||
|
||||
/**
|
||||
* To detect `multiformats`. If a number, then the encoding is
|
||||
* assumed to have a {@link format} of 'view'.
|
||||
* @see https://github.com/multiformats/js-multiformats/blob/master/src/codecs/interface.ts
|
||||
*/
|
||||
code?: any
|
||||
}
|
||||
|
||||
/**
|
||||
* Names of built-in encodings.
|
||||
*/
|
||||
export type KnownEncodingName = 'utf8' | 'buffer' | 'view' | 'json' | 'hex' | 'base64'
|
||||
|
||||
/**
|
||||
* One of the supported encoding interfaces.
|
||||
*/
|
||||
export type MixedEncoding<TIn, TFormat, TOut> =
|
||||
IEncoding<TIn, TFormat, TOut> |
|
||||
IExternalEncoding<TIn, TFormat, TOut>
|
||||
|
||||
/**
|
||||
* Type utility to cast a built-in encoding identified by its name to an {@link Encoding}.
|
||||
*/
|
||||
export type KnownEncoding<N extends KnownEncodingName, TFormat>
|
||||
= Encoding<KnownEncodingInput<N>, TFormat, KnownEncodingOutput<N>>
|
||||
|
||||
/**
|
||||
* Type utility to get the input type of a built-in encoding identified by its name.
|
||||
*/
|
||||
export type KnownEncodingInput<N extends KnownEncodingName>
|
||||
= N extends 'utf8' ? string | Buffer | Uint8Array
|
||||
: N extends 'buffer' ? Buffer | Uint8Array | string
|
||||
: N extends 'view' ? Uint8Array | string
|
||||
: N extends 'json' ? any
|
||||
: N extends 'hex' ? Buffer | string
|
||||
: N extends 'base64' ? Buffer | string
|
||||
: never
|
||||
|
||||
/**
|
||||
* Type utility to get the output type of a built-in encoding identified by its name.
|
||||
*/
|
||||
export type KnownEncodingOutput<N extends KnownEncodingName>
|
||||
= N extends 'utf8' ? string
|
||||
: N extends 'buffer' ? Buffer
|
||||
: N extends 'view' ? Uint8Array
|
||||
: N extends 'json' ? any
|
||||
: N extends 'hex' ? string
|
||||
: N extends 'base64' ? string
|
||||
: never
|
||||
|
||||
/**
|
||||
* Type utility to use a {@link MixedEncoding} with an untyped format.
|
||||
*/
|
||||
export type PartialEncoding<TIn, TOut = TIn> = MixedEncoding<TIn, any, TOut>
|
||||
|
||||
/**
|
||||
* Type utility to use a {@link MixedEncoding} with an untyped format and output.
|
||||
* For when only the encoding side is needed.
|
||||
*/
|
||||
export type PartialEncoder<TIn> = MixedEncoding<TIn, any, any>
|
||||
|
||||
/**
|
||||
* Type utility to use a {@link MixedEncoding} with an untyped input and format.
|
||||
* For when only the decoding side is needed.
|
||||
*/
|
||||
export type PartialDecoder<TOut> = MixedEncoding<any, any, TOut>
|
105
node_modules/level-transcoder/lib/encoding.js
generated
vendored
Normal file
105
node_modules/level-transcoder/lib/encoding.js
generated
vendored
Normal file
@ -0,0 +1,105 @@
|
||||
'use strict'
|
||||
|
||||
const ModuleError = require('module-error')
|
||||
const formats = new Set(['buffer', 'view', 'utf8'])
|
||||
|
||||
/**
|
||||
* @template TIn, TFormat, TOut
|
||||
* @abstract
|
||||
*/
|
||||
class Encoding {
|
||||
/**
|
||||
* @param {IEncoding<TIn,TFormat,TOut>} options
|
||||
*/
|
||||
constructor (options) {
|
||||
/** @type {(data: TIn) => TFormat} */
|
||||
this.encode = options.encode || this.encode
|
||||
|
||||
/** @type {(data: TFormat) => TOut} */
|
||||
this.decode = options.decode || this.decode
|
||||
|
||||
/** @type {string} */
|
||||
this.name = options.name || this.name
|
||||
|
||||
/** @type {string} */
|
||||
this.format = options.format || this.format
|
||||
|
||||
if (typeof this.encode !== 'function') {
|
||||
throw new TypeError("The 'encode' property must be a function")
|
||||
}
|
||||
|
||||
if (typeof this.decode !== 'function') {
|
||||
throw new TypeError("The 'decode' property must be a function")
|
||||
}
|
||||
|
||||
this.encode = this.encode.bind(this)
|
||||
this.decode = this.decode.bind(this)
|
||||
|
||||
if (typeof this.name !== 'string' || this.name === '') {
|
||||
throw new TypeError("The 'name' property must be a string")
|
||||
}
|
||||
|
||||
if (typeof this.format !== 'string' || !formats.has(this.format)) {
|
||||
throw new TypeError("The 'format' property must be one of 'buffer', 'view', 'utf8'")
|
||||
}
|
||||
|
||||
if (options.createViewTranscoder) {
|
||||
this.createViewTranscoder = options.createViewTranscoder
|
||||
}
|
||||
|
||||
if (options.createBufferTranscoder) {
|
||||
this.createBufferTranscoder = options.createBufferTranscoder
|
||||
}
|
||||
|
||||
if (options.createUTF8Transcoder) {
|
||||
this.createUTF8Transcoder = options.createUTF8Transcoder
|
||||
}
|
||||
}
|
||||
|
||||
get commonName () {
|
||||
return /** @type {string} */ (this.name.split('+')[0])
|
||||
}
|
||||
|
||||
/** @return {BufferFormat<TIn,TOut>} */
|
||||
createBufferTranscoder () {
|
||||
throw new ModuleError(`Encoding '${this.name}' cannot be transcoded to 'buffer'`, {
|
||||
code: 'LEVEL_ENCODING_NOT_SUPPORTED'
|
||||
})
|
||||
}
|
||||
|
||||
/** @return {ViewFormat<TIn,TOut>} */
|
||||
createViewTranscoder () {
|
||||
throw new ModuleError(`Encoding '${this.name}' cannot be transcoded to 'view'`, {
|
||||
code: 'LEVEL_ENCODING_NOT_SUPPORTED'
|
||||
})
|
||||
}
|
||||
|
||||
/** @return {UTF8Format<TIn,TOut>} */
|
||||
createUTF8Transcoder () {
|
||||
throw new ModuleError(`Encoding '${this.name}' cannot be transcoded to 'utf8'`, {
|
||||
code: 'LEVEL_ENCODING_NOT_SUPPORTED'
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
exports.Encoding = Encoding
|
||||
|
||||
/**
|
||||
* @typedef {import('./encoding').IEncoding<TIn,TFormat,TOut>} IEncoding
|
||||
* @template TIn, TFormat, TOut
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef {import('./formats').BufferFormat<TIn,TOut>} BufferFormat
|
||||
* @template TIn, TOut
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef {import('./formats').ViewFormat<TIn,TOut>} ViewFormat
|
||||
* @template TIn, TOut
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef {import('./formats').UTF8Format<TIn,TOut>} UTF8Format
|
||||
* @template TIn, TOut
|
||||
*/
|
9
node_modules/level-transcoder/lib/encodings.d.ts
generated
vendored
Normal file
9
node_modules/level-transcoder/lib/encodings.d.ts
generated
vendored
Normal file
@ -0,0 +1,9 @@
|
||||
import { KnownEncodingInput, KnownEncodingOutput } from './encoding'
|
||||
import { BufferFormat, ViewFormat, UTF8Format } from './formats'
|
||||
|
||||
export const utf8: UTF8Format<KnownEncodingInput<'utf8'>, KnownEncodingOutput<'utf8'>>
|
||||
export const json: UTF8Format<KnownEncodingInput<'json'>, KnownEncodingOutput<'json'>>
|
||||
export const buffer: BufferFormat<KnownEncodingInput<'buffer'>, KnownEncodingOutput<'buffer'>>
|
||||
export const view: ViewFormat<KnownEncodingInput<'view'>, KnownEncodingOutput<'view'>>
|
||||
export const hex: BufferFormat<KnownEncodingInput<'hex'>, KnownEncodingOutput<'hex'>>
|
||||
export const base64: BufferFormat<KnownEncodingInput<'base64'>, KnownEncodingOutput<'base64'>>
|
135
node_modules/level-transcoder/lib/encodings.js
generated
vendored
Normal file
135
node_modules/level-transcoder/lib/encodings.js
generated
vendored
Normal file
@ -0,0 +1,135 @@
|
||||
'use strict'
|
||||
|
||||
const { Buffer } = require('buffer') || { Buffer: { isBuffer: () => false } }
|
||||
const { textEncoder, textDecoder } = require('./text-endec')()
|
||||
const { BufferFormat, ViewFormat, UTF8Format } = require('./formats')
|
||||
|
||||
/** @type {<T>(v: T) => v} */
|
||||
const identity = (v) => v
|
||||
|
||||
/**
|
||||
* @type {typeof import('./encodings').utf8}
|
||||
*/
|
||||
exports.utf8 = new UTF8Format({
|
||||
encode: function (data) {
|
||||
// On node 16.9.1 buffer.toString() is 5x faster than TextDecoder
|
||||
return Buffer.isBuffer(data)
|
||||
? data.toString('utf8')
|
||||
: ArrayBuffer.isView(data)
|
||||
? textDecoder.decode(data)
|
||||
: String(data)
|
||||
},
|
||||
decode: identity,
|
||||
name: 'utf8',
|
||||
createViewTranscoder () {
|
||||
return new ViewFormat({
|
||||
encode: function (data) {
|
||||
return ArrayBuffer.isView(data) ? data : textEncoder.encode(data)
|
||||
},
|
||||
decode: function (data) {
|
||||
return textDecoder.decode(data)
|
||||
},
|
||||
name: `${this.name}+view`
|
||||
})
|
||||
},
|
||||
createBufferTranscoder () {
|
||||
return new BufferFormat({
|
||||
encode: function (data) {
|
||||
return Buffer.isBuffer(data)
|
||||
? data
|
||||
: ArrayBuffer.isView(data)
|
||||
? Buffer.from(data.buffer, data.byteOffset, data.byteLength)
|
||||
: Buffer.from(String(data), 'utf8')
|
||||
},
|
||||
decode: function (data) {
|
||||
return data.toString('utf8')
|
||||
},
|
||||
name: `${this.name}+buffer`
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
/**
|
||||
* @type {typeof import('./encodings').json}
|
||||
*/
|
||||
exports.json = new UTF8Format({
|
||||
encode: JSON.stringify,
|
||||
decode: JSON.parse,
|
||||
name: 'json'
|
||||
})
|
||||
|
||||
/**
|
||||
* @type {typeof import('./encodings').buffer}
|
||||
*/
|
||||
exports.buffer = new BufferFormat({
|
||||
encode: function (data) {
|
||||
return Buffer.isBuffer(data)
|
||||
? data
|
||||
: ArrayBuffer.isView(data)
|
||||
? Buffer.from(data.buffer, data.byteOffset, data.byteLength)
|
||||
: Buffer.from(String(data), 'utf8')
|
||||
},
|
||||
decode: identity,
|
||||
name: 'buffer',
|
||||
createViewTranscoder () {
|
||||
return new ViewFormat({
|
||||
encode: function (data) {
|
||||
return ArrayBuffer.isView(data) ? data : Buffer.from(String(data), 'utf8')
|
||||
},
|
||||
decode: function (data) {
|
||||
return Buffer.from(data.buffer, data.byteOffset, data.byteLength)
|
||||
},
|
||||
name: `${this.name}+view`
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
/**
|
||||
* @type {typeof import('./encodings').view}
|
||||
*/
|
||||
exports.view = new ViewFormat({
|
||||
encode: function (data) {
|
||||
return ArrayBuffer.isView(data) ? data : textEncoder.encode(data)
|
||||
},
|
||||
decode: identity,
|
||||
name: 'view',
|
||||
createBufferTranscoder () {
|
||||
return new BufferFormat({
|
||||
encode: function (data) {
|
||||
return Buffer.isBuffer(data)
|
||||
? data
|
||||
: ArrayBuffer.isView(data)
|
||||
? Buffer.from(data.buffer, data.byteOffset, data.byteLength)
|
||||
: Buffer.from(String(data), 'utf8')
|
||||
},
|
||||
decode: identity,
|
||||
name: `${this.name}+buffer`
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
/**
|
||||
* @type {typeof import('./encodings').hex}
|
||||
*/
|
||||
exports.hex = new BufferFormat({
|
||||
encode: function (data) {
|
||||
return Buffer.isBuffer(data) ? data : Buffer.from(String(data), 'hex')
|
||||
},
|
||||
decode: function (buffer) {
|
||||
return buffer.toString('hex')
|
||||
},
|
||||
name: 'hex'
|
||||
})
|
||||
|
||||
/**
|
||||
* @type {typeof import('./encodings').base64}
|
||||
*/
|
||||
exports.base64 = new BufferFormat({
|
||||
encode: function (data) {
|
||||
return Buffer.isBuffer(data) ? data : Buffer.from(String(data), 'base64')
|
||||
},
|
||||
decode: function (buffer) {
|
||||
return buffer.toString('base64')
|
||||
},
|
||||
name: 'base64'
|
||||
})
|
13
node_modules/level-transcoder/lib/formats.d.ts
generated
vendored
Normal file
13
node_modules/level-transcoder/lib/formats.d.ts
generated
vendored
Normal file
@ -0,0 +1,13 @@
|
||||
import { Encoding, IEncoding } from './encoding'
|
||||
|
||||
export class BufferFormat<TIn, TOut> extends Encoding<TIn, Buffer, TOut> {
|
||||
constructor (options: Omit<IEncoding<TIn, Buffer, TOut>, 'format'>)
|
||||
}
|
||||
|
||||
export class ViewFormat<TIn, TOut> extends Encoding<TIn, Uint8Array, TOut> {
|
||||
constructor (options: Omit<IEncoding<TIn, Uint8Array, TOut>, 'format'>)
|
||||
}
|
||||
|
||||
export class UTF8Format<TIn, TOut> extends Encoding<TIn, string, TOut> {
|
||||
constructor (options: Omit<IEncoding<TIn, string, TOut>, 'format'>)
|
||||
}
|
111
node_modules/level-transcoder/lib/formats.js
generated
vendored
Normal file
111
node_modules/level-transcoder/lib/formats.js
generated
vendored
Normal file
@ -0,0 +1,111 @@
|
||||
'use strict'
|
||||
|
||||
const { Buffer } = require('buffer') || {}
|
||||
const { Encoding } = require('./encoding')
|
||||
const textEndec = require('./text-endec')
|
||||
|
||||
/**
|
||||
* @template TIn, TOut
|
||||
* @extends {Encoding<TIn,Buffer,TOut>}
|
||||
*/
|
||||
class BufferFormat extends Encoding {
|
||||
/**
|
||||
* @param {Omit<IEncoding<TIn, Buffer, TOut>, 'format'>} options
|
||||
*/
|
||||
constructor (options) {
|
||||
super({ ...options, format: 'buffer' })
|
||||
}
|
||||
|
||||
/** @override */
|
||||
createViewTranscoder () {
|
||||
return new ViewFormat({
|
||||
encode: this.encode, // Buffer is a view (UInt8Array)
|
||||
decode: (data) => this.decode(
|
||||
Buffer.from(data.buffer, data.byteOffset, data.byteLength)
|
||||
),
|
||||
name: `${this.name}+view`
|
||||
})
|
||||
}
|
||||
|
||||
/** @override */
|
||||
createBufferTranscoder () {
|
||||
return this
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @extends {Encoding<TIn,Uint8Array,TOut>}
|
||||
* @template TIn, TOut
|
||||
*/
|
||||
class ViewFormat extends Encoding {
|
||||
/**
|
||||
* @param {Omit<IEncoding<TIn, Uint8Array, TOut>, 'format'>} options
|
||||
*/
|
||||
constructor (options) {
|
||||
super({ ...options, format: 'view' })
|
||||
}
|
||||
|
||||
/** @override */
|
||||
createBufferTranscoder () {
|
||||
return new BufferFormat({
|
||||
encode: (data) => {
|
||||
const view = this.encode(data)
|
||||
return Buffer.from(view.buffer, view.byteOffset, view.byteLength)
|
||||
},
|
||||
decode: this.decode, // Buffer is a view (UInt8Array)
|
||||
name: `${this.name}+buffer`
|
||||
})
|
||||
}
|
||||
|
||||
/** @override */
|
||||
createViewTranscoder () {
|
||||
return this
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @extends {Encoding<TIn,string,TOut>}
|
||||
* @template TIn, TOut
|
||||
*/
|
||||
class UTF8Format extends Encoding {
|
||||
/**
|
||||
* @param {Omit<IEncoding<TIn, string, TOut>, 'format'>} options
|
||||
*/
|
||||
constructor (options) {
|
||||
super({ ...options, format: 'utf8' })
|
||||
}
|
||||
|
||||
/** @override */
|
||||
createBufferTranscoder () {
|
||||
return new BufferFormat({
|
||||
encode: (data) => Buffer.from(this.encode(data), 'utf8'),
|
||||
decode: (data) => this.decode(data.toString('utf8')),
|
||||
name: `${this.name}+buffer`
|
||||
})
|
||||
}
|
||||
|
||||
/** @override */
|
||||
createViewTranscoder () {
|
||||
const { textEncoder, textDecoder } = textEndec()
|
||||
|
||||
return new ViewFormat({
|
||||
encode: (data) => textEncoder.encode(this.encode(data)),
|
||||
decode: (data) => this.decode(textDecoder.decode(data)),
|
||||
name: `${this.name}+view`
|
||||
})
|
||||
}
|
||||
|
||||
/** @override */
|
||||
createUTF8Transcoder () {
|
||||
return this
|
||||
}
|
||||
}
|
||||
|
||||
exports.BufferFormat = BufferFormat
|
||||
exports.ViewFormat = ViewFormat
|
||||
exports.UTF8Format = UTF8Format
|
||||
|
||||
/**
|
||||
* @typedef {import('./encoding').IEncoding<TIn,TFormat,TOut>} IEncoding
|
||||
* @template TIn, TFormat, TOut
|
||||
*/
|
6
node_modules/level-transcoder/lib/text-endec.d.ts
generated
vendored
Normal file
6
node_modules/level-transcoder/lib/text-endec.d.ts
generated
vendored
Normal file
@ -0,0 +1,6 @@
|
||||
declare function textEndec (): {
|
||||
textEncoder: TextEncoder
|
||||
textDecoder: TextDecoder
|
||||
}
|
||||
|
||||
export = textEndec
|
19
node_modules/level-transcoder/lib/text-endec.js
generated
vendored
Normal file
19
node_modules/level-transcoder/lib/text-endec.js
generated
vendored
Normal file
@ -0,0 +1,19 @@
|
||||
'use strict'
|
||||
|
||||
/** @type {{ textEncoder: TextEncoder, textDecoder: TextDecoder }|null} */
|
||||
let lazy = null
|
||||
|
||||
/**
|
||||
* Get semi-global instances of TextEncoder and TextDecoder.
|
||||
* @returns {{ textEncoder: TextEncoder, textDecoder: TextDecoder }}
|
||||
*/
|
||||
module.exports = function () {
|
||||
if (lazy === null) {
|
||||
lazy = {
|
||||
textEncoder: new TextEncoder(),
|
||||
textDecoder: new TextDecoder()
|
||||
}
|
||||
}
|
||||
|
||||
return lazy
|
||||
}
|
Reference in New Issue
Block a user