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

xtypejs-extension-autocamel-name-scheme

v0.1.1

Published

xtypejs Extension - Auto Camel Name Scheme

Downloads

14

Readme

xtypejs Extension - Auto Camel Name Scheme

This extension provides a virtual name scheme named auto-camel, which when is the active name scheme, automatically assigns a camel-cased type name to all types in xtypejs, including all default and custom types.

This happens automatically, so that even custom types registered in xtypejs after the extension has already been applied to xtypejs will also each automatically acquire a camel-cased version of their respective type names in the auto-camel name scheme. This is the primary difference between the auto-camel name scheme provided by this extension, and the regular xtypejs camel name scheme module, which only provides a static set of camel-cased type names for the xtypejs built-in types.

Note that this is an xtypejs extension, not an xtypejs name scheme. It therefore requires registration to xtypejs using the xtype.ext.registerExtension method, and cannot be registered using the xtype.ext.registerNameScheme method.

Installation with npm

npm install xtypejs-extension-autocamel-name-scheme --save

NodeJs import and setup

var xtype = require('xtypejs');
var xtypejsAutoCamelNameSchemeExtension = require('xtypejs-extension-autocamel-name-scheme');

xtype.ext.registerExtension(xtypejsAutoCamelNameSchemeExtension);
xtype.options.setNameScheme('auto-camel');

/*
 * Scheme is now active here, and all default and custom types
 * in xtype will now automatically use a camel-converted
 * version of their registered names. For instance, for the
 * 'positive_number' type, the camel name 'positiveNumber'
 * should be used when referencing it in type expressions.
 */

HTML script tag import and setup

Include the extension script after the xtypejs script to automatically register the extension into xtypejs without exporting any globals. This relies on xtypejs being available in the xtype global variable.

<script src="path/to/xtype.js"></script>
<script src="path/to/xtypejs-extension-autocamel-name-scheme.js"></script>

<script>
    xtype.options.setNameScheme('auto-camel');
    // Scheme is now active here
</script>

If the extension script needs to be included before the xtypejs script, or the xtype global is not available (or is using a different variable name) when the extension script is included, the extension will be exported instead to a global variable named xtypejsAutoCamelNameSchemeExtension, which must then be manually registered into xtypejs as an extension.

<!--
    Assume 'xtype' global variable not available here. The following
    exports global variable 'xtypejsAutoCamelNameSchemeExtension'
-->
<script src="path/to/xtypejs-extension-autocamel-name-scheme.js"></script>

<!-- Other things here... -->

<script>
    // Assume xtypejs later available here in variable 'myXtype'
    myXtype.ext.registerExtension(xtypejsAutoCamelNameSchemeExtension);
    myXtype.options.setNameScheme('auto-camel');

    // Scheme is now active here
</script>

Usage

When the auto-camel name scheme is the active scheme, all types, including newly registered custom types, will automatically use a camel-version of the name of the type.

Example:

xtype.options.setNameScheme('auto-camel');

// Registration of custom type 'app_flag' automatically
// uses the camel version of the name ('appFlag') instead:

xtype.registerType('app_flag', 'positive_integer, single_char_string');
xtype.which('g', 'appFlag') === 'appFlag';    // 'app_flag' type uses camel name 'appFlag'

For other related documentation for working with name schemes, also see:

Preventing name collisions

If the HTML script tag was used to import the extension script in a browser environment and in the absence of xtypejs in the xtype global variable, the extension will be exported to a global variable named xtypejsAutoCamelNameSchemeExtension. The noConflict method of the exported extension can be used to reassign the extension to a different namespace or variable name, and return the global xtypejsAutoCamelNameSchemeExtension variable to its previous value prior to including the extension script.

var myAutoCamel = xtypejsAutoCamelNameSchemeExtension.noConflict();

/*
 * myAutoCamel is now xtypejsAutoCamelNameSchemeExtension, while 
 * xtypejsAutoCamelNameSchemeExtension variable is now returned to
 * its original value prior to inclusion of the extension script.
 */ 

Type names used for built-in types


Type Default Name | Name in Scheme :------------------ | :------------ null | null undefined | undefined nan | nan symbol | symbol function | function date | date error | error regexp | regexp boolean | boolean true | true false | false string | string whitespace | whitespace single_char_string | singleCharString multi_char_string | multiCharString empty_string | emptyString blank_string | blankString non_empty_string | nonEmptyString non_blank_string | nonBlankString number | number positive_number | positiveNumber negative_number | negativeNumber zero | zero non_positive_number| nonPositiveNumber non_negative_number| nonNegativeNumber non_zero_number | nonZeroNumber integer | integer positive_integer | positiveInteger negative_integer | negativeInteger float | float positive_float | positiveFloat negative_float | negativeFloat infinite_number | infiniteNumber positive_infinity | positiveInfinity negative_infinity | negativeInfinity non_infinite_number| nonInfiniteNumber array | array empty_array | emptyArray single_elem_array | singleElemArray multi_elem_array | multiElemArray non_empty_array | nonEmptyArray object | object empty_object | emptyObject single_prop_object | singlePropObject multi_prop_object | multiPropObject non_empty_object | nonEmptyObject primitive | primitive nothing | nothing any | any none | none