MCPcopy
hub / github.com/jestjs/jest / pathAsArray

Function pathAsArray

packages/expect-utils/src/utils.ts:534–556  ·  view source on GitHub ↗
(propertyPath: string)

Source from the content-addressed store, hash-verified

532};
533
534export const pathAsArray = (propertyPath: string): Array<any> => {
535 const properties: Array<string> = [];
536
537 if (propertyPath === '') {
538 properties.push('');
539 return properties;
540 }
541
542 // will match everything that's not a dot or a bracket, and "" for consecutive dots.
543 const pattern = new RegExp('[^.[\\]]+|(?=(?:\\.)(?:\\.|$))', 'g');
544
545 // Because the regex won't match a dot in the beginning of the path, if present.
546 if (propertyPath[0] === '.') {
547 properties.push('');
548 }
549
550 propertyPath.replaceAll(pattern, match => {
551 properties.push(match);
552 return match;
553 });
554
555 return properties;
556};
557
558// Copied from https://github.com/graingert/angular.js/blob/a43574052e9775cbc1d7dd8a086752c979b0f020/src/Angular.js#L685-L693
559export const isError = (value: unknown): value is Error => {

Callers 2

toHavePropertyFunction · 0.90
getPathFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected