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

@a-a-game-studio/aa-components

v1.1.50

Published

node typescript base class

Downloads

204

Readme

aa-components

node typescript base class

Базовые классы и компонеты для forntend и backend

ErrorSys

const errorSys = new ErrorSys(); // Режим прода, для режима разработки указать ErrorSys('dev')
try{
    throw errorSys.throwAccess('Сообщение об ошибке доступа');
} catch(e){
    errorSys.errorEx(e, 'throwAccess-Success', 'Проврка ошибки доступа успешно выполнена')
}

try{
    throw errorSys.throwValidRoute('Сообщение об ошибке валидации данных роутинга');
} catch(e){
    errorSys.errorEx(e, 'throwValidRoute-Success', 'Проврка ошибки валидации роутинга успешно выполнена')
}

try{
    throw errorSys.throwLogic('Сообщение об ошибке логики');
} catch(e){
    errorSys.errorEx(e, 'throwLogic-Success', 'Проврка ошибки логики успешно выполнена')
}

try{
    throw errorSys.throwValidDB('Сообщение об ошибке валидации данных при записи в БД');
} catch(e){
    errorSys.errorEx(e, 'throwValidDB-Success', 'Проврка ошибки валидации при записи в БД успешно выполнена')
}

try{
    throw errorSys.throwValid('Сообщение об ошибке валидации ОБЩЕЙ');
} catch(e){
    errorSys.errorEx(e, 'throwValid-Success', 'Проврка ошибки валидации успешно выполнена')
}

errorSys.errorEx(new Error(), 'error', 'Генерация обычной ошибки с трейсом')

errorSys.error('simple_error', 'обычной ошибки');

errorSys.notice('notice', 'Уведомление пользователю');
errorSys.devNotice('devNotice', 'Уведомление пользователю в режиме разработки, на проде не генерирет');

errorSys.warning('warning', 'Предупреждение пользователю');
errorSys.devWarning('devWarnig', 'Предупреждение пользователю в режиме разработки, на проде не генерирет');

let traceList = errorSys.getTraceList();
console.log('===trace-list>', traceList);

let errList = errorSys.getErrors();
console.log('===error>',errList);

console.log('===notice>',errorSys.getNotice());
console.log('===warning>',errorSys.getWarning());

ModelValidatorSys

TPL VALIDATION

const rules = new System.ModelRulesC();

// ===========================
// ID

rules.set(rules.tpl('id_require_true_1', true)
    .tplID('ID обязателен для заполнения')
);

rules.set(rules.tpl('id_require_false_1', true)
    .tplID('ID обязателен для заполнения')
);

rules.set(rules.tpl('id_true_1')
    .tplID('ID не обязателен заполнения')
);

// ==========================-
// TEXT

rules.set(rules.tpl('text_true_1', true)
    .tplStr('Текст true_1')
);

// ===========================
// STR

rules.set(rules.tpl('str_true_1', true)
    .tplStr('Строка true_1')
);

rules.set(rules.tpl('str_regex_true_1', true)
    .tplStr('С регуларынм выражением true_1')
    .if(/^аист[ои]к$/)
);

rules.set(rules.tpl('str_regex_false_1', true)
    .tplStr('С регуларынм выражением false_1')
    .if(/^аист[ои]к$/)
);

// =============================
// ENUM

rules.set(rules.tpl('enum_number_true_1', true)
    .tplEnum('Сообщение - enum_number_true_1')
    .if([1,2])
);

rules.set(rules.tpl('enum_string_true_1', true)
    .tplEnum('Сообщение - enum_string_true_1')
    .if(['s1','s2', '1'])
);

const validator = new System.ModelValidatorSys(new System.ErrorSys('dev'));
validator.fValid(rules.get(), data);

validator.getResult();

====

Пример

const rules = new System.ModelRulesC();

rules.set(rules.rule('enum_boolean_true_1')
    .type(System.ModelRulesT.enum)
    .require()
    .if([1,0])
    .errorEx('enum_boolean_true_1', 'enum_boolean_true_1')
);

rules.set(rules.rule('enum_boolean_true_2')
    .type(System.ModelRulesT.enum)
    .require()
    .if([1,0])
    .errorEx('enum_boolean_true_2', 'enum_boolean_true_2')
);

rules.set(rules.rule('enum_boolean_true_3')
    .type(System.ModelRulesT.enum)
    .require()
    .if([1,0])
    .errorEx('enum_boolean_true_3', 'enum_boolean_true_3')
);

rules.set(rules.rule('enum_boolean_true_4')
    .type(System.ModelRulesT.enum)
    .require()
    .if([1,0])
    .errorEx('enum_boolean_true_4', 'enum_boolean_true_4')
);

rules.set(rules.rule('enum_boolean_false_1')
    .type(System.ModelRulesT.enum)
    .require()
    .if([1,0])
    .errorEx('enum_boolean_false_1', 'enum_boolean_false_1')
);

rules.set(rules.rule('enum_boolean_false_2')
    .type(System.ModelRulesT.enum)
    .require()
    .if([1,0])
    .errorEx('enum_boolean_false_2', 'enum_boolean_false_2')
);

rules.set(rules.rule('enum_boolean_false_3')
    .type(System.ModelRulesT.enum)
    .require()
    .if([1,0])
    .errorEx('enum_boolean_false_3', 'enum_boolean_false_3')
);

// =============================================
// NUMBER

rules.set(rules.rule('enum_number_true_1')
    .type(System.ModelRulesT.enum)
    .require()
    .if([1,2])
    .errorEx('enum_number_true_1', 'enum_number_true_1')
);

rules.set(rules.rule('enum_number_true_2')
    .type(System.ModelRulesT.enum)
    .require()
    .if([1,2])
    .errorEx('enum_number_true_2', 'enum_number_true_2')
);

rules.set(rules.rule('enum_number_false_1')
    .type(System.ModelRulesT.enum)
    .require()
    .if([1,2])
    .errorEx('enum_number_false_1', 'enum_number_false_1')
);

rules.set(rules.rule('enum_number_false_1')
    .type(System.ModelRulesT.enum)
    .require()
    .if([1,2])
    .errorEx('enum_number_false_1', 'enum_number_false_1')
);

// =================================================
// STRING

rules.set(rules.rule('enum_string_true_1')
    .type(System.ModelRulesT.enum)
    .require()
    .if(['s1','s2', '1'])
    .errorEx('enum_string_true_1', 'enum_string_true_1')
);

rules.set(rules.rule('enum_string_false_1')
    .type(System.ModelRulesT.enum)
    .require()
    .if(['s1','s2', '1'])
    .errorEx('enum_string_false_1', 'enum_string_false_1')
);

rules.set(rules.rule('enum_string_false_2')
    .type(System.ModelRulesT.enum)
    .require()
    .if(['s1','s2', '1'])
    .errorEx('enum_string_false_2', 'enum_string_false_2')
);

rules.set(rules.rule('enum_string_false_3')
    .type(System.ModelRulesT.enum)
    .require()
    .if(['s1','s2', '1'])
    .errorEx('enum_string_false_3', 'enum_string_false_3')
);

const validator = new System.ModelValidatorSys(new System.ErrorSys('dev'));
validator.fValid(rules.get(), data);

validator.getResult();

FieldValidator

    // Пример использования 1
    import { FieldValidator, ErrorSys } from "@a-a-game-studio/aa-components/lib";
    let data = '20d00';
    const errorSys = new ErrorSys();
    let myValidator = new FieldValidator(errorSys, data)
            .fSetErrorString('multy')
            .fInt()
            .fMoreOrEqual(5000)
            .fLess(5000);

    assert.ok(!myValidator.fIsOk());
    assert.ok(errorSys.getErrorCount() == 3);

Получился список ошибок

    { 
        "multy.isNotInt": "isNotInt",
        "multy.isNotMoreOrEqualThan": "isNotMoreOrEqualThan",
        "multy.isNotLessThan": "isNotLessThan" 
    }
    // Пример использования 2
    import { FieldValidator, ErrorSys } from "@a-a-game-studio/aa-components/lib";
    let data = 10000;
    const errorSys = new ErrorSys();

    let iArg1 = 1000;
    let iArg2 = 1000;

    const tstFnc = (arg1: number, arg2: number) => {
        iArg1 = arg1;
        iArg2 = arg2;
    };

    let myValidator = new FieldValidator(errorSys, data)
        .fSetErrorString('multy')
        .fInt()
        .fMoreOrEqual(5000)
        .fDoIfOk(tstFnc, [2, 3])
        ;

    assert.ok(myValidator.fIsOk());

    assert.ok(iArg1 == 2);
    assert.ok(iArg2 == 3);
    // Пример использования 3
    import { FieldValidator, ErrorSys } from "@a-a-game-studio/aa-components/lib";
    let data = 10000;
    const errorSys = new ErrorSys();

    let iArg1 = 1000;
    let iArg2 = 1000;

    const tstFnc = (arg1: number, arg2: number) => {
        return new Promise((resolve, reject) => {
            iArg1 = arg1;
            iArg2 = arg2;

            resolve('funcOk');
        })
    };

    let myValidator = new FieldValidator(errorSys, data)
        .fSetErrorString('multy')
        .fInt()
        .fMoreOrEqual(5000);

    let resp = await myValidator.fDoIfOkAsync(tstFnc, [2, 3]);

    assert.ok(myValidator.fIsOk());

    assert.ok(iArg1 == 2);
    assert.ok(iArg2 == 3);
    // Пример использования 4
    import { FieldValidator, ErrorSys } from "@a-a-game-studio/aa-components/lib";
   
    const errorSys = new ErrorSys();
    let login = 'user';
    let pass = 'test pass';
    let passConfirm = 'test pass';

    const loginFnc = (login: string, pass: string) => {
        // Do login
    }

    new FieldValidator(errorSys, login)
        .fSetErrorString('login')
        .fExist()
        .fText()
        .fMinLen(5)

        .fSetData(pass)
        .fSetErrorString('pass')
        .fExist()
        .fText()
        .fMinLen(7)

        .fSetData(passConfirm)
        .fSetErrorString('passConfirm')
        .fExist()
        .fText()
        .fMinLen(7)
        .fEqual(pass)

        .fDoIfOk(loginFnc, [login, pass]);
    // Пример использования 5 - асинхронная ф-я
    import { FieldValidator, ErrorSys } from "@a-a-game-studio/aa-components/lib";
    
    const errorSys = new ErrorSys();
    let login = 'user';
    let pass = 'test pass';
    let passConfirm = 'test pass';

    const faLoginFnc = async (login: string, pass: string) => {
        // Do login ...
    }
    const faAfterloginFnc = async (someData: any) => {
        // Do something ...
    }

    const myValidator = new FieldValidator(errorSys, login)
        .fSetErrorString('login')
        .fExist()
        .fText()
        .fMinLen(5)

        .fSetData(pass)
        .fSetErrorString('pass')
        .fExist()
        .fText()
        .fMinLen(7)

        .fSetData(passConfirm)
        .fSetErrorString('passConfirm')
        .fExist()
        .fText()
        .fMinLen(7)
        .fEqual(pass);

    myValidator.faDoIfOkAsync(() => faLoginFnc(login, pass))
        .then((data: any) => myValidator.faDoIfOkAsync(() => faAfterloginFnc(data)))
        .then((data: any) => myValidator.faDoIfOkAsync(() => faAfterloginFnc(data)))
        .then((data: any) => myValidator.faDoIfOkAsync(() => faAfterloginFnc(data)))
        
        ;