import { getPosition , getValue } from "data-with-position" ; import kindOf from "kind-of" ; import _ from "lodash" ; import { Position } from "unist" ; import { LitvisDocument } from "../../types" ; export const extractFollows = ( dataWithPosition , document ) : { value ? : string ; position ? : Position ; } => { const followsWithPosition = dataWithPosition . follows ; if ( ! _ . isUndefined ( followsWithPosition ) ) { const rawValue = getValue ( followsWithPosition ) ; const position = getPosition ( followsWithPosition ) ; if ( _ . isNull ( rawValue ) ) { } else if ( ! _ . isString ( rawValue ) ) { document . message ( `‘follows’ has to be a string, ${ kindOf ( rawValue ) } given. Value ignored.` , position , "litvis:frontmatter-follows" ) ; } else if ( rawValue . match ( /\n/g ) ) { document . message ( `‘follows’ cannot contain newlines. Value ignored.` , position , "litvis:frontmatter-follows" ) ; } else { const normalizedValue = rawValue . trim ( ) ; if ( normalizedValue !== rawValue ) { document . info ( `Surrounded spaces in ‘follows’ were trimmed.` , position , "litvis:frontmatter-follows" ) ; } return { value : normalizedValue , position , } ; } } return { } ; } ;