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

arc-server

v3.1.1

Published

<a href="https://www.ebay.com"> <img src="https://img.shields.io/badge/ebay-open%20source-01d5c2.svg" alt="ebay open source"/> </a> <a href="https://img.shields.io/github/license/eBay/arc.svg"> <img src="https://img.shields.io/github/license/eBay/ar

Downloads

244

Readme

arc-server

API

The arc-server api is split into 3 submodules:

arc-server

import { withFlags, setFlags, getFlags } from "arc-server";
  • setFlags(flags): void: sets arc flags for the current synchronous execution and then persists the flags through any following asynchronous calls.
  • withFlags<T>(flags, fn: () => T): T: sets arc flags for the synchronous execution of the provided fn and then persists the flags through asynchronous calls made within the provided fn. Returns the result of calling fn.
  • getFlags(): Record<string, boolean> | undefined: gets the currently set flags or undefined.

Example

setFlags

import { setFlags, getFlags } from "arc-server";

function start(flags, delay) {
  setFlags(flags);
  wait(delay);
}

function wait(delay) {
  setTimeout(logFlags, delay);
}

function logFlags() {
  // The flags weren't passed here, but we can get them from the context
  console.log(getFlags());
}

start({ foo: true }, 100);
start({ baz: true }, 10);
start({ baz: true }, 50);

// After 10ms, { bar:true } is logged
// After 50ms, { baz:true } is logged
// After 100ms, { foo:true } is logged

withFlags

import { withFlags, getFlags } from "arc-server";

function start(flags, delay) {
  withFlags(flags, () => {
    wait(delay);
  });
}

function wait(delay) {
  setTimeout(logFlags, delay);
}

function logFlags() {
  // The flags weren't passed here, but we can get them from the context
  console.log(getFlags());
}

start({ foo: true }, 100);
start({ baz: true }, 10);
start({ baz: true }, 50);

// After 10ms, { bar:true } is logged
// After 50ms, { baz:true } is logged
// After 100ms, { foo:true } is logged

Example usage in example-arc-server/index.js

arc-server/install

import "arc-server/install";

If you are not bundling your server files with another arc plugin, you should import/require this module near the beginning of your application entry point before loading any modules that need to be adaptable.

arc-server/proxy

import createAdaptiveProxy from "arc-server/proxy";

An AdaptiveProxy is returned from an import/require call. It can be treated as if it were the underlying module (with a few caveats. You probably won't need to use this module directly.

createAdaptiveProxy(matches)

  • matches: a MatchSet where each value is the loaded module

Proxy caveats

Primitive values

Applies if you require an adaptive file that sets exports to a primitive value:

module.exports = "Hello World";

Proxy and Reflect are used to provide adaptive values, but these do not support primitive values (string, number, boolean).

To work around this, these primitives are converted into instances of String, Number, or Boolean. In many cases, you will be able to treat this as if it were the original value, but there are differences.

One notable example is truthiness:

// Objects are truthy, regardless of value
!!new Boolean(false) === true;
!!new String("") === true;
!!new Number(0) === true;

Another is typeof:

// typeof is object, regardless of value
typeof new Boolean(true) === "object";
typeof new String("hello") === "object";
typeof new Number(10) === "object";

If you need a true primitive, you can convert an adaptive primitive to its resolved primitive value using valueOf:

let string = adaptiveString.valueOf();

Autobound native functions

Native functions, eg from Object.prototype, or String.prototype are bound to the adapted object:

let valueOf = adaptiveValue.valueOf;

// works because it is bound
valueOf();

// this doesn't change, because it was previously bound
valueOf.bind(newThis);