How to use @tanker/global-this - 10 common examples

To help you get started, we’ve selected a few @tanker/global-this examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github TankerHQ / sdk-js / packages / types / src / data-types.js View on Github external
const dataTypeDefs = (() => {
  const defs = [];
  if (globalThis.ArrayBuffer !== undefined)
    defs.push({ type: ArrayBuffer, lengthOf: (arg: ArrayBuffer) => arg.byteLength });
  if (globalThis.Buffer !== undefined)
    defs.push({ type: Buffer, lengthOf: (arg: Buffer) => arg.length }); // MUST be before Uint8Array
  if (globalThis.Uint8Array !== undefined)
    defs.push({ type: Uint8Array, lengthOf: (arg: Uint8Array) => arg.length });
  if (globalThis.File !== undefined) {
    defs.push({ type: File, lengthOf: (arg: File) => arg.size }); // MUST be before FilePonyfill and Blob
    defs.push({ type: FilePonyfill, lengthOf: (arg: FilePonyfill) => arg.size }); // MUST be before Blob
  }
  if (globalThis.Blob !== undefined)
    defs.push({ type: Blob, lengthOf: (arg: Blob) => arg.size });
  return defs;
})();
github TankerHQ / sdk-js / packages / core / src / DataProtection / options.js View on Github external
// @flow
import type { b64string } from '@tanker/crypto';
import { InternalError, InvalidArgument } from '@tanker/errors';
import globalThis from '@tanker/global-this';
import { getConstructor, type Data } from '@tanker/types';

import type { OnProgress } from './ProgressHandler';

export const defaultDownloadType = globalThis.File ? globalThis.File : Uint8Array;

export type OutputOptions = { type: Class, mime?: string, name?: string, lastModified?: number };

export type ProgressOptions = { onProgress?: OnProgress };

export type SharingOptions = { shareWithUsers?: Array, shareWithGroups?: Array };

export const isObject = (val: Object) => !!val && typeof val === 'object' && Object.getPrototypeOf(val) === Object.prototype;

export const extractSharingOptions = (options: Object): SharingOptions => {
  const error = new InvalidArgument('options', '{ shareWithUsers?: Array, shareWithGroups?: Array }', options);

  if (!isObject(options))
    throw error;

  const sharingOptions = {};
github TankerHQ / sdk-js / packages / types / src / data-types.js View on Github external
export const getConstructorName = (constructor: Object): string => {
  if (constructor === ArrayBuffer)
    return 'ArrayBuffer';
  if (globalThis.Buffer && constructor === Buffer)
    return 'Buffer';
  if (constructor === Uint8Array)
    return 'Uint8Array';
  if (globalThis.File && (constructor === File || constructor === FilePonyfill)) // must be before Blob
    return 'File';
  if (globalThis.Blob && constructor === Blob)
    return 'Blob';
  throw new InternalError('Assertion error: unhandled type');
};
github TankerHQ / sdk-js / packages / types / src / data-types.js View on Github external
const dataTypeDefs = (() => {
  const defs = [];
  if (globalThis.ArrayBuffer !== undefined)
    defs.push({ type: ArrayBuffer, lengthOf: (arg: ArrayBuffer) => arg.byteLength });
  if (globalThis.Buffer !== undefined)
    defs.push({ type: Buffer, lengthOf: (arg: Buffer) => arg.length }); // MUST be before Uint8Array
  if (globalThis.Uint8Array !== undefined)
    defs.push({ type: Uint8Array, lengthOf: (arg: Uint8Array) => arg.length });
  if (globalThis.File !== undefined) {
    defs.push({ type: File, lengthOf: (arg: File) => arg.size }); // MUST be before FilePonyfill and Blob
    defs.push({ type: FilePonyfill, lengthOf: (arg: FilePonyfill) => arg.size }); // MUST be before Blob
  }
  if (globalThis.Blob !== undefined)
    defs.push({ type: Blob, lengthOf: (arg: Blob) => arg.size });
  return defs;
})();
github TankerHQ / sdk-js / packages / types / src / data-types.js View on Github external
export const getConstructorName = (constructor: Object): string => {
  if (constructor === ArrayBuffer)
    return 'ArrayBuffer';
  if (globalThis.Buffer && constructor === Buffer)
    return 'Buffer';
  if (constructor === Uint8Array)
    return 'Uint8Array';
  if (globalThis.File && (constructor === File || constructor === FilePonyfill)) // must be before Blob
    return 'File';
  if (globalThis.Blob && constructor === Blob)
    return 'Blob';
  throw new InternalError('Assertion error: unhandled type');
};
github TankerHQ / sdk-js / packages / types / src / data-types.js View on Github external
const dataTypeDefs = (() => {
  const defs = [];
  if (globalThis.ArrayBuffer !== undefined)
    defs.push({ type: ArrayBuffer, lengthOf: (arg: ArrayBuffer) => arg.byteLength });
  if (globalThis.Buffer !== undefined)
    defs.push({ type: Buffer, lengthOf: (arg: Buffer) => arg.length }); // MUST be before Uint8Array
  if (globalThis.Uint8Array !== undefined)
    defs.push({ type: Uint8Array, lengthOf: (arg: Uint8Array) => arg.length });
  if (globalThis.File !== undefined) {
    defs.push({ type: File, lengthOf: (arg: File) => arg.size }); // MUST be before FilePonyfill and Blob
    defs.push({ type: FilePonyfill, lengthOf: (arg: FilePonyfill) => arg.size }); // MUST be before Blob
  }
  if (globalThis.Blob !== undefined)
    defs.push({ type: Blob, lengthOf: (arg: Blob) => arg.size });
  return defs;
})();
github TankerHQ / sdk-js / packages / types / src / data-types.js View on Github external
export const getConstructorName = (constructor: Object): string => {
  if (constructor === ArrayBuffer)
    return 'ArrayBuffer';
  if (globalThis.Buffer && constructor === Buffer)
    return 'Buffer';
  if (constructor === Uint8Array)
    return 'Uint8Array';
  if (globalThis.File && (constructor === File || constructor === FilePonyfill)) // must be before Blob
    return 'File';
  if (globalThis.Blob && constructor === Blob)
    return 'Blob';
  throw new InternalError('Assertion error: unhandled type');
};
github TankerHQ / sdk-js / packages / types / src / data-types.js View on Github external
const dataTypeDefs = (() => {
  const defs = [];
  if (globalThis.ArrayBuffer !== undefined)
    defs.push({ type: ArrayBuffer, lengthOf: (arg: ArrayBuffer) => arg.byteLength });
  if (globalThis.Buffer !== undefined)
    defs.push({ type: Buffer, lengthOf: (arg: Buffer) => arg.length }); // MUST be before Uint8Array
  if (globalThis.Uint8Array !== undefined)
    defs.push({ type: Uint8Array, lengthOf: (arg: Uint8Array) => arg.length });
  if (globalThis.File !== undefined) {
    defs.push({ type: File, lengthOf: (arg: File) => arg.size }); // MUST be before FilePonyfill and Blob
    defs.push({ type: FilePonyfill, lengthOf: (arg: FilePonyfill) => arg.size }); // MUST be before Blob
  }
  if (globalThis.Blob !== undefined)
    defs.push({ type: Blob, lengthOf: (arg: Blob) => arg.size });
  return defs;
})();
github TankerHQ / sdk-js / packages / types / src / data-types.js View on Github external
const dataTypeDefs = (() => {
  const defs = [];
  if (globalThis.ArrayBuffer !== undefined)
    defs.push({ type: ArrayBuffer, lengthOf: (arg: ArrayBuffer) => arg.byteLength });
  if (globalThis.Buffer !== undefined)
    defs.push({ type: Buffer, lengthOf: (arg: Buffer) => arg.length }); // MUST be before Uint8Array
  if (globalThis.Uint8Array !== undefined)
    defs.push({ type: Uint8Array, lengthOf: (arg: Uint8Array) => arg.length });
  if (globalThis.File !== undefined) {
    defs.push({ type: File, lengthOf: (arg: File) => arg.size }); // MUST be before FilePonyfill and Blob
    defs.push({ type: FilePonyfill, lengthOf: (arg: FilePonyfill) => arg.size }); // MUST be before Blob
  }
  if (globalThis.Blob !== undefined)
    defs.push({ type: Blob, lengthOf: (arg: Blob) => arg.size });
  return defs;
})();
github TankerHQ / sdk-js / packages / core / src / DataProtection / options.js View on Github external
if (options.type) {
    outputType = options.type;
  } else if (input) {
    outputType = getConstructor(input);
  } else {
    throw new InternalError('Assertion error: called extractOutputOptions without a type or input');
  }

  const outputOptions = {};
  outputOptions.type = outputType;

  if (globalThis.Blob && input instanceof globalThis.Blob) {
    outputOptions.mime = input.type;
  }
  if (globalThis.File && input instanceof globalThis.File) {
    outputOptions.name = input.name;
    outputOptions.lastModified = input.lastModified;
  }

  if (typeof options.mime === 'string') {
    outputOptions.mime = options.mime;
  }
  if (typeof options.name === 'string') {
    outputOptions.name = options.name;
  }
  if (typeof options.lastModified === 'number') {
    outputOptions.lastModified = options.lastModified;
  }

  return outputOptions;
};

@tanker/global-this

Tanker SDK (global-this)

Apache-2.0
Latest version published 6 months ago

Package Health Score

61 / 100
Full package analysis

Similar packages