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

A library to locate a file by criteria and load it

  • 0.5.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
80K
increased by3.57%
Maintainers
1
Weekly downloads
 
Created
Source

Locter 🔥

npm version CI codecov Known Vulnerabilities semantic-release: angular

Locter is a library to locate and load a file regarding specific criteria.

Table of Contents

Installation

npm install locter --save

Usage

The following examples are based on some shared assumptions:

  • A folder named files exists in the root directory.
  • The folder files contains the following files:
    • example.js
    • example.json
    • example.ts
    • example-long.ts

Locator

Multiple

Locating multiple files will return information about all files matching the pattern.

import { locateFiles } from 'locter';

(async () => {
    let files = await locateFiles(
        'files/example.{js,.ts}',
        {
            path: process.cwd()
        }
    );

    console.log(files);
    /*
    [
        { path: 'files', name: 'example', extension: '.js'},
        { path: 'files', name: 'example', extension: '.ts'}
    ]
     */

    files = await locateFiles(
        'files/*.{js,ts}',
        {
            path: process.cwd()
        }
    );

    console.log(files);
    /*
    [
        { path: 'files', name: 'example', extension: '.js'},
        { path: 'files', name: 'example', extension: '.ts'},
        { path: 'files', name: 'example-long', extension: '.ts'},
    ]
     */
})

A synchronous variant is also available: locateFilesSync

Single

Locating a single file will return information about the first file matching the pattern.

import { locateFile } from 'locter';

(async () => {
    let file = await locateFile(
        'files/example.{js,.ts}',
        {
            path: process.cwd()
        }
    );

    console.log(file);
    /*
    { path: 'files', name: 'example', extension: '.js'}
     */
})

A synchronous variant is also available: locateFileSync

Loader

The method will load the located file.

import { loadFile, locateFile } from 'locter';

(async () => {
    const file = await locateFile(
        'files/example.{js,.ts}',
        {
            path: process.cwd()
        }
    );

    const content = loadFile(file);

    console.log(content);

    // ...
})

A synchronous variant is also available: loadFileSync

License

Made with 💚

Published under MIT License.

Keywords

FAQs

Package last updated on 29 Nov 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

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