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

snaked-js

v1.0.2

Published

Lightweight high-performance wrapper for accessing camelCase JavaScript objects using snake_case syntax.

Downloads

6

Readme

Test Status npm npm dependency ECMAScript version

Slim. Beautiful. Snaked.

This module is also available for Python as snaked-py.

Snaked - Snakifying Your JavaScript Code

snaked-js is a universal wrapper for JavaScript objects of all kinds. It allows you to access camelCase and PascalCase fields of wrapped objects using snake_case syntax.

Installation

You can install the latest stable release of snaked-js using npm:

$ npm install --save snaked-js

Requirements

This is a CommonJS module. It will work out of the box with NodeJS. It requires at least ECMAScript 2015 / ES6.

Features

  • auto-enables snake_case access for camelCase objects
  • autp-enables snake_case access for PascalCase objects
  • wraps around any kind of object/3rd-party module/etc.
  • includes runtime optimizations like caching
  • lightweight with only one dependency

Why should I use Snaked?

JavaScript has no standard guidelines for coding style. If you're used to the snake_case syntax or if your backend is written in a Python-like coding language and you want to have a consistent coding style, you might want to write JavaScript using snake_case syntax instead of camelCase.

Since there's a broad range of camelCase JavaScript objects, classes and functions, you would write inconsistent code if you decided to use snake_case names for your own code parts.

Snaked solves this problem by providing convenient wrapper utilities for accessing your camelCase objects using the preferred snake_case syntax.

Example Usage

Let's use the following class in this example:

class Camel {
    createMe(name) {
        this.name = name;
    }
    sayHello() {
        console.log("Hey, I'm " + self.name);
    }
}

Usual access:

> let animal = new Camel();
> animal.createMe("Mr. C. Java");
> animal.sayHello();
Hey, I'm Mr. C. Java

Snaked Access:

> const snaked = require("snaked-js");
> let animal = snaked(new Camel());
> animal.create_me("Mr. C. JavaScript");
> animal.say_hello();
Hey, I'm Mr. C. JavaScript

Edge Cases

Snaked uses resolution-caching by default to improve performance. In some rare situations, you might remove camelCase/pascalCase-attributes of your wrapped objects and re-introduce them in a different case.

Example:

> let original = new Camel();
> let animal = snaked(original);
> animal.create_me("Mr. Ed");
> animal.say_hello();
Hey, I'm Mr. Ed
> original.SayHello = original.sayHello;
> delete original.sayHello;
> animal.say_hello()
TypeError: 'sayHello' is not a function

You will then have to clear the resolution cache to let Snaked search again for the corresponding new camelCase/PascalCase/snake_case version:

> original.SayHello = original.sayHello;
> delete original.sayHello;
> animal.__clear_cache(); // <- this line is important
> animal.say_hello();
Hey, I'm Mr. Ed

You can also circumvent this situation by preventing Snaked from caching resolved attributes. Note however, that this will decrease your program's performance drastically.

let animal = snaked(original, false) // added use_cache=false as 2nd argument

License

This project is licensed under the MIT license by Squirrel-Preslash. It is free to use for any commercial or non-commercial purpose.

If you do so, you are required to include the full license text in a special section of your compiled program (i.e. in a credits or startup screen) or a copy of the license in the distributed source code.