npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@reason-native/fp

v0.0.1

Published

Reason Native file paths library.

Downloads

4

Readme

fp

Fp is a human usable library for creating and operating on file paths consistently on all platforms.

Similar to the File URI scheme, Fp provides one consistent API that can be used to refer to files in a platform agnostic manner but Fp differs in that Fp focuses on programmers instead of on descriptions of files to be sent across the wire in networking applications. For example, Fp expands upon the concept of a file URI by also allowing the representation of a "relative" file path - something left unspecified by file URI protocol.

Programmers can use Fp to reason about file system paths inside of their code, and then convert the Fp data into URIs, or other platform specific formats.

Typed Paths:

Fp keeps track of which paths are relative, absolute, so that you can write libraries that demand only absolute paths. The types also allow APIs that can accept either kind and even preserve the nature of the type polymorphically.

For example, Fp is able to preserve its "absoluteness" across append operations:

let newAbs : Fp.t(absolute) = Fp.append(myAbs, "foo");

let newRel : Fp.t(relative) = Fp.append(myRel, "foo");

Syntax:

Fp includes a Fp.At module that can be opened using the Fp.At.(...) syntax. It provides path operations such as /, /../, and /../../.

let path = Fp.At.(rootDir / "usr" / "bin" / "example.exe");
let relative = Fp.At.(rootDir /../ "home" /../../ "apps");

More Examples:

Safe absolute and relative path parsing:

/* Some(Fp.t) */
let bin = Fp.absolute("/usr/bin");
/* Some(Fp.t) */
let bin = Fp.relative("./bin");

Less safe absolute and relative path parsing:

/* Fp.t */
let bin = Fp.absoluteExn("/usr/bin");
/* Fp.t */
let bin = Fp.relativeExn("./bin");

Constructing paths safely, segment by segment:

/* "/" */
let root = Fp.root;
/* /foo */
let foo = Fp.append(root, "foo");
/* /foo/bar */
let fooBar = Fp.append(root, "bar");

Or, alternatively:

let fooBar = Fp.At.(Fp.root / "foo" / "bar");

Common utility functions:

/* bar */
Fp.baseName(fooBar);
/* foo */
Fp.dirName(fooBar);

Goals:

  • Developer usability.
  • Very few dependencies if any.
  • Small code size suitable for compiling to JavaScript/PHP.

Protocol:

Path parsing in the Fp.absolute/Fp.relative functions follow the Fp convention, not any operating system convention. You should prefer the functions append and / when possible, but if using the Fp.absolute/relative functions, the following is the convention for parsing the supplied paths.

  • Path separators must always be forward slash and backslash is reserved for escaping.
  • The grammar for paths is as follows:
ESCAPED_SEP=\/
DIR_CHARS= a-z | A-Z | 0-9 | _ | DOT | ......
DIR_NAME=(DIR_CHARS - DOT)+ (DIR_CHARS | ESCAPED_SEP)
SEGMENT=DOT | DOTDOT | DIR_NAME | EMPTY
ABSOLUTE=EMPTY
(DRIVE|RELATIVE|ABSOLUTE) (SEP SEGMENT)*
DRIVE=CAP_LETTER:/
RELATIVE=DOTDOT SLASH | DOT SLASH | DOT

Note that the above grammar doesn't specify how to interpret: "a/b". If Fp cannot parse the path with a drive, relative, or absolute, it will consider the path relative (that is, "./a/b" in this case).

Eventually Fp should include functions for parsing OS specific path formats into the canonical Fp.t.