# dotnetjs

> .Net framework support in javascript

Latest version **1.7.5** (published 2017-08-18) · MIT license · 0 weekly downloads

## Install

```sh
npm install dotnetjs
pnpm add dotnetjs
yarn add dotnetjs
bun add dotnetjs
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.7.5 |
| Published | 2017-08-18 |
| First published | 2016-10-20 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Master Yu |
| Maintainers | masteryu |
| Keywords | javascript, typescript, dotnet, collections, linq, string-format |

## Links

- npm: https://www.npmjs.com/package/dotnetjs
- Repository: https://github.com/Master76/dotnetjs
- Homepage: https://github.com/Master76/dotnetjs#readme
- Issues: https://github.com/Master76/dotnetjs/issues
- npm.io page: https://npm.io/package/dotnetjs

## Alternatives

- [@openai/codex-sdk](https://npm.io/package/@openai/codex-sdk.md) — 731.4K weekly downloads
- [babel-plugin-transform-react-jsx](https://npm.io/package/babel-plugin-transform-react-jsx.md) — 565.0K weekly downloads
- [babel-helper-remove-or-void](https://npm.io/package/babel-helper-remove-or-void.md) — 508.5K weekly downloads
- [@pnpm/store-controller-types](https://npm.io/package/@pnpm/store-controller-types.md) — 186.9K weekly downloads
- [react-native-signature-canvas](https://npm.io/package/react-native-signature-canvas.md) — 155.6K weekly downloads

## Recent versions

- 1.7.5 (latest) — 2017-08-18
- 1.7.4 — 2017-08-17
- 1.7.3 — 2017-08-16
- 1.7.2 — 2017-05-05
- 1.7.1 — 2017-05-05
- 1.7.0 — 2017-05-04
- 1.6.5 — 2017-04-26
- 1.6.4 — 2017-03-15
- 1.6.3 — 2017-03-15
- 1.6.2 — 2017-01-25
- 1.6.1 — 2017-01-25
- 1.6.0 — 2017-01-25
- 1.5.18 — 2016-12-16
- 1.5.17 — 2016-12-12
- 1.5.16 — 2016-12-07
- … 28 more at https://npm.io/package/dotnetjs/versions

## README

# DotnetJs
.Net Framework support in javascript

## Get DotnetJs

1. Nodejs

    firstly, run ```npm install dotnetjs --save``` 

    If you are using typescript: 

    ```typescript 
    import * as DotnetJs from 'dotnetjs';
    ```

    else just like the others: 

    ```javascript 
    var DotnetJs = require('dotnetjs');
    ```

2. Browser

    run ```npm install dotnetjs --save``` 
    
    or download the files in the dist directory.
    
    or run ```bower install dotnetjs```

    ```html
    <!--if debug-->
    <script src="dotnet.js"></script>
    <!--if release-->
    <script src="dotnet.min.js"></script>
    <script src="your.js"></script>
    ```

    in your .ts file: 
    
    ```typescript
    /// <reference path="dotnet.d.ts" />
    ```
    
## Work with DotnetJs

DotnetJs uses similiar interface as it is in .Net Framework.

### Linq

If you are about to use complicated Linq Expressions, first make a instance of LinqIntermediate by using LinqStart:

```typescript
var expression = DotnetJs.Linq.LinqStart(enumerable);
```
    
the enumerable can be any type that implements IEnumerable, in addition, I implemented it for the Array. Then you can do like the following:

```typescript
expression.Where(...).Select(...).ToArray();
```

Or use:

```typescript
DotnetJs.Linq.Where(enumerable, ...).Select(...).ToArray();
```

remember to use ```ToArray``` or ```ToList``` or ```ToDictionary``` to end the expression(if the result is still IEnumerable). No matter how long your linq is, the time complexity is always O(n).

### String Format

The match case: ```{index[,alignment][:format]}```, with 2 optional parameters (alignment and format).

1. index

    Index indicate the index of the object in the following parameter args[].

2. alignment

    Alignment will do PadLeft or PadRight with spaces, if it is positive then do PadLeft, else do PadRight.

3. format

    With the magic char ':', you can control the format of your toString method. For number, there are specifiers ['D', 'E', 'F', 'G', 'N', 'P', 'X'] implemented, [usage portal](https://msdn.microsoft.com/en-us/library/dwhawy9k(v=vs.110).aspx). Now, let's see the following example:

    ```typescript
    var number = 1.0437E21;
    var specifier = 'G';
    console.writeLine("   {0,-22} {1:G}", specifier + ":", number);
    // output:   G:                     1.0437e+21
    
    class Foo {
        public bar: number;
        public toString(format: string) {
            if (format == null)
                return this.bar.toString();
            if (format == '!')
                return '!' + this.bar;
            return '?' + this.bar;
        }
    }

    var foo = new Foo();
    foo.bar = 65521;

    console.log(String.Format('test Foo toString: {0:!}, {0:?}, {0,10}', foo));
    // output: test Foo toString: !65521, ?65521,      65521
    ```

### Indexer for the collections

As there isn't have a way to implement indexer in typescript. You have to call the element of List or IDictionay, by using ```GetValue(index || key)``` and ```SetValue(index || key, value)```, but not ```collection[index || key]```.

### GetHashCode

Both object, string, boolean or number are supported for the GetHashCode Method, actually for the object, it is more likely to be called as a 'unique id'.

To get a new hashcode for an object, call the method with parameter 'ture'. But please becareful, this may due to unexpected errors (e.g.: when you are using ```Dictionary```).

### Equals

If you inherit from typescript abstract class ValueType, remember to override Equals method, else it will compare the result of GetHashCode() to decide whether it equals to the other.

### ContainsKey

```typescript
var obj = { name: 'readme' };

console.log(obj.ContainsKey('name'));
// output: true
```

### TODO

More extensions. If you have any idea, please feel free to contact me.

## Test

Change directory to tests, then run ```tsc``` to compile the typescript files, then run ```npm link ../``` secondly, to set up the local dependence, finally run ```node index.js``` to start the test.

## Contributors

[Master76](https://github.com/Master76) Author

[AsherWang](https://github.com/AsherWang) RegExp suport

---
_Source: https://npm.io/package/dotnetjs · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
