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 🙏

© 2026 – Pkg Stats / Ryan Hefner

angulator

v1.0.0

Published

An angular plugin to validate forms using annotation on model.

Readme

angulator

An angular plugin to validate forms using annotation on model.

Author

Nabil MANSOURI

How to use it

1- Import dependency

npm i --save angulator

2- Samples

See demo folder! Or run npm test

Import module

import {
  AngulatorModule
} from "angulator";


@NgModule({
  declarations: [
  ],
  imports: [
    AngulatorModule 
  ],
  bootstrap: []
})
export class AppModule {
}

Annotate model

import {
  MinLength, MaxLength, EnabledIf, MaxLengthIf, DisabledIf, Capitalize,
  RequiredIf, Required, RequiredTrue, Length, IsEqual, Min, Max,
  MinDate, MaxDate, MinArray, MaxArray, Range, Pattern,
  IsIP, Digits, DateIso, IsEmail, IsDate, IsUrl, IsNumber,
  DateGt, DateLt, Phone, Unaccent, ReadOnly, DateLimit
} from "angulator"; 

export class User {
  @MinLength(5) @MaxLength(10) name: string;
  hasBrother: boolean;
  age: number;
  sexe: string;
  happy: string;
  colors = [];
  @RequiredIf("hasBrother", true) brother: string;
  //OTHER 
  @Required() required: string;
  @RequiredTrue() requiredTrue: boolean;
  requiredDep: boolean;
  @RequiredIf("requiredDep") requiredIf: string;
  enabledDep: boolean;
  @EnabledIf("enabledDep") enabledIf: string;
  disabledDep: boolean;
  @DisabledIf("disabledDep") disabledIf: string;
  maxLengthDep: string;
  @MaxLengthIf("maxLengthDep", 30, " ") maxLengthIf: string;
  @Unaccent() unaccent: string;
  @Capitalize() captitalize: string;
  @ReadOnly() readonly: string;
  @MinLength(5) minlength: string;
  @MaxLength(5) maxlength: string;
  @Length(5) length: string;
  @IsEqual(5) isequal: number;
  @Min(5) min: number;
  @Max(5) max: number;
  @MinDate(DateLimit.Today) minDate: Date;
  @MaxDate(DateLimit.Today) maxDate: Date;
  @MinArray(5) minArray: number[] = [];
  @MaxArray(5) maxArray: number[] = [];
  @Range(2, 4) range: number;
  @Pattern(/d+/) pattern: string;
  @IsIP() isip: string;
  @Digits() digits: string;
  @DateIso() dateiso: string;
  @IsEmail() isemail: string;
  @IsDate() isdate: Date;
  @IsUrl() isurl: string;
  @IsNumber() isnumber: number;
  dategtDep: Date;
  @DateGt("dategtDep") dategt: Date;
  dateltDep: Date;
  @DateLt("dateltDep") datelt: Date;
  @Phone() isphone: string;
}

Add the directive on template

<div [nbGroup]="user" ngForm>
    <div >
        Name:
        <input type="text" nbModel="name" class="name" (nbModelChange)="changed()" />
    </div>
    <div>
        Has brother:
        <input type="checkbox" nbModel="hasBrother" class="hasBrother" (nbModelChange)="changedCheck()" />
    </div>
    <div>
        <input type="text" nbModel="brother" class="brother" />
    </div>
    <div>
        <input type="number" nbModel="age" class="age" (nbModelChange)="changedNum()" />
    </div>
    <div>
        <input type="radio" nbModel="sexe" class="girl" value="girl" (nbModelChange)="changedRadio()" />
    </div>
    <div>
        <input type="radio" nbModel="sexe" class="boy" value="boy" (nbModelChange)="changedRadio()" />
    </div>
    <div>
        <select nbModel="happy" class="happy" (nbModelChange)="changedSelect()">
            <option value="yes" class="yes">YES</option>
            <option value="no" class="no">NO</option>
        </select>
    </div>
    <div>
        <select multiple nbModel="colors" class="colors" (nbModelChange)="changedSelect()">
            <option value="blue" class="blue">blue</option>
            <option value="yellow" class="yellow">yellow</option>
            <option value="green" class="green">green</option>
        </select>
    </div>
</div>

How does it works?

This module provide two directives "nbGroup" and "nbModel". These directives extends "ngModel" and add some validators automatically. "nbModel" manage a state that let accessor listen and modify the DOM if needed. For example @MaxLength change the state of the model and the default accessor will add a property "maxLength" on the DOM.

List of annotation

MinLength, MaxLength, Length

Accept an integer as parameter. It validates that the input field (string) has a length greater (or smaller) than the value provide as parameter. It also add an attribute "maxLength" (or "minLength") to the DOM element.

EnabledIf, DisabledIf

Accept a string or an array of string (dependencies) as parameter. The field is disabled or enabled according to the dependencies. Dependencies are others fields that we need to listen in order to update the state of the model. For exemple: a checkbox "hasName" could enable or disable the field "name". So "name" will be annoted by @EnabledIf("hasName")

MaxLengthIf

Accept a string or an array of string (dependencies) as parameter and an integer (maxLength) The maxlength of the field is computed according to dependencies fields. For example, you could have a phone number with a maxlength of 10 and another field prefix. If prefix is filled, maxlength of phone is: maxlength-length(prefix).

Capitalize

It automatically capitalize the input while typing

RequiredIf

The field is required or not according to the dependencies. Dependencies are others fields that we need to listen in order to update the state of the model. For exemple: a checkbox "isRequired" could force the field "name".

Required

The field is required

RequiredTrue

Apply to a checkbox. The checkbox must be checked by the user.

IsEqual, Min, Max,Range

Accept an integer as parameter. The number must be equal (or greater or smaller) than the value.

MinDate, MaxDate

Accept a date or a constant (TOday, Now...) The date must be greater (or smaller) than the value.

MinArray, MaxArray

Accept an integer as parameter. The collection length must be greater (or smaller) than the value.

Pattern

Accept a regex or a string as parameter. The value must match the regex.

IsIP

The value must be an IP address

Digits

The value must contains only digits

DateIso

The value must be a date with format : YYYY-MM-DD

IsEmail

The value must be an email

IsDate

THe value must be a valid date

IsUrl

THe value must be an URL.

IsNumber

The value must be a valid number (input type number)

DateGt, DateLt

Accept a string or an array of string (dependencies) as parameter. The value must be greater (or smaller) than the dependency value. The aim is to validate one date regarding another.

Phone

The value must be a valid phone

Unaccent

Automatically unaccent the text while the user is typing.

ReadOnly

The field is a read only field

TODO

  • externalize validator in order to make a backend validation using the same model
  • externalize accessor because it is platform dependent (web)
  • extend to make it available for nativescript (mobile apps)