2.1.4 • Published 5 years ago

vincijs v2.1.4

Weekly downloads
2
License
ISC
Repository
github
Last release
5 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

5 years ago

2.1.3

5 years ago

2.1.2

5 years ago

2.1.1

5 years ago

1.0.39

6 years ago

1.0.38

6 years ago

1.0.37

6 years ago

1.0.36

6 years ago

1.0.35

6 years ago

1.0.34

6 years ago

1.0.33

6 years ago

1.0.32

6 years ago

1.0.31

6 years ago

1.0.30

6 years ago

1.0.29

6 years ago

1.0.27

6 years ago

1.0.25

6 years ago

1.0.24

6 years ago

1.0.23

6 years ago

1.0.21

6 years ago

1.0.20

6 years ago

1.0.19

6 years ago

1.0.18

6 years ago

1.0.17

6 years ago

1.0.16

6 years ago

1.0.15

6 years ago

1.0.14

6 years ago

1.0.13

6 years ago

1.0.12

6 years ago

1.0.11

6 years ago

1.0.10

6 years ago

1.0.9

6 years ago

1.0.8

6 years ago

1.0.7

6 years ago

1.0.6

6 years ago

1.0.5

6 years ago

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago