2.1.4 • Published 6 years ago

vincijs v2.1.4

Weekly downloads
2
License
ISC
Repository
github
Last release
6 years ago

Patterns

singleton

为开发者提供单例解决方案

why singleton:

usage:

import { SingletonFactory } from './../src/Patterns/Singleton';

/**
 * the class used with singleton contain value field 需要单例使用的类
 */
class TestClass {
    constructor(public value: number) {
        console.log('start');
    }
}

//set TestClass as singleton
SingletonFactory.SetSingletonConstructor('TestClass', TestClass, 9)

console.log('complete setting');

//观察 实体值
console.log(SingletonFactory.GetSingleton<TestClass>('TestClass').value)

//modify the value of singleton
SingletonFactory.GetSingleton<TestClass>('TestClass').value++;

//show the value of singleton again to test that it is single
console.log(SingletonFactory.GetSingleton<TestClass>('TestClass').value)

Utilities

HttpClient

why is HttpClient

usage

import { HttpRequestConfigBuilder, HttpClient } from "../src/Utilities/Http";

// create init parameters
new HttpRequestConfigBuilder().WithCors('no-cors').WithCredentials('omit')
    .WithFormData(new FormData()).Post();
// or using DefaultBuilder with post;'same-origin credentials';'cors'
const data = new HttpRequestConfigBuilder().DefaultBuilder().WithJson({});

// launch request :发起一个请求
new HttpClient().Request('url string', data.Build())
    .then(d => {
        d.data.info = 'I\'m json object from response data if resonse content type is "application/json" '
        return d.data;
    })
    .then(d => {
        console.log(JSON.stringify(d));
    }).catch(e => {
        console.log('show the error');
    })

//an anther method using Request object directly
new HttpClient().Request(new Request('', {}))

Guid

usage:

import { Guid } from "../src/Utilities/Guid";

// string
Guid.Empty();

// create a new guid
Guid.NewId();

// test a string is a guid
Guid.Validate('')  //false
Guid.Validate(Guid.NewId())  //true

Type

usage:

import { Type } from "../src/Utilities/Type";

Type('')  //string
Type({})  //object
Type(function () { }) //function
Type(new Date()) //date
Type(22)  //number
Type(/sss/)  //regexp
Type([])  //array
2.1.4

6 years ago

2.1.3

6 years ago

2.1.2

6 years ago

2.1.1

6 years ago

1.0.39

7 years ago

1.0.38

7 years ago

1.0.37

7 years ago

1.0.36

7 years ago

1.0.35

7 years ago

1.0.34

7 years ago

1.0.33

7 years ago

1.0.32

7 years ago

1.0.31

7 years ago

1.0.30

7 years ago

1.0.29

7 years ago

1.0.27

7 years ago

1.0.25

7 years ago

1.0.24

7 years ago

1.0.23

7 years ago

1.0.21

7 years ago

1.0.20

7 years ago

1.0.19

7 years ago

1.0.18

7 years ago

1.0.17

7 years ago

1.0.16

7 years ago

1.0.15

7 years ago

1.0.14

7 years ago

1.0.13

7 years ago

1.0.12

7 years ago

1.0.11

7 years ago

1.0.10

7 years ago

1.0.9

7 years ago

1.0.8

7 years ago

1.0.7

7 years ago

1.0.6

7 years ago

1.0.5

7 years ago

1.0.4

7 years ago

1.0.3

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago