2
0

ModuleRequestExtensions.cs 767 B

123456789101112131415161718192021
  1. namespace Jint.Runtime.Modules;
  2. public static class ModuleRequestExtensions
  3. {
  4. /// <summary>
  5. /// Returns true if the provided <paramref name="request"/>
  6. /// is a json module, otherwise false.
  7. /// </summary>
  8. /// <example>
  9. /// The following JavaScript import statement imports a JSON module
  10. /// for which this method would return true.
  11. /// <code>
  12. /// import value from 'config.json' with { type: 'json' }
  13. /// </code>
  14. /// </example>
  15. public static bool IsJsonModule(this ModuleRequest request)
  16. {
  17. return request.Attributes != null
  18. && Array.Exists(request.Attributes, x => string.Equals(x.Key, "type", StringComparison.Ordinal) && string.Equals(x.Value, "json", StringComparison.Ordinal));
  19. }
  20. }