How to use tiny-invariant - 10 common examples

To help you get started, we’ve selected a few tiny-invariant 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 atlassian / react-beautiful-dnd / src / view / draggable / check-own-props.js View on Github external
export default (props: Props) => {
  // Number.isInteger will be provided by @babel/runtime-corejs2
  invariant(
    Number.isInteger(props.index),
    'Draggable requires an integer index prop',
  );
  invariant(props.draggableId, 'Draggable requires a draggableId');
  invariant(
    typeof props.isDragDisabled === 'boolean',
    'isDragDisabled must be a boolean',
  );
};
github atlassian / react-beautiful-dnd / src / view / use-droppable-dimension-publisher / use-droppable-dimension-publisher.js View on Github external
(windowScroll: Position, options: ScrollOptions) => {
      invariant(
        !whileDraggingRef.current,
        'Cannot collect a droppable while a drag is occurring',
      );
      const previous: Props = previousRef.current;
      const ref: ?HTMLElement = previous.getDroppableRef();
      invariant(ref, 'Cannot collect without a droppable ref');
      const env: Env = getEnv(ref);

      const dragging: WhileDragging = {
        ref,
        descriptor,
        env,
        scrollOptions: options,
      };
      // side effect
      whileDraggingRef.current = dragging;
github commercetools / ui-kit / src / components / internals / rich-text-plugins / plugins / mark.js View on Github external
const MarkPlugin = (options = {}) => {
  const missingRequiredOptions = validate(options);

  invariant(
    missingRequiredOptions.length >= 0,
    `ui-kit/rich-text-input/Mark: missing required options: ${missingRequiredOptions.join(
      ','
    )}`
  );

  const isHotKey = memoizedIsHotkey(options.hotkey);

  return [
    {
      // eslint-disable-next-line consistent-return
      onKeyDown(event, editor, next) {
        if (!isHotKey(event)) {
          return next();
        }
github atlassian / react-beautiful-dnd / src / state / droppable / with-placeholder.js View on Github external
if (!frame) {
    const subject: DroppableSubject = getSubject({
      page: droppable.subject.page,
      axis: droppable.axis,
      frame: null,
      // cleared
      withPlaceholder: null,
    });
    return {
      ...droppable,
      subject,
    };
  }

  const oldMaxScroll: ?Position = added.oldFrameMaxScroll;
  invariant(
    oldMaxScroll,
    'Expected droppable with frame to have old max frame scroll when removing placeholder',
  );

  const newFrame: Scrollable = withMaxScroll(frame, oldMaxScroll);

  const subject: DroppableSubject = getSubject({
    page: droppable.subject.page,
    axis: droppable.axis,
    frame: newFrame,
    // cleared
    withPlaceholder: null,
  });
  return {
    ...droppable,
    subject,
github walnutdust / perusal / es / utils.js View on Github external
export function assert(value, spec) {
  // getSpec allows us to pass it strings to retrive previously defined specs.
  invariant(
    typeof spec === 'string' || spec instanceof Spec,
    'Invalid spec '.concat(spec, ' passed to perusal.assert.')
  );
  var specification = getSpec(spec); // If the value was previous asserted with this specification, simply return the
  // previous result.

  if (value.specs && value.specs[specification.name]) return value.specs[specification.name];
  return specification.assert(value);
}
/**
github atlassian / react-beautiful-dnd / src / view / use-drag-handle / util / get-drag-handle-ref.js View on Github external
const throwIfSVG = (el: mixed) => {
  invariant(
    !isSvgElement(el),
    `A drag handle cannot be an SVGElement: it has inconsistent focus support.

    More information: https://github.com/atlassian/react-beautiful-dnd/blob/master/docs/guides/dragging-svgs.md`,
  );
};
github makuga01 / dnsFookup / FE / node_modules / react-router / esm / react-router.js View on Github external
function useParams() {
  if (process.env.NODE_ENV !== "production") {
    !(typeof useContext === "function") ? process.env.NODE_ENV !== "production" ? invariant(false, "You must use React >= 16.8 in order to use useParams()") : invariant(false) : void 0;
  }

  var match = useContext(context).match;
  return match ? match.params : {};
}
function useRouteMatch(path) {
github walnutdust / perusal-immutable / es / spec / and.js View on Github external
export function and(name) {
  invariant(typeof name === 'string', 'perusal-immutable.and was called with an invalid name.');

  for (
    var _len = arguments.length, specs = new Array(_len > 1 ? _len - 1 : 0), _key = 1;
    _key < _len;
    _key++
  ) {
    specs[_key - 1] = arguments[_key];
  }

  invariant(specs.length > 0, 'perusal-immutable.and was called without specs.');

  for (var _i = 0, _specs = specs; _i < _specs.length; _i++) {
    var spec = _specs[_i];
    invariant(spec instanceof Spec, 'perusal-immutable.and was called with invalid specs.');
  }

  return new And(name, specs);
}
github walnutdust / perusal-immutable / src / utils.ts View on Github external
export function getSpec(maybeSpec: string | Spec) {
  if (maybeSpec instanceof Spec) return maybeSpec;

  invariant(defs[maybeSpec], `Specification for ${maybeSpec} does not exist!`);
  return defs[maybeSpec];
}
github walnutdust / perusal-immutable / src / spec / pred.ts View on Github external
export const pred = (name: string, fn: (value: any) => boolean) => {
  invariant(
    fn && typeof fn === 'function',
    'perusal-immutable.pred was called with an invalid predicate.'
  );

  invariant(
    name && typeof name === 'string',
    'perusal-immutable.pred was called with an invalid string.'
  );

  return new Pred(name, fn);
};

tiny-invariant

A tiny invariant function

MIT
Latest version published 9 months ago

Package Health Score

77 / 100
Full package analysis

Popular tiny-invariant functions