Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/Celtian/ngx-nullable

This library provides a way to make properties nullable in Angular templates.
https://github.com/Celtian/ngx-nullable

angular library

Last synced: 1 day ago
JSON representation

This library provides a way to make properties nullable in Angular templates.

Awesome Lists containing this project

README

        



NgxNullable

[![npm version](https://badge.fury.io/js/ngx-nullable.svg)](https://badge.fury.io/js/ngx-nullable)
[![Package License](https://img.shields.io/npm/l/ngx-nullable.svg)](https://www.npmjs.com/ngx-nullable)
[![NPM Downloads](https://img.shields.io/npm/dm/ngx-nullable.svg)](https://www.npmjs.com/ngx-nullable)
[![Snyk](https://snyk.io/advisor/npm-package/ngx-nullable/badge.svg)](https://snyk.io/advisor/npm-package/ngx-nullable)
[![codecov](https://codecov.io/gh/Celtian/ngx-nullable/branch/master/graph/badge.svg?token=1IRUKIKM0D)](https://codecov.io/gh/celtian/ngx-nullable/)
[![stars](https://badgen.net/github/stars/celtian/ngx-nullable)](https://github.com/celtian/ngx-nullable/)
[![forks](https://badgen.net/github/forks/celtian/ngx-nullable)](https://github.com/celtian/ngx-nullable/)
[![HitCount](http://hits.dwyl.com/celtian/ngx-nullable.svg)](http://hits.dwyl.com/celtian/ngx-nullable)

This library provides a way to make properties nullable in Angular templates.

> ✓ _Angular 18 compatible_

Here's the [demo](http://celtian.github.io/ngx-nullable/)

- Lightweight
- No dependencies!

## 🛠️ Install

1. Use yarn (or npm) to install the package

```terminal
yarn add ngx-nullable
```

2. Add `provideNullable` into your config (optional)

```typescript
import { provideNullable } from 'ngx-nullable';

export const appConfig: ApplicationConfig = {
providers: [
// ...
provideNullable({
character: '---',
separator: ' | ',
displayZero: true
})
]
};
```

or module

```typescript
import { provideNullable } from 'ngx-nullable';

@NgModule({
// ...
providers: [
// ...
provideNullable({
character: '---',
separator: ' | ',
displayZero: true
})
]
})
```

## 🚀 Quick start

### Pipe example

```html


  • {{ -1000 | ngxNullable }}

  • {{ 1000 | ngxNullable }}

  • {{ 0 | ngxNullable }}

  • {{ null | ngxNullable }}

  • {{ undefined | ngxNullable }}

  • {{ 'string' | ngxNullable }}

  • {{ '' | ngxNullable }}

  • {{ ' ' | ngxNullable }}


  • {{ ['', ' ', undefined, null] | ngxNullableJoin }}

  • {{ ['AAA', 'BBB', 'CCC'] | ngxNullableJoin }}

  • {{ ['AAA', '', ' ', undefined, null, 'BBB'] | ngxNullableJoin }}

  • {{ [] | ngxNullableJoin }}


```

### Signals example

```Typescript

@Component({
// ...
})
class Example {
private readonly nullable = inject(NgxNullableService);
public readonly input = signal('');
public readonly computed = computed(() => this.nullable.fromString(this.input()));
}

```

## 🛠️ Options

### Root options

| Option | Type | Default | Description |
| --------------- | ------- | ------- | ------------------------------------------------------------ |
| **character** | string | '—' | The character to display when the value is null or undefined |
| **separator** | string | ', ' | The separator to use when joining multiple values |
| **displayZero** | boolean | true | Whether to display zero when the value is zero |

## 📦 Dependencies

_None_

## 🪪 License

Copyright © 2024 [Dominik Hladik](https://github.com/Celtian)

All contents are licensed under the [MIT license].

[mit license]: LICENSE