2.0.0 • Published 4 years ago

@enbock/simple-storage v2.0.0

Weekly downloads
1
License
MIT
Repository
-
Last release
4 years ago

Simple Storage for PWA

Testing Publishing Scrutinizer Code Quality Code Coverage Build Status

A simple storage manager for Progressive Web Applications.
The Simple Storage can store:

  • string
  • int
  • boolean
  • number
  • (passive) object

Features

  • Provide Adapter(Callback) based Interface
  • Developed with Injection Methodology
  • Any storage of Web Storage Interface can be used.
  • Data model to JSON and back conversion.

Usage

const storage: DataStorage = new DataStorage('example', window.localStorage);
const adapter: IObserverAdapter<string> = {
  onChange(newValue: string): void {
    console.log('Value "' + newValue + '" was stored in "example::theKey".');
  }
};
const observer: Observer<string> = new Observer<string>(
  storage.loadData('theKey', 'initial value'),
  storage.attach<string>('theKey', adapter)
);

observer.value = 'Hello World!';

Testing

Using this library in your project

This library is providing in ECMAScript® 2020 language. When you use jest, you get this error by using my library:

  Details:
  
  <YOUR_PATH>\node_modules\@enbock\state-value-observer\ListenerAdapter.js:1
  export default class ListenerAdapter {
  ^^^^^^
  
  SyntaxError: Unexpected token 'export'
      at compileFunction (vm.js:341:18)

See more: https://jestjs.io/docs/en/tutorial-react-native#transformignorepatterns-customization

Reason and solution

Jest running internally on ES5, that does not know the ES6-imports.

Force converting ES6+ Libraries

To solve this, you have to exclude all my libraries from the exclusion-list:

"transformIgnorePatterns": [
  "/node_modules/(?!(@enbock)/)"
]
Let babel "learn" ES6+

babel.config.js

module.exports = {
  presets: [
    ['@babel/preset-env', {targets: {node: 'current'}}],
    '@babel/preset-typescript'
  ]
};

See more: https://github.com/facebook/jest#using-typescript

Run tests

yarn test

Building

yarn build
2.0.0

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago

0.1.0-dev.2

4 years ago