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

Function parseSegments

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

Source from the content-addressed store, hash-verified

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

Callers 1

useTokenFieldFunction · 0.85

Calls 1

parseMethod · 0.45

Tested by

no test coverage detected