stoplightio/json

View on GitHub
src/extractSourceFromRef.ts

Summary

Maintainability
A
0 mins
Test Coverage
A
100%
import { isExternalRef } from './isExternalRef';

export const extractSourceFromRef = (ref: unknown): string | null => {
  if (typeof ref !== 'string' || ref.length === 0 || !isExternalRef(ref)) {
    return null;
  }

  const index = ref.indexOf('#');
  return index === -1 ? ref : ref.slice(0, index);
};