UNPKG

pdf-lib

Version:

Library for creating and modifying PDF files in JavaScript

42 lines (41 loc) 1.72 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; } Object.defineProperty(exports, "__esModule", { value: true }); /* tslint:disable:ban-types */ var forEach_1 = __importDefault(require("lodash/forEach")); // Need this for React Native Android. // Need to import the minified version because it is ES5 not ES6 - which is // required to us "uglify" for minification. require("proxy-polyfill/proxy.min.js"); // Need this for React Native Android var validate_1 = require("./validate"); var EMPTY_ARR = []; // TODO: See if this can be refined/simplified at all... exports.typedArrayProxy = function (obj, type, config) { if (config === void 0) { config = {}; } forEach_1.default(config.methods, function (val, key) { obj[key] = new Proxy(obj[key], { apply: function (target, thisArg, elements) { return val(function (args) { return target.apply(thisArg, args); }, elements); }, }); }); return new Proxy(obj, { set: function (target, property, value, receiver) { if (!(property in EMPTY_ARR)) { validate_1.validate(value, validate_1.isInstance(type), "Typed Array Proxy elements must be of type " + type.name); } if (config.set) config.set(property, value); target[property] = value; return true; }, get: function (target, property, receiver) { if (config.get && config.get(property)) { return config.get(property)(target[property]); } return target[property]; }, }); };