Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

locter

Package Overview
Dependencies
Maintainers
1
Versions
51
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

locter - npm Package Compare versions

Comparing version 0.5.0 to 0.5.1

166

dist/index.cjs.js
'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": {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc