rtti.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.isError = isError;
  6. exports.isLikelyNpxGlobal = void 0;
  7. exports.isObject = isObject;
  8. exports.isRegExp = isRegExp;
  9. exports.isString = isString;
  10. /**
  11. * Copyright (c) Microsoft Corporation.
  12. *
  13. * Licensed under the Apache License, Version 2.0 (the "License");
  14. * you may not use this file except in compliance with the License.
  15. * You may obtain a copy of the License at
  16. *
  17. * http://www.apache.org/licenses/LICENSE-2.0
  18. *
  19. * Unless required by applicable law or agreed to in writing, software
  20. * distributed under the License is distributed on an "AS IS" BASIS,
  21. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  22. * See the License for the specific language governing permissions and
  23. * limitations under the License.
  24. */
  25. function isString(obj) {
  26. return typeof obj === 'string' || obj instanceof String;
  27. }
  28. function isRegExp(obj) {
  29. return obj instanceof RegExp || Object.prototype.toString.call(obj) === '[object RegExp]';
  30. }
  31. function isObject(obj) {
  32. return typeof obj === 'object' && obj !== null;
  33. }
  34. function isError(obj) {
  35. var _Object$getPrototypeO;
  36. return obj instanceof Error || obj && ((_Object$getPrototypeO = Object.getPrototypeOf(obj)) === null || _Object$getPrototypeO === void 0 ? void 0 : _Object$getPrototypeO.name) === 'Error';
  37. }
  38. const isLikelyNpxGlobal = () => process.argv.length >= 2 && process.argv[1].includes('_npx');
  39. exports.isLikelyNpxGlobal = isLikelyNpxGlobal;