pluckKey function

IValidator pluckKey(
  1. String key,
  2. IValidator child, {
  3. String? message,
})

Plucks a single key's value from a Map (similar to getField but transform style).

Implementation

IValidator pluckKey(String key, IValidator child, {String? message}) {
  return core.pivotValue(
    (value) {
      if (value is! Map || !value.containsKey(key)) return null;
      return value[key];
    },
    child: child,
    errorMessage: message ?? 'a Map containing key: $key',
  );
}