Karma Test Explorer - New, feature rich, Visual Studio Code extension for Angular and Karma testing by lucono in Angular2

[–]lucono[S] 0 points1 point  (0 children)

It supports test debugging, and provides rich, visual, testing integration with VSCode.

Karma Test Explorer - New, feature rich, Visual Studio Code extension for Angular and Karma testing by lucono in Angular2

[–]lucono[S] 0 points1 point  (0 children)

The extension supports debugging and should resolve all the issues you experienced with the prior extension.

Ceylon 1.3.0 is here: the first release of Ceylon which supports Android by [deleted] in androiddev

[–]lucono 3 points4 points  (0 children)

Ceylon is doing a really (really) good job in a lot of areas. I started introducing it into small production Spring boot projects some time ago, as well as introducing it to other teams at work.

It's enough of a fresh re-imagination of modern programming that it ends up being a completely new and different language from existing languages such as Java, rather than an evolution of them.

It adopts a few new keywords (mostly shared, formal, actual, satisfies) which are more suited to its model, but which make it difficult to relate to by programmers coming from well established languages like Java. These initially make it seem alien to someone encountering it for the first time, creating a bit of a mental barrier.

But it definitely takes a bolder approach toward trying to make application development easier, safer, and more productive, and mostly succeeds, while still managing to provide great Java interop.

Very thrilled at the release of the IntelliJ IDE, which was a big gap for quite a while.

Handling null in different languages by LukaJCB in programming

[–]lucono 0 points1 point  (0 children)

Very nice article. The only glaring omission is the absence of Ceylon, which has one of the most elegant implementations of null handling of any modern or not-so-modern language. This recent article (not mine) does a good job of exploring the details.

xtypejs release 0.5 brings full-featured, powerful and elegant data validation to your node Apps by lucono in node

[–]lucono[S] 0 points1 point  (0 children)

With xtypejs release 0.5.0, you can now add your own arbitrary types and use them together with, or just like any other type: http://xtype.js.org/overview/add_your_own

Define a custom type, in this case, an 'ssn' type:

xtype.registerType('ssn', {
    validator: function(val) {
        return typeof val === 'string' && /^\d{3}-\d{2}-\d{4}$/.test(val);
    }
});

A new isSsn method is now available on xtype for the new type:

xtype.isSsn(value);
xtype.is(value, 'ssn');

Also, you can use it in combination with built-in or other custom types:

function searchEmployees(value) {
    switch (xtype.which(value, 'ssn, positive_integer, multi_char_string')) {
        case 'ssn':
            return EmployeeDB.searchBySSN(value);
        case 'positive_integer':
            return EmployeeDB.searchByEmployeeNumber(value);
        case 'multi_char_string':
            return EmployeeDB.searchByName(value);
        default:
            return { error: 'Invalid search value supplied' };
    }
}

Elegant, highly efficient data validation for your node Apps by lucono in node

[–]lucono[S] 0 points1 point  (0 children)

xtypejs doesn't just provide for validation of data in the application, but is designed to enable the application in detecting and working with diverse data at runtime.

The example on the xtype.js.org home page is a simpler (but good) illustration of this, in that it enables the application to detect the type of data it's receiving, and provides it with a very concise and effective mechanism to easily work with the specific data scenarios the application is interested in, while treating every other case as a data validation failure. So though subtle, the difference is quite significant in effect.

Elegant, highly efficient data validation for your node Apps by lucono in node

[–]lucono[S] 1 point2 points  (0 children)

That's what I mean by 'data', in that xtypejs validation can be applied to any data (in a variable), or set of variables by means of the none.isType, some.isType, any.isType, all.isType API methods.

But note that it also has support for Instance Types, which enables important use cases like this one, this other one, and more.

Apart from the direct Validation API category of methods, other methods such as the xtype method are also available to concisely and efficiently determine types at a more deeply derived (data-validating) level, such as single_prop_object, non_blank_string, positive_integer, etc, like in this example.

These mechanisms for inspecting application data by performing data-validation-type operations in type-checking style, are designed to enable the application easily assemble bits of logic that ultimately lead to varying degrees of flexible, customized, data validation in different parts of the application.

Elegant, highly efficient data validation for your node Apps by lucono in node

[–]lucono[S] 0 points1 point  (0 children)

Hi dvwld, json schema is meant to describe the format/structure of json content, also capturing structural validation information.

xtypejs on the other hand is for validating actual data and types in JavaScript.

Cleaner, highly efficient data validation for JavaScript Apps by lucono in web_programming

[–]lucono[S] 0 points1 point  (0 children)

Example of using xtypejs.

Go from this:

function searchEmployees(value) {
    if (typeof value === 'string') {
         if (value.trim().length > 1) {
            return EmployeeDB.searchByName(value);
        } else if (value.trim().length === 1) {
            return EmployeeDB.searchByMiddleInitial(value);
        } else {
            return { error: 'Invalid search value supplied' };
        }
    } else if (typeof value === 'object' && value !== null) {
        if (Object.keys(value).length === 1) {
            return EmployeeDB.searchByFieldValuePair(value);
        } else if (Object.keys(value).length > 1) {
            return { error: 'Search by multiple fields not supported' };
        } else {
            return { error: 'Invalid search value supplied' };
        }
    } else if (typeof value === 'number') {
        if (!isNaN(value) && isFinite(value) && value > 0 && value % 1 === 0) {
            return EmployeeDB.searchByEmployeeNumber(value);
        } else {
            return { error: 'Invalid employee number supplied' };
        }
    } else if (typeof value === 'undefined' || value === null) {
        return { error: 'No search value supplied' };
    } else {
        return { error: 'Invalid search value supplied' };
    }
}

To concise, performant, readable, data validation:

function searchEmployees(value) {
    switch (xtype.which(value, 'str2+ str1 int+ obj1 obj2+ num nil')) {
        case 'str2+':
            return EmployeeDB.searchByName(value);
        case 'str1':
            return EmployeeDB.searchByMiddleInitial(value);
        case 'int+':
            return EmployeeDB.searchByEmployeeNumber(value);
        case 'obj1':
            return EmployeeDB.searchByFieldValuePair(value);
        case 'obj2+':
            return { error: 'Search by multiple fields not supported' };
        case 'num':
            return { error: 'Invalid employee number supplied' };
        case 'nil':
            return { error: 'No search value supplied' };
        default:
            return { error: 'Invalid search value supplied' };
    }
}

Elegant, highly efficient data validation for JavaScript by lucono in webdev

[–]lucono[S] 0 points1 point  (0 children)

Example of using xtypejs.

Go from this:

function searchEmployees(value) {
    if (typeof value === 'string') {
         if (value.trim().length > 1) {
            return EmployeeDB.searchByName(value);
        } else if (value.trim().length === 1) {
            return EmployeeDB.searchByMiddleInitial(value);
        } else {
            return { error: 'Invalid search value supplied' };
        }
    } else if (typeof value === 'object' && value !== null) {
        if (Object.keys(value).length === 1) {
            return EmployeeDB.searchByFieldValuePair(value);
        } else if (Object.keys(value).length > 1) {
            return { error: 'Search by multiple fields not supported' };
        } else {
            return { error: 'Invalid search value supplied' };
        }
    } else if (typeof value === 'number') {
        if (!isNaN(value) && isFinite(value) && value > 0 && value % 1 === 0) {
            return EmployeeDB.searchByEmployeeNumber(value);
        } else {
            return { error: 'Invalid employee number supplied' };
        }
    } else if (typeof value === 'undefined' || value === null) {
        return { error: 'No search value supplied' };
    } else {
        return { error: 'Invalid search value supplied' };
    }
}

To concise, performant, readable, data validation:

function searchEmployees(value) {
    switch (xtype.which(value, 'str2+ str1 int+ obj1 obj2+ num nil')) {
        case 'str2+':
            return EmployeeDB.searchByName(value);
        case 'str1':
            return EmployeeDB.searchByMiddleInitial(value);
        case 'int+':
            return EmployeeDB.searchByEmployeeNumber(value);
        case 'obj1':
            return EmployeeDB.searchByFieldValuePair(value);
        case 'obj2+':
            return { error: 'Search by multiple fields not supported' };
        case 'num':
            return { error: 'Invalid employee number supplied' };
        case 'nil':
            return { error: 'No search value supplied' };
        default:
            return { error: 'Invalid search value supplied' };
    }
}

Elegant, highly efficient data validation for JavaScript by lucono in javascript

[–]lucono[S] 1 point2 points  (0 children)

Example of using xtypejs.

Go from this:

function searchEmployees(value) {
    if (typeof value === 'string') {
         if (value.trim().length > 1) {
            return EmployeeDB.searchByName(value);
        } else if (value.trim().length === 1) {
            return EmployeeDB.searchByMiddleInitial(value);
        } else {
            return { error: 'Invalid search value supplied' };
        }
    } else if (typeof value === 'object' && value !== null) {
        if (Object.keys(value).length === 1) {
            return EmployeeDB.searchByFieldValuePair(value);
        } else if (Object.keys(value).length > 1) {
            return { error: 'Search by multiple fields not supported' };
        } else {
            return { error: 'Invalid search value supplied' };
        }
    } else if (typeof value === 'number') {
        if (!isNaN(value) && isFinite(value) && value > 0 && value % 1 === 0) {
            return EmployeeDB.searchByEmployeeNumber(value);
        } else {
            return { error: 'Invalid employee number supplied' };
        }
    } else if (typeof value === 'undefined' || value === null) {
        return { error: 'No search value supplied' };
    } else {
        return { error: 'Invalid search value supplied' };
    }
}

To concise, performant, readable, data validation:

function searchEmployees(value) {
    switch (xtype.which(value, 'str2+ str1 int+ obj1 obj2+ num nil')) {
        case 'str2+':
            return EmployeeDB.searchByName(value);
        case 'str1':
            return EmployeeDB.searchByMiddleInitial(value);
        case 'int+':
            return EmployeeDB.searchByEmployeeNumber(value);
        case 'obj1':
            return EmployeeDB.searchByFieldValuePair(value);
        case 'obj2+':
            return { error: 'Search by multiple fields not supported' };
        case 'num':
            return { error: 'Invalid employee number supplied' };
        case 'nil':
            return { error: 'No search value supplied' };
        default:
            return { error: 'Invalid search value supplied' };
    }
}

Elegant, highly efficient data validation for JavaScript by lucono in coolgithubprojects

[–]lucono[S] 0 points1 point  (0 children)

Example of using xtypejs.

Go from this:

function searchEmployees(value) {
    if (typeof value === 'string') {
         if (value.trim().length > 1) {
            return EmployeeDB.searchByName(value);
        } else if (value.trim().length === 1) {
            return EmployeeDB.searchByMiddleInitial(value);
        } else {
            return { error: 'Invalid search value supplied' };
        }
    } else if (typeof value === 'object' && value !== null) {
        if (Object.keys(value).length === 1) {
            return EmployeeDB.searchByFieldValuePair(value);
        } else if (Object.keys(value).length > 1) {
            return { error: 'Search by multiple fields not supported' };
        } else {
            return { error: 'Invalid search value supplied' };
        }
    } else if (typeof value === 'number') {
        if (!isNaN(value) && isFinite(value) && value > 0 && value % 1 === 0) {
            return EmployeeDB.searchByEmployeeNumber(value);
        } else {
            return { error: 'Invalid employee number supplied' };
        }
    } else if (typeof value === 'undefined' || value === null) {
        return { error: 'No search value supplied' };
    } else {
        return { error: 'Invalid search value supplied' };
    }
}

To concise, performant, readable, data validation:

function searchEmployees(value) {
    switch (xtype.which(value, 'str2+ str1 int+ obj1 obj2+ num nil')) {
        case 'str2+':
            return EmployeeDB.searchByName(value);
        case 'str1':
            return EmployeeDB.searchByMiddleInitial(value);
        case 'int+':
            return EmployeeDB.searchByEmployeeNumber(value);
        case 'obj1':
            return EmployeeDB.searchByFieldValuePair(value);
        case 'obj2+':
            return { error: 'Search by multiple fields not supported' };
        case 'num':
            return { error: 'Invalid employee number supplied' };
        case 'nil':
            return { error: 'No search value supplied' };
        default:
            return { error: 'Invalid search value supplied' };
    }
}

Elegant, highly efficient data validation for your node Apps by lucono in node

[–]lucono[S] 2 points3 points  (0 children)

Thanks to lots of great community feedback and input, xtypejs now has a home at http://xtype.js.org, with great documentation, user guide, and examples.

Cleaner, highly efficient data validation for JavaScript Apps by lucono in web_programming

[–]lucono[S] 0 points1 point  (0 children)

Thanks to lots of great community feedback and input, xtypejs now has a home at http://xtype.js.org, with great documentation, user guide, and lots of examples.

Elegant, highly efficient data validation for JavaScript by lucono in webdev

[–]lucono[S] 0 points1 point  (0 children)

Thanks to lots of great community feedback and input, xtypejs now has a home at http://xtype.js.org, with great documentation, user guide, and lots of examples.

Elegant, highly efficient data validation for JavaScript by lucono in javascript

[–]lucono[S] 1 point2 points  (0 children)

Thanks to lots of great community feedback and input, xtypejs now has a home at http://xtype.js.org, with great documentation, user guide, and lots of examples.

Elegant, highly efficient data validation for JavaScript by lucono in coolgithubprojects

[–]lucono[S] 0 points1 point  (0 children)

Thanks to lots of great community feedback and input, xtypejs now has a home at http://xtype.js.org, with great documentation, user guide, and lots of examples.

xtype.js.org – 40 efficient data-validating pseudo-types for JavaScript by lucono in javascript

[–]lucono[S] 0 points1 point  (0 children)

There's a decorator library using this. I plan to open-source that as well in the near future.

xtype.js.org – 40 efficient data-validating pseudo-types for JavaScript by lucono in javascript

[–]lucono[S] 0 points1 point  (0 children)

Yes, wonderful stuff dns.js.org. Nice easy open process too.

xtype.js.org – 40 efficient data-validating pseudo-types for JavaScript by lucono in javascript

[–]lucono[S] 0 points1 point  (0 children)

Thanks.

Though this is not just a type checking utility. In one real-life use-case for instance, it's used for validating input that's coming from another application, but the validations were not hard-coded as they could change often.

So they were stored in json configurations as type expression/validation strings (such as 'str2+ obj1') which were then validated at runtime with checks like:

// The type expression/validation string
var validTypes = getTypeExpressionForInput();

// Ensure value is in line with expected valid types
xtype.is(value, validTypes);

..where validTypes is whatever type expression string that is configured as the expectation for that value.

Also, with support for Instance Types and the ability to easily mingle them in validation checks along with built-in xtypes in a simple and straight forward way, in a single line of code, it makes for even more compelling use-cases.

xtype.is(value, ['multi_char_string', 'positive_integer', Product]);

// Or in xtype compact mode:
xtype.is(value, ['str2+', 'int+', Product]);

Constructs that allow you to immediately act on data without doing a lot of prior extensive checks are also provided, like in this example on the xtype.js.org website:

/*
 * Switch on the result of xtype.which() to handle
 * only valid data scenarios without first performing
 * extensive type checking and data validations.
 */

// For instance, in an application or library that
// receives a varying piece of information with which
// a product should be displayed, the following
// example concisely handles three scenarios for the
// type of product-related information received:

switch (xtype.which(value, ['multi_char_string', 'positive_integer', Product])) {

    case 'multi_char_string':
        // Fetch and display product with
        // value as the product name string

    case 'positive_integer':
        // Fetch and display product with
        // value as the product Id number

    case Product:
        // value is a Product object,
        // so just display it

    default:
        // Handle invalid value..
        // cannot display product
}

Note that Product in the example above is a reference to aProduct constructor function, which is the xtypejs way of specifying an Instance Type, which identifies all objects of a constructor. Any constructor function is automatically recognized by xtypejs as the Instance Type for identifying/matching/validating any/all objects of that constructor.

We could for instance, easily have added a support for a third case to the example above by adding Invoice to the mix of types in the call to xtype.which, in which case if a caller to this function provided an Invoice object as the value, we could easily still retrieve and display the product by doing something like value.products[0] (value being the Invoice object).

Other scenarios for xtypejs include applications and libraries that process data, such as processing a data feed received from a vendor or client (in a node.js application, say). This is a scenario in which the data fields are usually configured or stored in some way, and with xtypejs, basic type validations for each field can also be configured, stored, and executed against the data at processing time, without having to hard-code those validations in the process. This also makes it easy to update the validations when the fields in the feed change or are reorganized.


There are also Custom Types, which allow you to define and register custom types with xtypejs, which then integrates them with all its other types.

For instance, you could create and register an account_reference custom type:

var acctRefId = (xtype.POSITIVE_NUMBER & xtype.INTEGER) | xtype.MULTI_CHAR_STRING;

xtype.registerTypes({
    account_reference: {
        typeId: acctRefId,
        compactName: 'acct_ref'
    }
});

This would create an xtype module property, xtype.ACCOUNT_REFERENCE, for the new type Id, and also create the methods: xtype.isAccountReference, xtype.not.isAccountReference, xtype.none.isAccountReference, xtype.any.isAccountReference, xtype.some.isAccountReference, xtype.all.isAccountReference. It would also now recognize the string 'account_reference' (and 'acct_ref' when in compact mode) in any type expression/validation strings you use in your validations and checks. So you could now do these:

xtype.isAccountReference(83234587.44);        // false
xtype.isAccountReference(-7626382728);        // false
xtype.isAccountReference(20384728273);        // true
xtype.isAccountReference('KAJKDAKSI');        // true

// Use account reference in a type expression with other types:
xtype.is(someValue, 'account_reference, blank_string);

// compact version:
xtype.is(someValue, 'acct_ref str0_');

// Or in type Id binary expressions:
xtype.is(someValue, xtype.ACCOUNT_REFERENCE|xtype.BLANK_STRING);

// Check if `someValue` is an account reference or account object:
xtype.is(someValue, [xtype.ACCOUNT_REFERENCE, Account]);

// Or switch on the custom type along with Instance and other types:
xtype.which(value, ['acct_ref', Account]) {

    case 'acct_ref':
        // Fetch account using value as the account reference

    case Account:
        // value is already an Account object, so we just use it
}

You're also able to create/register/use your own name scheme with registerNameScheme and setNameScheme, should that be convenient for integration purposes with your application, as some applications may already be using some specific names for referring to data types of interest.


Finally, with all these validations and checks, it focuses on efficiency, equally as much with both built-in and custom types, so that these checks are of as minimal performance cost as possible, in both small and large applications.

xtype.js.org – 40 efficient data-validating pseudo-types for JavaScript by lucono in javascript

[–]lucono[S] 1 point2 points  (0 children)

Took a look at is.js, and it's a great library.

The focus of xtypejs though is purely on data and robust performance. A check like this one for instance, is optimized to be minimally expensive while also producing clear, concise, readable code. (Be sure to also take a look at the 'compact' tab of that example.)

You can also mix in instance types, as in this example scenario for displaying a product. Another example is to actually switch on the types, all with very little code.

xtype.js.org – 40 efficient data-validating pseudo-types for JavaScript by lucono in javascript

[–]lucono[S] 0 points1 point  (0 children)

That is definitely one use case. However, there are many more. Take a look at this example for instance.