Skip to content

Commit

Permalink
Split getValue out of readPdf to reuse it for reading dictionaries
Browse files Browse the repository at this point in the history
  • Loading branch information
vbuch committed Nov 29, 2023
1 parent 0f1bf61 commit 7ff6a32
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 21 deletions.
19 changes: 19 additions & 0 deletions packages/placeholder-plain/src/getValue.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
* @param {Buffer} trailer
* @param {string} key
* @returns {string}
*/
export const getValue = (trailer, key) => {
let index = trailer.indexOf(key);

if (index === -1) {
return undefined;
}

const slice = trailer.subarray(index);
index = slice.indexOf('/', 1);
if (index === -1) {
index = slice.indexOf('>', 1);
}
return slice.subarray(key.length + 1, index).toString().trim(); // key + at least one space
};
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {getValue} from './readPdf';
import {getValue} from './getValue';

describe(getValue, () => {
it('matches snapshots', () => {
Expand Down
21 changes: 1 addition & 20 deletions packages/placeholder-plain/src/readPdf.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,6 @@
import readRefTable from './readRefTable';
import findObject from './findObject';

/**
* @param {Buffer} trailer
* @param {string} key
* @returns {string}
*/
export const getValue = (trailer, key) => {
let index = trailer.indexOf(key);

if (index === -1) {
return undefined;
}

const slice = trailer.slice(index);
index = slice.indexOf('/', 1);
if (index === -1) {
index = slice.indexOf('>', 1);
}
return slice.slice(key.length + 1, index).toString().trim(); // key + at least one space
};
import {getValue} from './getValue';

/**
* @typedef {object} ReadPdfReturnType
Expand Down

0 comments on commit 7ff6a32

Please sign in to comment.