@candidstartup/infinisheet-types 0.8.0 → 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -54,9 +54,7 @@ class VariableSizeItemOffsetMapping {
54
54
  }
55
55
  offsetToItem(offset) {
56
56
  let startOffset = 0;
57
- const length = this.#sizes.length;
58
- for (let i = 0; i < length; i++) {
59
- const size = this.#sizes[i];
57
+ for (const [i, size] of this.#sizes.entries()) {
60
58
  if (startOffset + size > offset) {
61
59
  return [i, startOffset];
62
60
  }
@@ -64,6 +62,7 @@ class VariableSizeItemOffsetMapping {
64
62
  }
65
63
  const itemIndex = Math.floor((offset - startOffset) / this.#defaultItemSize);
66
64
  startOffset += itemIndex * this.#defaultItemSize;
65
+ const length = this.#sizes.length;
67
66
  return [itemIndex + length, startOffset];
68
67
  }
69
68
  #defaultItemSize;
@@ -111,7 +110,7 @@ function splitRowColRef(ref) {
111
110
  if (!found)
112
111
  return [undefined, undefined];
113
112
  const col = found[1];
114
- const row = parseInt(found[2]);
113
+ const row = found[2] ? parseInt(found[2]) : 0;
115
114
  return [(row > 0) ? row - 1 : undefined, col ? col : undefined];
116
115
  }
117
116
  /** Converts a {@link RowColRef} to {@link RowColCoords} */
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../src/FixedSizeItemOffsetMapping.ts","../src/VariableSizeItemOffsetMapping.ts","../src/SpreadsheetData.ts","../src/RowColRef.ts"],"sourcesContent":["import type { ItemOffsetMapping } from './ItemOffsetMapping';\n\n/**\n * Implementation of {@link ItemOffsetMapping} for use when all items have a fixed size\n */\nexport class FixedSizeItemOffsetMapping implements ItemOffsetMapping {\n /**\n * @param itemSize - Size to use for all items\n */\n constructor (itemSize: number) {\n this.#fixedItemSize = itemSize;\n }\n\n itemSize(_itemIndex: number): number {\n return this.#fixedItemSize;\n }\n\n itemOffset(itemIndex: number): number {\n return itemIndex * this.#fixedItemSize;\n }\n\n offsetToItem(offset: number): [itemIndex: number, startOffset: number] {\n const itemIndex = Math.floor(offset / this.#fixedItemSize);\n const startOffset = itemIndex * this.#fixedItemSize;\n\n return [itemIndex, startOffset];\n }\n\n #fixedItemSize: number;\n}\n\n","import type { ItemOffsetMapping } from './ItemOffsetMapping';\n\n/**\n * Implementation of {@link ItemOffsetMapping} for use when initial items have variable sizes.\n */\nexport class VariableSizeItemOffsetMapping implements ItemOffsetMapping {\n /**\n * @param defaultItemSize - Size to use for all other items\n * @param sizes - Array of sizes to use for the initial items, one size per item\n */\n constructor (defaultItemSize: number, sizes: number[]) {\n this.#defaultItemSize = defaultItemSize;\n this.#sizes = sizes;\n }\n\n itemSize(itemIndex: number): number {\n return (itemIndex < this.#sizes.length) ? this.#sizes[itemIndex] : this.#defaultItemSize;\n }\n\n itemOffset(itemIndex: number): number {\n let offset = 0;\n let length = this.#sizes.length;\n if (itemIndex > length) {\n const numDefaultSize = itemIndex - length;\n offset = numDefaultSize * this.#defaultItemSize;\n } else {\n length = itemIndex;\n }\n \n for (let i = 0; i < length; i ++)\n {\n offset += this.#sizes[i];\n }\n\n return offset;\n }\n\n offsetToItem(offset: number): [itemIndex: number, startOffset: number] {\n let startOffset = 0;\n const length = this.#sizes.length;\n for (let i = 0; i < length; i ++) {\n const size = this.#sizes[i];\n if (startOffset + size > offset) {\n return [i, startOffset];\n }\n startOffset += size;\n }\n\n const itemIndex = Math.floor((offset - startOffset) / this.#defaultItemSize);\n startOffset += itemIndex * this.#defaultItemSize;\n\n return [itemIndex+length, startOffset];\n }\n\n #defaultItemSize: number;\n #sizes: number[];\n}\n","import type { ItemOffsetMapping } from \"./ItemOffsetMapping\";\nimport { FixedSizeItemOffsetMapping } from \"./FixedSizeItemOffsetMapping\";\n\n/** Possible spreadsheet error values\n * \n * Includes those that can be returned by `ERROR.TYPE` and additional values\n * introduced by more recent versions of Excel.\n*/\nexport type CellErrorValue = '#NULL!' | \n '#DIV/0!' |\n '#VALUE!' |\n '#REF!' |\n '#NAME?' |\n '#NUM!' |\n '#N/A' |\n '#GETTING_DATA' |\n '#SPILL!' |\n '#UNKNOWN!' |\n '#FIELD!' |\n '#CALC!';\n\n/** Type that represents an error value stored in a cell\n * \n * Defined as a discriminated union so that additional cell value types\n * can be added in future.\n */\nexport interface CellError {\n /** Discriminated union tag */\n type: 'CellError',\n\n /** {@link CellErrorValue | Error Value} */\n value: CellErrorValue;\n};\n\n/** Possible types for a cell value \n * \n * The native JavaScript types string, number and boolean represent the *Text*, *Number* and *Logical*\n * spreadsheet data types. {@link CellError} represents an *Error Value*.\n * \n * Undefined is used to represent a cell with no defined value. Null represents a cell that has been\n * explicitly marked as empty. \n*/\nexport type CellValue = string | number | boolean | null | undefined | CellError;\n\n/**\n * Interface used to access the data in a spreadsheet\n * \n * The data exposed through the interface may change over time outside of any changes made through the interface. The caller\n * can use the {@link subscribe} method to be notified when the data changes. When reading data, the caller must first request\n * a snapshot using {@link getSnapshot}. All values returned by gettors are relative to a specified snapshot. The values will be\n * consistent with each other as long as the same snapshot is used.\n * \n * @typeParam Snapshot - Type of snapshot. Implementations are free to use whatever type makes sense for them.\n */\nexport interface SpreadsheetData<Snapshot> {\n /** Subscribe to data changes */\n subscribe(onDataChange: () => void): () => void,\n\n /** Return a snapshot to use when accessing values at a consistent point in time */\n getSnapshot(): Snapshot,\n\n /** Number of rows in the spreadsheet */\n getRowCount(snapshot: Snapshot): number,\n\n /** {@link ItemOffsetMapping} which describes sizes and offsets to start of rows */\n getRowItemOffsetMapping(snapshot: Snapshot): ItemOffsetMapping,\n\n /** Number of columns in the spreadsheet */\n getColumnCount(snapshot: Snapshot): number,\n\n /** {@link ItemOffsetMapping} which describes sizes and offsets to start of columns */\n getColumnItemOffsetMapping(snapshot: Snapshot): ItemOffsetMapping,\n\n /** Value of specified cell using 0-based row and column indexes */\n getCellValue(snapshot: Snapshot, row: number, column: number): CellValue;\n\n /** Format of specified cell using 0-based row and column indexes */\n getCellFormat(snapshot: Snapshot, row: number, column: number): string | undefined;\n\n /** Set value and format of specified cell\n * \n * @returns True if the change was successfully applied\n */\n setCellValueAndFormat(row: number, column: number, value: CellValue, format: string | undefined): boolean;\n}\n\nconst rowItemOffsetMapping = new FixedSizeItemOffsetMapping(30);\nconst columnItemOffsetMapping = new FixedSizeItemOffsetMapping(100);\n\nexport class EmptySpreadsheetData implements SpreadsheetData<number> {\n subscribe(_onDataChange: () => void) { return () => {}; }\n getSnapshot() { return 0; }\n \n getRowCount(_snapshot: number) { return 0; }\n getRowItemOffsetMapping(_snapshot: number): ItemOffsetMapping { return rowItemOffsetMapping; }\n getColumnCount(_snapshot: number) { return 0; }\n getColumnItemOffsetMapping(_snapshot: number): ItemOffsetMapping { return columnItemOffsetMapping; }\n getCellValue(_snapshot: number, _row: number, _column: number): CellValue { return null; }\n getCellFormat(_snapshot: number, _row: number, _column: number): string|undefined { return undefined; }\n setCellValueAndFormat(_row: number, _column: number, _value: CellValue, _format: string | undefined): boolean { return false; }\n}\n\n","/** Classic Spreadsheet reference to Column (e.g \"A\") */\nexport type ColRef = string;\n\n/** Classic Spreadsheet reference to Cell (e.g. \"A1\"), Row (e.g. \"1\") or Column (e.g \"A\") */\nexport type RowColRef = string;\n\n/** Equivalent to {@link RowColRef} as coordinate pair. \"A1\" has coords [0,0], \"1\" is [0,undefined] and \"A\" is [undefined,0] */\nexport type RowColCoords = [row: number|undefined, col: number|undefined];\n\n/** Converts a {@link ColRef} to the 0-based index of the column */\nexport function colRefToIndex(col: ColRef): number {\n let n = 0;\n for (let i = 0; i < col.length; i ++) {\n n = col.charCodeAt(i) - 64 + n * 26;\n }\n return n-1;\n}\n\n/** Converts a 0-based column index to a {@link ColRef} */\nexport function indexToColRef(index: number): ColRef {\n let ret = \"\";\n index ++;\n while (index > 0) {\n index --;\n const remainder = index % 26;\n index = Math.floor(index / 26);\n ret = String.fromCharCode(65+remainder) + ret;\n }\n return ret;\n}\n\n/** Splits a RowColRef into a 0-based row index and a {@link ColRef} */\nexport function splitRowColRef(ref: RowColRef): [row: number|undefined, col: ColRef|undefined] {\n const re = /^([A-Z]*)(\\d*)$/;\n const found = ref.match(re);\n if (!found)\n return [undefined,undefined];\n\n const col = found[1];\n const row = parseInt(found[2]);\n return [(row>0) ? row-1 : undefined, col ? col : undefined];\n}\n\n/** Converts a {@link RowColRef} to {@link RowColCoords} */\nexport function rowColRefToCoords(ref: RowColRef): RowColCoords {\n const [row,col] = splitRowColRef(ref);\n return [row, col ? colRefToIndex(col) : undefined];\n}\n\n/** Converts {@link RowColCoords} to a {@link RowColRef} */\nexport function rowColCoordsToRef(row: number|undefined, col: number|undefined): RowColRef {\n if (row !== undefined) {\n if (col !== undefined) {\n return indexToColRef(col) + (row+1);\n } else {\n return (row+1).toString();\n }\n } else {\n if (col !== undefined) {\n return indexToColRef(col);\n } else {\n return \"\";\n }\n }\n}"],"names":[],"mappings":"AAEA;;AAEG;MACU,0BAA0B,CAAA;AACrC;;AAEG;AACH,IAAA,WAAA,CAAa,QAAgB,EAAA;AAC3B,QAAA,IAAI,CAAC,cAAc,GAAG,QAAQ;;AAGhC,IAAA,QAAQ,CAAC,UAAkB,EAAA;QACzB,OAAO,IAAI,CAAC,cAAc;;AAG5B,IAAA,UAAU,CAAC,SAAiB,EAAA;AAC1B,QAAA,OAAO,SAAS,GAAG,IAAI,CAAC,cAAc;;AAGxC,IAAA,YAAY,CAAC,MAAc,EAAA;AACzB,QAAA,MAAM,SAAS,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,GAAG,IAAI,CAAC,cAAc,CAAC;AAC1D,QAAA,MAAM,WAAW,GAAG,SAAS,GAAG,IAAI,CAAC,cAAc;AAEnD,QAAA,OAAO,CAAC,SAAS,EAAE,WAAW,CAAC;;AAGjC,IAAA,cAAc;AACf;;AC3BD;;AAEG;MACU,6BAA6B,CAAA;AACxC;;;AAGG;IACH,WAAa,CAAA,eAAuB,EAAE,KAAe,EAAA;AACnD,QAAA,IAAI,CAAC,gBAAgB,GAAG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YACrB,OAAO,aAAa,CAAC,GAAG,CAAC,IAAI,GAAG,GAAC,CAAC,CAAC;;aAC9B;YACL,OAAO,CAAC,GAAG,GAAC,CAAC,EAAE,QAAQ,EAAE;;;SAEtB;AACL,QAAA,IAAI,GAAG,KAAK,SAAS,EAAE;AACrB,YAAA,OAAO,aAAa,CAAC,GAAG,CAAC;;aACpB;AACL,YAAA,OAAO,EAAE;;;AAGf;;;;"}
1
+ {"version":3,"file":"index.js","sources":["../src/FixedSizeItemOffsetMapping.ts","../src/VariableSizeItemOffsetMapping.ts","../src/SpreadsheetData.ts","../src/RowColRef.ts"],"sourcesContent":["import type { ItemOffsetMapping } from './ItemOffsetMapping';\n\n/**\n * Implementation of {@link ItemOffsetMapping} for use when all items have a fixed size\n */\nexport class FixedSizeItemOffsetMapping implements ItemOffsetMapping {\n /**\n * @param itemSize - Size to use for all items\n */\n constructor (itemSize: number) {\n this.#fixedItemSize = itemSize;\n }\n\n itemSize(_itemIndex: number): number {\n return this.#fixedItemSize;\n }\n\n itemOffset(itemIndex: number): number {\n return itemIndex * this.#fixedItemSize;\n }\n\n offsetToItem(offset: number): [itemIndex: number, startOffset: number] {\n const itemIndex = Math.floor(offset / this.#fixedItemSize);\n const startOffset = itemIndex * this.#fixedItemSize;\n\n return [itemIndex, startOffset];\n }\n\n #fixedItemSize: number;\n}\n\n","import type { ItemOffsetMapping } from './ItemOffsetMapping';\n\n/**\n * Implementation of {@link ItemOffsetMapping} for use when initial items have variable sizes.\n */\nexport class VariableSizeItemOffsetMapping implements ItemOffsetMapping {\n /**\n * @param defaultItemSize - Size to use for all other items\n * @param sizes - Array of sizes to use for the initial items, one size per item\n */\n constructor (defaultItemSize: number, sizes: number[]) {\n this.#defaultItemSize = defaultItemSize;\n this.#sizes = sizes;\n }\n\n itemSize(itemIndex: number): number {\n return (itemIndex < this.#sizes.length) ? this.#sizes[itemIndex]! : this.#defaultItemSize;\n }\n\n itemOffset(itemIndex: number): number {\n let offset = 0;\n let length = this.#sizes.length;\n if (itemIndex > length) {\n const numDefaultSize = itemIndex - length;\n offset = numDefaultSize * this.#defaultItemSize;\n } else {\n length = itemIndex;\n }\n \n for (let i = 0; i < length; i ++)\n {\n offset += this.#sizes[i]!;\n }\n\n return offset;\n }\n\n offsetToItem(offset: number): [itemIndex: number, startOffset: number] {\n let startOffset = 0;\n for (const [i,size] of this.#sizes.entries()) {\n if (startOffset + size > offset) {\n return [i, startOffset];\n }\n startOffset += size;\n }\n\n const itemIndex = Math.floor((offset - startOffset) / this.#defaultItemSize);\n startOffset += itemIndex * this.#defaultItemSize;\n\n const length = this.#sizes.length;\n return [itemIndex+length, startOffset];\n }\n\n #defaultItemSize: number;\n #sizes: number[];\n}\n","import type { ItemOffsetMapping } from \"./ItemOffsetMapping\";\nimport { FixedSizeItemOffsetMapping } from \"./FixedSizeItemOffsetMapping\";\n\n/** Possible spreadsheet error values\n * \n * Includes those that can be returned by `ERROR.TYPE` and additional values\n * introduced by more recent versions of Excel.\n*/\nexport type CellErrorValue = '#NULL!' | \n '#DIV/0!' |\n '#VALUE!' |\n '#REF!' |\n '#NAME?' |\n '#NUM!' |\n '#N/A' |\n '#GETTING_DATA' |\n '#SPILL!' |\n '#UNKNOWN!' |\n '#FIELD!' |\n '#CALC!';\n\n/** Type that represents an error value stored in a cell\n * \n * Defined as a discriminated union so that additional cell value types\n * can be added in future.\n */\nexport interface CellError {\n /** Discriminated union tag */\n type: 'CellError',\n\n /** {@link CellErrorValue | Error Value} */\n value: CellErrorValue;\n};\n\n/** Possible types for a cell value \n * \n * The native JavaScript types string, number and boolean represent the *Text*, *Number* and *Logical*\n * spreadsheet data types. {@link CellError} represents an *Error Value*.\n * \n * Undefined is used to represent a cell with no defined value. Null represents a cell that has been\n * explicitly marked as empty. \n*/\nexport type CellValue = string | number | boolean | null | undefined | CellError;\n\n/**\n * Interface used to access the data in a spreadsheet\n * \n * The data exposed through the interface may change over time outside of any changes made through the interface. The caller\n * can use the {@link subscribe} method to be notified when the data changes. When reading data, the caller must first request\n * a snapshot using {@link getSnapshot}. All values returned by gettors are relative to a specified snapshot. The values will be\n * consistent with each other as long as the same snapshot is used.\n * \n * @typeParam Snapshot - Type of snapshot. Implementations are free to use whatever type makes sense for them.\n */\nexport interface SpreadsheetData<Snapshot> {\n /** Subscribe to data changes */\n subscribe(onDataChange: () => void): () => void,\n\n /** Return a snapshot to use when accessing values at a consistent point in time */\n getSnapshot(): Snapshot,\n\n /** Number of rows in the spreadsheet */\n getRowCount(snapshot: Snapshot): number,\n\n /** {@link ItemOffsetMapping} which describes sizes and offsets to start of rows */\n getRowItemOffsetMapping(snapshot: Snapshot): ItemOffsetMapping,\n\n /** Number of columns in the spreadsheet */\n getColumnCount(snapshot: Snapshot): number,\n\n /** {@link ItemOffsetMapping} which describes sizes and offsets to start of columns */\n getColumnItemOffsetMapping(snapshot: Snapshot): ItemOffsetMapping,\n\n /** Value of specified cell using 0-based row and column indexes */\n getCellValue(snapshot: Snapshot, row: number, column: number): CellValue;\n\n /** Format of specified cell using 0-based row and column indexes */\n getCellFormat(snapshot: Snapshot, row: number, column: number): string | undefined;\n\n /** Set value and format of specified cell\n * \n * @returns True if the change was successfully applied\n */\n setCellValueAndFormat(row: number, column: number, value: CellValue, format: string | undefined): boolean;\n}\n\nconst rowItemOffsetMapping = new FixedSizeItemOffsetMapping(30);\nconst columnItemOffsetMapping = new FixedSizeItemOffsetMapping(100);\n\nexport class EmptySpreadsheetData implements SpreadsheetData<number> {\n subscribe(_onDataChange: () => void) { return () => {}; }\n getSnapshot() { return 0; }\n \n getRowCount(_snapshot: number) { return 0; }\n getRowItemOffsetMapping(_snapshot: number): ItemOffsetMapping { return rowItemOffsetMapping; }\n getColumnCount(_snapshot: number) { return 0; }\n getColumnItemOffsetMapping(_snapshot: number): ItemOffsetMapping { return columnItemOffsetMapping; }\n getCellValue(_snapshot: number, _row: number, _column: number): CellValue { return null; }\n getCellFormat(_snapshot: number, _row: number, _column: number): string|undefined { return undefined; }\n setCellValueAndFormat(_row: number, _column: number, _value: CellValue, _format: string | undefined): boolean { return false; }\n}\n\n","/** Classic Spreadsheet reference to Column (e.g \"A\") */\nexport type ColRef = string;\n\n/** Classic Spreadsheet reference to Cell (e.g. \"A1\"), Row (e.g. \"1\") or Column (e.g \"A\") */\nexport type RowColRef = string;\n\n/** Equivalent to {@link RowColRef} as coordinate pair. \"A1\" has coords [0,0], \"1\" is [0,undefined] and \"A\" is [undefined,0] */\nexport type RowColCoords = [row: number|undefined, col: number|undefined];\n\n/** Converts a {@link ColRef} to the 0-based index of the column */\nexport function colRefToIndex(col: ColRef): number {\n let n = 0;\n for (let i = 0; i < col.length; i ++) {\n n = col.charCodeAt(i) - 64 + n * 26;\n }\n return n-1;\n}\n\n/** Converts a 0-based column index to a {@link ColRef} */\nexport function indexToColRef(index: number): ColRef {\n let ret = \"\";\n index ++;\n while (index > 0) {\n index --;\n const remainder = index % 26;\n index = Math.floor(index / 26);\n ret = String.fromCharCode(65+remainder) + ret;\n }\n return ret;\n}\n\n/** Splits a RowColRef into a 0-based row index and a {@link ColRef} */\nexport function splitRowColRef(ref: RowColRef): [row: number|undefined, col: ColRef|undefined] {\n const re = /^([A-Z]*)(\\d*)$/;\n const found = ref.match(re);\n if (!found)\n return [undefined,undefined];\n\n const col = found[1];\n const row = found[2] ? parseInt(found[2]) : 0;\n return [(row>0) ? row-1 : undefined, col ? col : undefined];\n}\n\n/** Converts a {@link RowColRef} to {@link RowColCoords} */\nexport function rowColRefToCoords(ref: RowColRef): RowColCoords {\n const [row,col] = splitRowColRef(ref);\n return [row, col ? colRefToIndex(col) : undefined];\n}\n\n/** Converts {@link RowColCoords} to a {@link RowColRef} */\nexport function rowColCoordsToRef(row: number|undefined, col: number|undefined): RowColRef {\n if (row !== undefined) {\n if (col !== undefined) {\n return indexToColRef(col) + (row+1);\n } else {\n return (row+1).toString();\n }\n } else {\n if (col !== undefined) {\n return indexToColRef(col);\n } else {\n return \"\";\n }\n }\n}"],"names":[],"mappings":"AAEA;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AAC,SAAS,CAAC;AAE9B,IAAA,MAAM,GAAG,GAAG,KAAK,CAAC,CAAC,CAAC;IACpB,MAAM,GAAG,GAAG,KAAK,CAAC,CAAC,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC;IAC7C,OAAO,CAAC,CAAC,GAAG,GAAC,CAAC,IAAI,GAAG,GAAC,CAAC,GAAG,SAAS,EAAE,GAAG,GAAG,GAAG,GAAG,SAAS,CAAC;AAC7D;AAEA;AACM,SAAU,iBAAiB,CAAC,GAAc,EAAA;IAC9C,MAAM,CAAC,GAAG,EAAC,GAAG,CAAC,GAAG,cAAc,CAAC,GAAG,CAAC;AACrC,IAAA,OAAO,CAAC,GAAG,EAAE,GAAG,GAAG,aAAa,CAAC,GAAG,CAAC,GAAG,SAAS,CAAC;AACpD;AAEA;AACgB,SAAA,iBAAiB,CAAC,GAAqB,EAAE,GAAqB,EAAA;AAC5E,IAAA,IAAI,GAAG,KAAK,SAAS,EAAE;AACrB,QAAA,IAAI,GAAG,KAAK,SAAS,EAAE;YACrB,OAAO,aAAa,CAAC,GAAG,CAAC,IAAI,GAAG,GAAC,CAAC,CAAC;;aAC9B;YACL,OAAO,CAAC,GAAG,GAAC,CAAC,EAAE,QAAQ,EAAE;;;SAEtB;AACL,QAAA,IAAI,GAAG,KAAK,SAAS,EAAE;AACrB,YAAA,OAAO,aAAa,CAAC,GAAG,CAAC;;aACpB;AACL,YAAA,OAAO,EAAE;;;AAGf;;;;"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@candidstartup/infinisheet-types",
3
3
  "private": false,
4
- "version": "0.8.0",
4
+ "version": "0.9.0",
5
5
  "description": "Common types for the InfiniSheet packages",
6
6
  "author": "Tim Wiegand <tim.wiegand@thecandidstartup.org>",
7
7
  "license": "BSD-3-Clause",
@@ -49,5 +49,5 @@
49
49
  "test": "vitest"
50
50
  },
51
51
  "main": "index.js",
52
- "gitHead": "5f783ed7b6eef96cbc72fb8972ba04d6033f9ece"
52
+ "gitHead": "8035218a392af0bc15c99ff272536ba8ef841c49"
53
53
  }