# snooze-baselib

> basic opinionated entities/services for a snoozejs project

Latest version **1.0.0-alpha.3** (published 2015-01-07) · MIT license · 0 weekly downloads

## Install

```sh
npm install snooze-baselib
pnpm add snooze-baselib
yarn add snooze-baselib
bun add snooze-baselib
```

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0-alpha.3 |
| Published | 2015-01-07 |
| First published | 2015-01-02 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Micah Williamson |
| Maintainers | iamchairs |
| Keywords | snooze, baselib, base, lib, service, entity |

## Links

- npm: https://www.npmjs.com/package/snooze-baselib
- Repository: git@github.com:iamchairs/snooze-baselib
- Homepage: https://github.com/iamchairs/snooze-baselib
- Issues: https://github.com/iamchairs/snooze-baselib/issues
- npm.io page: https://npm.io/package/snooze-baselib

## Alternatives

- [@cantoo/pdf-lib](https://npm.io/package/@cantoo/pdf-lib.md) — 297.9K weekly downloads
- [datatables.net-buttons](https://npm.io/package/datatables.net-buttons.md) — 200.1K weekly downloads
- [@ckeditor/ckeditor5-export-pdf](https://npm.io/package/@ckeditor/ckeditor5-export-pdf.md) — 167.0K weekly downloads
- [scanbot-web-sdk](https://npm.io/package/scanbot-web-sdk.md) — 15.0K weekly downloads
- [@syncfusion/ej2-angular-pdfviewer](https://npm.io/package/@syncfusion/ej2-angular-pdfviewer.md) — 8.8K weekly downloads

## Recent versions

- 1.0.0-alpha.3 (latest) — 2015-01-07
- 1.0.0-alpha.2 — 2015-01-02
- 1.0.0-alpha.1 — 2015-01-02

## README

# snooze-baselib 1.0.0-alpha.1

## Installation
In your applications root direction install via npm.

    npm install snooze-baselib --save

In you main.js file import the `snooze-baselib` module.

    snooze.module('myApp', ['snooze-baselib']);
    
## Entities

`snooze-baselib` provides 3 Entities. `service`, `value`, and `constant`.

#### Service

A service is generic and unopinionated as far as Entities go. It allows you to inject functionality into other Entities, run processes, or config processes. Once `snooze-baselib` has been imported, the `module.service` method becomes available.

    snooze.module('myApp', ['snooze-baselib'])
        .service('MyService', function() {});
        
A service is constructed with an injectable function. What is returned by the function becomes the `EntityInstance`. If we wanted to create a Math service that could do our basic mathematical operations we can create the service like so-

    snooze.module('myApp', ['snooze-baselib'])
        .service('MyService', function() {
            function sum(num1, num2) {
                return num1 + num2;
            };
            
            function difference(num1, num2) {
                return num1 - num2;
            };
            
            function product(num1, num2) {
                return num1 * num2;
            };
            
            function quotient(num1, num2) {
                return num1 / num2;
            };
            
            return {
                sum: sum,
                difference: difference,
                product: product,
                quotient: quotient
            };
        });
        
The returned object makes these methods available when injected.

    snooze.module('myApp')
        .service('Bank', function(Math) {
            var accountBalance = 1000;
            
            function deposit(amt) {
                accountBalance = Math.sum(accountBalance, amt);
            };
            
            function withdraw(amt) {
                accountBalance = Math.difference(accountBalance, amt);
            };
            
            function getBalance() {
                return accountBalance;
            };
            
            return {
                deposit: deposit,
                withdraw: withdraw,
                getBalance: getBalance
            };
        })
        .run(function(Bank) {
            Bank.deposit(500);
            console.log(Bank.getBalance());
            Bank.withraw(750);
            console.log(Bank.getBalance());
        });
        
Outputs

    1500
    750
    
You can also define what specifically gets injected when or configured by returned a `$get` or `$config` property.

    snooze.module('myApp')
        .service('Bank', function(Math) {
            var accountBalance = 0;
            
            function deposit(amt) {
                accountBalance = Math.sum(accountBalance, amt);
            };
            
            function withdraw(amt) {
                accountBalance = Math.difference(accountBalance, amt);
            };
            
            function getBalance() {
                return accountBalance;
            };
            
            function initBalance(balance) {
                accountBalance = balance;
            };
            
            return {
                $get: {
                    deposit: deposit,
                    withdraw: withdraw,
                    getBalance: getBalance
                },
                $config: {
                    initBalance: initBalance
                }
            };
        })
        .config(function(Bank) {
            Bank.initBalance(1000);
            console.log(Bank.deposit);
        })
        .run(function(Bank) {
            Bank.deposit(1000);
            console.log(Bank.initBalance);
            console.log(Bank.getBalance());
        });

Outputs

    undefined
    undefined
    2000
    
Finally you can set if the `service` is `injectable`, `configurable`, or `private` by setting the `$injectable`, `$configurable`, and `$private` properties respectively.

    snooze.module('myApp')
        .service('Bank', function(Math) {
            return {
                $injectable: false,
                $configurable: false,
                $private: true
            };
        });
        
The Bank `service` is now not injectable, configurable, and cannot be imported into other modules (and is useless at this point).

#### Value

A single value can be passed as an injectable.

    snooze.module('myApp')
        .value('port', 80)
        .service('HTTP', function(port) {
            // ... do something with port
        });

The value can be a string, function, object, array, integer, anything.

#### Constant

A constant is the same as a value except it's value is copied instead of returned. This means if an object or array is used the injected value cannot change the original.

    snooze.module('myApp')
        .constant('settings', {color: 'blue'})
        .run(function(settings) {
            settings.color = 'red';
            console.log(settings.color);
        })
        .run(function(settings) {
            console.log(settings.color);
        });
        
Outputs

    red
    blue
    
## Import Processes

**importEntities** - Imports Entities from all imported modules to the importee module. Imported Entities will overwrite existing Entities with the same name.
**importEntityGroups** - Imports EntityGroups from all imported modules to the importee module. If an importing EntityGroup has the same type as an existing EntityGroup it will be skipped.

## Config Preprocessors

**mergeModeConfigs** - If a mode is defined and that mode exists in the modes object, those properties will be merged on top of the existing config.

## snooze.json extensions

`snooze-baselib` Allows creating config modes. This lets you create a base config but merge properties on top of the base config depending on the `mode` you define.

    {
        "mode": "development",
        "modes": {
            "development": {
                "silent": false
            },
            "production": {
                "silent": true
            },
            "foobar": {
                "silent": true,
                "bar": "baz"
            }
        }
    }

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