Comparing version 0.5.0 to 0.5.1
'use strict'; | ||
var isFileEsm = require('is-file-esm'); | ||
var url = require('url'); | ||
@@ -10,2 +9,23 @@ var glob = require('glob'); | ||
function ownKeys(object, enumerableOnly) { | ||
var keys = Object.keys(object); | ||
if (Object.getOwnPropertySymbols) { | ||
var symbols = Object.getOwnPropertySymbols(object); | ||
enumerableOnly && (symbols = symbols.filter(function (sym) { | ||
return Object.getOwnPropertyDescriptor(object, sym).enumerable; | ||
})), keys.push.apply(keys, symbols); | ||
} | ||
return keys; | ||
} | ||
function _objectSpread2(target) { | ||
for (var i = 1; i < arguments.length; i++) { | ||
var source = null != arguments[i] ? arguments[i] : {}; | ||
i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { | ||
_defineProperty(target, key, source[key]); | ||
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { | ||
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); | ||
}); | ||
} | ||
return target; | ||
} | ||
function _regeneratorRuntime() { | ||
@@ -351,2 +371,30 @@ _regeneratorRuntime = function () { | ||
} | ||
function _defineProperty(obj, key, value) { | ||
key = _toPropertyKey(key); | ||
if (key in obj) { | ||
Object.defineProperty(obj, key, { | ||
value: value, | ||
enumerable: true, | ||
configurable: true, | ||
writable: true | ||
}); | ||
} else { | ||
obj[key] = value; | ||
} | ||
return obj; | ||
} | ||
function _toPrimitive(input, hint) { | ||
if (typeof input !== "object" || input === null) return input; | ||
var prim = input[Symbol.toPrimitive]; | ||
if (prim !== undefined) { | ||
var res = prim.call(input, hint || "default"); | ||
if (typeof res !== "object") return res; | ||
throw new TypeError("@@toPrimitive must return a primitive value."); | ||
} | ||
return (hint === "string" ? String : Number)(input); | ||
} | ||
function _toPropertyKey(arg) { | ||
var key = _toPrimitive(arg, "string"); | ||
return typeof key === "symbol" ? key : String(key); | ||
} | ||
@@ -404,30 +452,2 @@ /* | ||
/* | ||
* Copyright (c) 2022. | ||
* Author Peter Placzek (tada5hi) | ||
* For the full copyright and license information, | ||
* view the LICENSE file that was distributed with this source code. | ||
*/ | ||
function getExportItem(data, filterFn) { | ||
if (filterFn) { | ||
var keys = Object.keys(data); | ||
for (var i = 0; i < keys.length; i++) { | ||
if (filterFn(keys[i], data[keys[i]])) { | ||
return { | ||
key: keys[i], | ||
value: data[keys[i]] | ||
}; | ||
} | ||
} | ||
} else { | ||
return { | ||
key: 'default', | ||
value: hasOwnProperty(data, 'default') ? data["default"] : data | ||
}; | ||
} | ||
/* istanbul ignore next */ | ||
return undefined; | ||
} | ||
function buildLocatorOptions(options) { | ||
@@ -644,8 +664,36 @@ var _options, _options$ignore; | ||
function loadScriptFile(_x) { | ||
/* | ||
* Copyright (c) 2022. | ||
* Author Peter Placzek (tada5hi) | ||
* For the full copyright and license information, | ||
* view the LICENSE file that was distributed with this source code. | ||
*/ | ||
function getExportItem(data, filterFn) { | ||
if (filterFn) { | ||
var keys = Object.keys(data); | ||
for (var i = 0; i < keys.length; i++) { | ||
if (filterFn(keys[i], data[keys[i]])) { | ||
return { | ||
key: keys[i], | ||
value: data[keys[i]] | ||
}; | ||
} | ||
} | ||
} else { | ||
return { | ||
key: 'default', | ||
value: hasOwnProperty(data, 'default') ? data["default"] : data | ||
}; | ||
} | ||
/* istanbul ignore next */ | ||
return undefined; | ||
} | ||
function loadScriptFile(_x, _x2) { | ||
return _loadScriptFile.apply(this, arguments); | ||
} | ||
function _loadScriptFile() { | ||
_loadScriptFile = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(data) { | ||
var locatorInfo, filePath, check; | ||
_loadScriptFile = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(data, options) { | ||
var locatorInfo, filePath; | ||
return _regeneratorRuntime().wrap(function _callee$(_context) { | ||
@@ -656,33 +704,39 @@ while (1) { | ||
if (typeof data === 'string') { | ||
filePath = data; | ||
locatorInfo = pathToLocatorInfo(data); | ||
} else { | ||
filePath = buildLoaderFilePath(data, true); | ||
locatorInfo = data; | ||
} | ||
_context.prev = 1; | ||
if (!(['.js', '.mjs', '.cjs'].indexOf(locatorInfo.extension) !== -1)) { | ||
_context.next = 10; | ||
options = options || {}; | ||
filePath = buildLoaderFilePath(locatorInfo, options.withExtension); | ||
if (options.withFilePrefix) { | ||
filePath = url.pathToFileURL(filePath).href; | ||
} | ||
_context.prev = 4; | ||
_context.next = 7; | ||
return import(filePath); | ||
case 7: | ||
return _context.abrupt("return", _context.sent); | ||
case 10: | ||
_context.prev = 10; | ||
_context.t0 = _context["catch"](4); | ||
if (!(_context.t0 instanceof Error && hasOwnProperty(_context.t0, 'code'))) { | ||
_context.next = 17; | ||
break; | ||
} | ||
_context.next = 5; | ||
return isFileEsm(filePath); | ||
case 5: | ||
check = _context.sent; | ||
if (!check.esm) { | ||
_context.next = 10; | ||
if (!(_context.t0.code === 'ERR_MODULE_NOT_FOUND')) { | ||
_context.next = 15; | ||
break; | ||
} | ||
_context.next = 9; | ||
return import(url.pathToFileURL(filePath).href); | ||
case 9: | ||
return _context.abrupt("return", _context.sent); | ||
case 10: | ||
_context.next = 12; | ||
return import(filePath); | ||
case 12: | ||
return _context.abrupt("return", _context.sent); | ||
return _context.abrupt("return", loadScriptFile(locatorInfo, _objectSpread2(_objectSpread2({}, options), {}, { | ||
withExtension: true | ||
}))); | ||
case 15: | ||
_context.prev = 15; | ||
_context.t0 = _context["catch"](1); | ||
if (!(_context.t0.code === 'ERR_UNSUPPORTED_ESM_URL_SCHEME')) { | ||
_context.next = 17; | ||
break; | ||
} | ||
return _context.abrupt("return", loadScriptFile(locatorInfo, _objectSpread2(_objectSpread2({}, options), {}, { | ||
withFilePrefix: true | ||
}))); | ||
case 17: | ||
return _context.abrupt("return", handleFileLoadError(_context.t0)); | ||
@@ -694,7 +748,7 @@ case 18: | ||
} | ||
}, _callee, null, [[1, 15]]); | ||
}, _callee, null, [[4, 10]]); | ||
})); | ||
return _loadScriptFile.apply(this, arguments); | ||
} | ||
function loadScriptFileExport(_x2, _x3) { | ||
function loadScriptFileExport(_x3, _x4) { | ||
return _loadScriptFileExport.apply(this, arguments); | ||
@@ -701,0 +755,0 @@ } |
@@ -1,2 +0,1 @@ | ||
import isFileEsm from 'is-file-esm'; | ||
import { pathToFileURL } from 'url'; | ||
@@ -8,2 +7,23 @@ import { glob, sync } from 'glob'; | ||
function ownKeys(object, enumerableOnly) { | ||
var keys = Object.keys(object); | ||
if (Object.getOwnPropertySymbols) { | ||
var symbols = Object.getOwnPropertySymbols(object); | ||
enumerableOnly && (symbols = symbols.filter(function (sym) { | ||
return Object.getOwnPropertyDescriptor(object, sym).enumerable; | ||
})), keys.push.apply(keys, symbols); | ||
} | ||
return keys; | ||
} | ||
function _objectSpread2(target) { | ||
for (var i = 1; i < arguments.length; i++) { | ||
var source = null != arguments[i] ? arguments[i] : {}; | ||
i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { | ||
_defineProperty(target, key, source[key]); | ||
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { | ||
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); | ||
}); | ||
} | ||
return target; | ||
} | ||
function _regeneratorRuntime() { | ||
@@ -349,2 +369,30 @@ _regeneratorRuntime = function () { | ||
} | ||
function _defineProperty(obj, key, value) { | ||
key = _toPropertyKey(key); | ||
if (key in obj) { | ||
Object.defineProperty(obj, key, { | ||
value: value, | ||
enumerable: true, | ||
configurable: true, | ||
writable: true | ||
}); | ||
} else { | ||
obj[key] = value; | ||
} | ||
return obj; | ||
} | ||
function _toPrimitive(input, hint) { | ||
if (typeof input !== "object" || input === null) return input; | ||
var prim = input[Symbol.toPrimitive]; | ||
if (prim !== undefined) { | ||
var res = prim.call(input, hint || "default"); | ||
if (typeof res !== "object") return res; | ||
throw new TypeError("@@toPrimitive must return a primitive value."); | ||
} | ||
return (hint === "string" ? String : Number)(input); | ||
} | ||
function _toPropertyKey(arg) { | ||
var key = _toPrimitive(arg, "string"); | ||
return typeof key === "symbol" ? key : String(key); | ||
} | ||
@@ -402,30 +450,2 @@ /* | ||
/* | ||
* Copyright (c) 2022. | ||
* Author Peter Placzek (tada5hi) | ||
* For the full copyright and license information, | ||
* view the LICENSE file that was distributed with this source code. | ||
*/ | ||
function getExportItem(data, filterFn) { | ||
if (filterFn) { | ||
var keys = Object.keys(data); | ||
for (var i = 0; i < keys.length; i++) { | ||
if (filterFn(keys[i], data[keys[i]])) { | ||
return { | ||
key: keys[i], | ||
value: data[keys[i]] | ||
}; | ||
} | ||
} | ||
} else { | ||
return { | ||
key: 'default', | ||
value: hasOwnProperty(data, 'default') ? data["default"] : data | ||
}; | ||
} | ||
/* istanbul ignore next */ | ||
return undefined; | ||
} | ||
function buildLocatorOptions(options) { | ||
@@ -642,8 +662,36 @@ var _options, _options$ignore; | ||
function loadScriptFile(_x) { | ||
/* | ||
* Copyright (c) 2022. | ||
* Author Peter Placzek (tada5hi) | ||
* For the full copyright and license information, | ||
* view the LICENSE file that was distributed with this source code. | ||
*/ | ||
function getExportItem(data, filterFn) { | ||
if (filterFn) { | ||
var keys = Object.keys(data); | ||
for (var i = 0; i < keys.length; i++) { | ||
if (filterFn(keys[i], data[keys[i]])) { | ||
return { | ||
key: keys[i], | ||
value: data[keys[i]] | ||
}; | ||
} | ||
} | ||
} else { | ||
return { | ||
key: 'default', | ||
value: hasOwnProperty(data, 'default') ? data["default"] : data | ||
}; | ||
} | ||
/* istanbul ignore next */ | ||
return undefined; | ||
} | ||
function loadScriptFile(_x, _x2) { | ||
return _loadScriptFile.apply(this, arguments); | ||
} | ||
function _loadScriptFile() { | ||
_loadScriptFile = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(data) { | ||
var locatorInfo, filePath, check; | ||
_loadScriptFile = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(data, options) { | ||
var locatorInfo, filePath; | ||
return _regeneratorRuntime().wrap(function _callee$(_context) { | ||
@@ -654,33 +702,39 @@ while (1) { | ||
if (typeof data === 'string') { | ||
filePath = data; | ||
locatorInfo = pathToLocatorInfo(data); | ||
} else { | ||
filePath = buildLoaderFilePath(data, true); | ||
locatorInfo = data; | ||
} | ||
_context.prev = 1; | ||
if (!(['.js', '.mjs', '.cjs'].indexOf(locatorInfo.extension) !== -1)) { | ||
_context.next = 10; | ||
options = options || {}; | ||
filePath = buildLoaderFilePath(locatorInfo, options.withExtension); | ||
if (options.withFilePrefix) { | ||
filePath = pathToFileURL(filePath).href; | ||
} | ||
_context.prev = 4; | ||
_context.next = 7; | ||
return import(filePath); | ||
case 7: | ||
return _context.abrupt("return", _context.sent); | ||
case 10: | ||
_context.prev = 10; | ||
_context.t0 = _context["catch"](4); | ||
if (!(_context.t0 instanceof Error && hasOwnProperty(_context.t0, 'code'))) { | ||
_context.next = 17; | ||
break; | ||
} | ||
_context.next = 5; | ||
return isFileEsm(filePath); | ||
case 5: | ||
check = _context.sent; | ||
if (!check.esm) { | ||
_context.next = 10; | ||
if (!(_context.t0.code === 'ERR_MODULE_NOT_FOUND')) { | ||
_context.next = 15; | ||
break; | ||
} | ||
_context.next = 9; | ||
return import(pathToFileURL(filePath).href); | ||
case 9: | ||
return _context.abrupt("return", _context.sent); | ||
case 10: | ||
_context.next = 12; | ||
return import(filePath); | ||
case 12: | ||
return _context.abrupt("return", _context.sent); | ||
return _context.abrupt("return", loadScriptFile(locatorInfo, _objectSpread2(_objectSpread2({}, options), {}, { | ||
withExtension: true | ||
}))); | ||
case 15: | ||
_context.prev = 15; | ||
_context.t0 = _context["catch"](1); | ||
if (!(_context.t0.code === 'ERR_UNSUPPORTED_ESM_URL_SCHEME')) { | ||
_context.next = 17; | ||
break; | ||
} | ||
return _context.abrupt("return", loadScriptFile(locatorInfo, _objectSpread2(_objectSpread2({}, options), {}, { | ||
withFilePrefix: true | ||
}))); | ||
case 17: | ||
return _context.abrupt("return", handleFileLoadError(_context.t0)); | ||
@@ -692,7 +746,7 @@ case 18: | ||
} | ||
}, _callee, null, [[1, 15]]); | ||
}, _callee, null, [[4, 10]]); | ||
})); | ||
return _loadScriptFile.apply(this, arguments); | ||
} | ||
function loadScriptFileExport(_x2, _x3) { | ||
function loadScriptFileExport(_x3, _x4) { | ||
return _loadScriptFileExport.apply(this, arguments); | ||
@@ -699,0 +753,0 @@ } |
@@ -0,4 +1,9 @@ | ||
import { LocatorInfo } from '../../../locator'; | ||
import { LoaderFilterFn, ScriptFileExportItem } from './type'; | ||
import { LocatorInfo } from '../../../locator'; | ||
export declare function loadScriptFile(data: LocatorInfo | string): Promise<unknown | undefined>; | ||
type ScriptFileLoadOptions = { | ||
withExtension?: boolean; | ||
withFilePrefix?: boolean; | ||
}; | ||
export declare function loadScriptFile(data: LocatorInfo | string, options?: ScriptFileLoadOptions): Promise<unknown | undefined>; | ||
export declare function loadScriptFileExport(data: LocatorInfo | string, filterFn?: LoaderFilterFn): Promise<ScriptFileExportItem | undefined>; | ||
export {}; |
{ | ||
"name": "locter", | ||
"version": "0.5.0", | ||
"version": "0.5.1", | ||
"description": "A library to locate a file by criteria and load it", | ||
@@ -75,4 +75,3 @@ "author": { | ||
"dependencies": { | ||
"glob": "^8.0.3", | ||
"is-file-esm": "^1.0.0" | ||
"glob": "^8.0.3" | ||
}, | ||
@@ -79,0 +78,0 @@ "config": { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
74789
1
1849
- Removedis-file-esm@^1.0.0
- Removed@babel/code-frame@7.26.2(transitive)
- Removed@babel/helper-validator-identifier@7.25.9(transitive)
- Removed@types/normalize-package-data@2.4.4(transitive)
- Removederror-ex@1.3.2(transitive)
- Removedfind-up@4.1.0(transitive)
- Removedfunction-bind@1.1.2(transitive)
- Removedhasown@2.0.2(transitive)
- Removedhosted-git-info@2.8.9(transitive)
- Removedis-arrayish@0.2.1(transitive)
- Removedis-core-module@2.16.0(transitive)
- Removedis-file-esm@1.0.0(transitive)
- Removedjs-tokens@4.0.0(transitive)
- Removedjson-parse-even-better-errors@2.3.1(transitive)
- Removedlines-and-columns@1.2.4(transitive)
- Removedlocate-path@5.0.0(transitive)
- Removednormalize-package-data@2.5.0(transitive)
- Removedp-limit@2.3.0(transitive)
- Removedp-locate@4.1.0(transitive)
- Removedp-try@2.2.0(transitive)
- Removedparse-json@5.2.0(transitive)
- Removedpath-exists@4.0.0(transitive)
- Removedpath-parse@1.0.7(transitive)
- Removedpicocolors@1.1.1(transitive)
- Removedread-pkg@5.2.0(transitive)
- Removedread-pkg-up@7.0.1(transitive)
- Removedresolve@1.22.9(transitive)
- Removedsemver@5.7.2(transitive)
- Removedspdx-correct@3.2.0(transitive)
- Removedspdx-exceptions@2.5.0(transitive)
- Removedspdx-expression-parse@3.0.1(transitive)
- Removedspdx-license-ids@3.0.20(transitive)
- Removedsupports-preserve-symlinks-flag@1.0.0(transitive)
- Removedtype-fest@0.6.00.8.1(transitive)
- Removedvalidate-npm-package-license@3.0.4(transitive)