当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript type-r.type函数代码示例

本文整理汇总了TypeScript中type-r.type函数的典型用法代码示例。如果您正苦于以下问题:TypeScript type函数的具体用法?TypeScript type怎么用?TypeScript type使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了type函数的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: convert

import {DateType, ChainableAttributeSpec, type} from "type-r";

const msDatePattern  = /\/Date\(([0-9]+)\)\//;

export class MicrosoftDateType extends DateType {
    convert( next ) {
        if( typeof next === 'string' ){
            const msDate = msDatePattern.exec( next );
            if( msDate ){
                return new Date( Number( msDate[ 1 ] ) );
            }
        }

        return DateType.prototype.convert.apply( this, arguments );
    }

    toJSON( value ) { return value && `/Date(${ value.getTime() })/`; }
}

export const MicrosoftDate = new ChainableAttributeSpec({
    type      : Date,
    _metatype: MicrosoftDateType
})

export const Timestamp = type( Date ).toJSON( x => x && x.getTime() );
开发者ID:Volicon,项目名称:Type-R,代码行数:25,代码来源:dates.ts

示例2: ChainableAttributeSpec

    return new ChainableAttributeSpec( { type : this, value : x, hasCustomDefault : true } );
};

Object.defineProperty( Function.prototype, 'isRequired', {
    get() { return this._isRequired || this.has.isRequired; },
    set( x ){ this._isRequired = x; }
});

Object.defineProperty( Function.prototype, 'asProp', {
    get() { return this.has.asProp; },
});

Object.defineProperty( Function.prototype, 'has', {
    get() {
        // workaround for sinon.js and other libraries overriding 'has'
        return this._has || type( this );
    },

    set( value ) { this._has = value; }
} );


Object.defineProperties( Date, {
    microsoft: {
        value: MicrosoftDate
    },

    timestamp: {
        value: Timestamp
    }
} );
开发者ID:Volicon,项目名称:Type-R,代码行数:31,代码来源:index.ts

示例3: isUrl

import { AttributeCheck, type } from 'type-r';

const urlPattern = /^(?:(?:https?|ftp):\/\/)(?:\S+(?::\S*)?@)?(?:(?!(?:10|127)(?:\.\d{1,3}){3})(?!(?:169\.254|192\.168)(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)(?:\.(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)*(?:\.(?:[a-z\u00a1-\uffff]{2,}))\.?)(?::\d{2,5})?(?:[/?#]\S*)?$/i;

export function isUrl( x : string ) {
    return !x || urlPattern.test( x );
}

(isUrl as AttributeCheck).error = 'Not valid URL'

export const Url = type( String ).check( isUrl );
开发者ID:Volicon,项目名称:Type-R,代码行数:11,代码来源:url.ts

示例4: type

import { Model, type } from 'type-r';

export const SecondsInterval = Model.extend({
    units: [
        'seconds',
        'minutes',
        'hours',
        'days',
        'weeks',
        'months',
        'years'
    ],

    defaults: {
        value: 1,
        interval: type( String ).value('months')
    },

    properties: {
        seconds: function() { return this.getUnitValue(1) },
        minutes: function() { return this.getUnitValue(60) },
        hours: function() { return this.getUnitValue(3600) },
        days: function() { return this.getUnitValue(86400) },
        weeks: function() { return this.getUnitValue(604800) },
        months: function() { return this.getUnitValue(2628000) },
        years: function() { return this.getUnitValue(31536000) }
    },

    getUnitValue( value ){
        return value;
    },
开发者ID:Volicon,项目名称:Type-R,代码行数:31,代码来源:common.ts

示例5: isIPAddress

import { AttributeCheck, type } from 'type-r';

const ipPattern = /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/;

export function isIPAddress( x : string ) {
    return !x || ipPattern.test( x );
}

(isIPAddress as AttributeCheck).error = 'Not valid IP address'

export const IPAddress = type( String ).check( isIPAddress );
开发者ID:Volicon,项目名称:Type-R,代码行数:11,代码来源:ip.ts

示例6: isEmail

import { AttributeCheck, type } from 'type-r';

const emailPattern = /^[-a-z0-9~!$%^&*_=+}{\'?]+(\.[-a-z0-9~!$%^&*_=+}{\'?]+)*@([a-z0-9_][-a-z0-9_]*(\.[-a-z0-9_]+)*\.(aero|arpa|biz|com|coop|edu|gov|info|int|mil|museum|name|net|org|pro|travel|mobi|[a-z][a-z])|([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}))(:[0-9]{1,5})?$/i;

export function isEmail( x : string ) {
    return !x || !!x.match( emailPattern );
}

(isEmail as AttributeCheck).error = 'Not valid email';

export const Email = type( String ).check( isEmail );
开发者ID:Volicon,项目名称:Type-R,代码行数:11,代码来源:email.ts


注:本文中的type-r.type函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。