MCPcopy Create free account
hub / github.com/adobe/react-spectrum / parseSegments

Function parseSegments

packages/react-aria/src/tokenfield/useTokenField.ts:871–881  ·  view source on GitHub ↗
(json: string)

Source from the content-addressed store, hash-verified

869// JSON or does not match the expected shape, so malformed or untrusted data is ignored rather
870// than throwing or being inserted into the field.
871function parseSegments(json: string): TokenFieldSegment[] | null {
872 try {
873 let data = JSON.parse(json);
874 if (Array.isArray(data) && data.length > 0 && data.every(isValidSegment)) {
875 return data;
876 }
877 } catch {
878 // Ignore invalid clipboard data.
879 }
880 return null;
881}
882
883function isValidSegment(segment: unknown): segment is TokenFieldSegment {
884 return (

Callers 1

useTokenFieldFunction · 0.85

Calls 1

parseMethod · 0.45

Tested by

no test coverage detected