Documentation
    Preparing search index...

    Class HashProperty

    A specialized string property that automatically hashes incoming values before storing them. Useful for storing passwords, secret tokens, or generating unique fingerprints. Values set on this property are one-way hashed and cannot be reversed.

    const password = new HashProperty({
    name: 'password',
    algorithm: HashProperty.ALGORITHM_SHA256,
    salt: 'mySecretSalt'
    });

    password.set('mySuperPassword');
    console.log(password.val()); // Returns the SHA256 hashed string
    const isValid = password.compare('mySuperPassword'); // true

    Hierarchy (View Summary)

    Index

    Constructors

    Properties

    _algorithm: string
    _allows: string[] = []
    _defaultValue: any
    _events: { [key: string]: Function } = {}
    _fullSearch: boolean = false
    _hasChanged: boolean
    _htmlType: PropertyHTMLType = 'off'
    _id: string
    _mandatory: boolean = false
    _maxLength: number = 0
    _minLength: number = 0
    _name: string
    _parent: DataObjectClass<any> | undefined
    _prefixed: boolean = false
    _protected: boolean = false
    _rawValue: boolean = true

    Set to false to bypass some rules

    _salt: string = ''
    _value: string | undefined
    ALGORITHM_BCRYPT: string = 'bcrypt'

    Identifier for the BCRYPT hashing algorithm.

    ALGORITHM_MD5: string = 'md5'

    Identifier for the MD5 hashing algorithm.

    ALGORITHM_SHA1: string = 'sha1'

    Identifier for the SHA1 hashing algorithm.

    ALGORITHM_SHA256: string = 'sha256'

    Identifier for the SHA256 hashing algorithm.

    ALLOW_DIGITS: string = 'digits'

    Permission flag to allow numeric digits.

    ALLOW_LETTERS: string = 'letters'

    Permission flag to allow alphabetic letters.

    ALLOW_NUMBERS: string = 'numbers'

    Permission flag to allow number values.

    ALLOW_SPACES: string = 'spaces'

    Permission flag to allow whitespace characters.

    ALLOW_STRINGS: string = 'strings'

    Permission flag to allow string values.

    EVENT_ONCHANGE: string = 'onChange'

    Event name triggered when the property value changes.

    EVENT_ONDELETE: string = 'onDelete'

    Event name triggered when the property is deleted.

    TRANSFORM_LCASE: string = 'lower'

    Transformation identifier to convert string to lowercase.

    TRANSFORM_UCASE: string = 'upper'

    Transformation identifier to convert string to uppercase.

    TYPE: string = 'hash'

    The string literal type identifier for this property.

    Accessors

    • get allows(): string[]

      Returns string[]

    • get fullSearch(): boolean

      Returns boolean

    • set fullSearch(mode: boolean): void

      Parameters

      • mode: boolean

      Returns void

    • get hasChanged(): boolean

      Returns boolean

    • set hasChanged(val: boolean): void

      Parameters

      • val: boolean

      Returns void

    • get htmlType(): PropertyHTMLType

      Returns PropertyHTMLType

    • set htmlType(type: PropertyHTMLType): void

      Parameters

      Returns void

    • get mandatory(): boolean

      Returns boolean

    • get maxLength(): number

      Returns number

    • set maxLength(max: number): void

      Parameters

      • max: number

      Returns void

    • get minLength(): number

      Returns number

    • set minLength(min: number): void

      Parameters

      • min: number

      Returns void

    • get name(): string

      Returns string

    • get protected(): boolean

      Returns boolean

    Methods

    • Parameters

      • value: boolean | undefined

      Returns value is true | undefined

    • Internal method to perform the cryptographic hash on a raw string. Uses Node.js native crypto module.

      Parameters

      • value: string

        The raw string to hash.

      Returns string

      The hexadecimal representation of the hashed string.

      If the chosen algorithm is unsupported.

    • Creates a deep clone of the current property instance, preserving its prototype chain.

      Returns any

      A new independent instance of the property.

    • Compares a raw cleartext string against the stored hashed value. Automatically applies the configured salt and algorithm to the input before comparison.

      Parameters

      • value: string

        The raw cleartext string to test.

      Returns boolean

      True if the hashed input matches the stored hash, false otherwise.

    • Retrieves the string value, optionally applying a casing transformation.

      Parameters

      • transform: string | undefined = undefined

        Use TRANSFORM_LCASE or TRANSFORM_UCASE to mutate output case.

      Returns string | undefined

      The raw or transformed string, or undefined.

    • Hashes the provided value and stores the hashed result. String length constraints (from StringProperty) are bypassed after hashing.

      Parameters

      • value: string

        The raw cleartext string to hash and store.

      • setChanged: boolean = true

        Whether to mark the property as modified.

      Returns HashProperty

      The property instance for chaining.

    • Serializes the property for JSON stringification.

      Returns any

      The raw internal value of the property.

    • Retrieves the current value of the property, or its default value if currently undefined.

      Parameters

      • transform: any = undefined

        An optional transformation function applied to the value before returning it.

      Returns any

      The raw or transformed property value.