1.0.3 • Published 5 years ago

swift-pattern-compiler v1.0.3

Weekly downloads
4
License
MIT
Repository
github
Last release
5 years ago

SWIFT Pattern Compiler

A compiler which transforms SWIFT - Society for Worldwide Interbank Financial Telecommunications patterns to an object representation with additional information's without any dependencies.

Install

npm install --save swift-pattern-compiler

Usage

const spc = require("./swift-pattern-compiler").compiler;
const pattern = ":4!c/[8c]/24x"
const patternObj = spc(pattern);
console.log(patternObj);

/*
{
    linesCount: 1,
    minChars: 7,
    maxChars: 39,
    regExp:
        ":[A-Z0-9]{4,4}/([A-Z0-9]{0,8})?/[A-Za-z0-9\\/\\-\\?\\:\\(\\)\\.\\,\\'\\+\n ]{0,24}",
    allowedCharsClass: "[:A-Z0-9/A-Za-z0-9\\/\\-\\?\\:\\(\\)\\.\\,\\'\\+\n ]",
    lines: [
        {
            minChars: 7,
            maxChars: 39,
            regExp:
                ":[A-Z0-9]{4,4}/([A-Z0-9]{0,8})?/[A-Za-z0-9\\/\\-\\?\\:\\(\\)\\.\\,\\'\\+\n ]{0,24}",
            allowedCharsClass: "[:A-Z0-9/A-Za-z0-9\\/\\-\\?\\:\\(\\)\\.\\,\\'\\+\n ]"
        }
    ]
}
*/

Multiline Pattern

The compiler returns global information's of a pattern and per line. For example a multiline pattern like 2*10c will return the following.

const spc = require("./swift-pattern-compiler").compiler;
const pattern = "2*10c"
const patternObj = spc(pattern);
console.log(patternObj);

/*
{
    linesCount: 2,
    minChars: 0,
    maxChars: 20,
    regExp: '([A-Z0-9]{0,10})?\n?([A-Z0-9]{0,10})?',
    allowedCharsClass: '[A-Z0-9\n]',
    lines: [
        {
            minChars: 0,
            maxChars: 10,
            regExp: '[A-Z0-9]{0,10}',
            allowedCharsClass: '[A-Z0-9]'
        },
        {
            minChars: 0,
            maxChars: 10,
            regExp: '[A-Z0-9]{0,10}',
            allowedCharsClass: '[A-Z0-9]'
        }
    ]
}
*/

Inspiration

The structure of the compiler is highly inspired by the great talk of James Kyles on EmberConf 2016 - How to Build a Compiler and the code example, which can be found here on github.

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago