Skip to content

Commit

Permalink
feat: first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
yisraelx committed Jun 24, 2017
0 parents commit 00d9fb7
Show file tree
Hide file tree
Showing 153 changed files with 13,201 additions and 0 deletions.
19 changes: 19 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# NodeJs
*.log
node_modules

# IDE
.idea
.vscode

# Build
modules/**/*.js.map
modules/**/*.d.ts
modules/**/*.js
modules/**/LICENSE
modules/**/README.md
tmp
.rpt2_cache

# Report
coverage
22 changes: 22 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
sudo: false
language: node_js
node_js:
- '4'
- '6'
- '7'
cache:
directories:
- node_modules
notifications:
email: false
branches:
only:
- master
except:
- /^v\d+\.\d+\.\d+$/
before_script:
- npm run ci:before
script:
- npm run ci:script
after_success:
- npm run ci:after
9 changes: 9 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
The MIT License (MIT)

Copyright © 2017 Yisrael Eliav

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
46 changes: 46 additions & 0 deletions PACKAGES.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@

# Packages:
- **@promises/-all** - [Git](https://github.com/yisraelx/promises/blob/master/modules/-all) - [Npm](https://https://npmjs.com/package/@promises/-all)
- **@promises/-constructor** - [Git](https://github.com/yisraelx/promises/blob/master/modules/-constructor) - [Npm](https://https://npmjs.com/package/@promises/-constructor)
- **@promises/-parallel** - [Git](https://github.com/yisraelx/promises/blob/master/modules/-parallel) - [Npm](https://https://npmjs.com/package/@promises/-parallel)
- **@promises/-prototype** - [Git](https://github.com/yisraelx/promises/blob/master/modules/-prototype) - [Npm](https://https://npmjs.com/package/@promises/-prototype)
- **@promises/-rxjs** - [Git](https://github.com/yisraelx/promises/blob/master/modules/-rxjs) - [Npm](https://https://npmjs.com/package/@promises/-rxjs)
- **@promises/-series** - [Git](https://github.com/yisraelx/promises/blob/master/modules/-series) - [Npm](https://https://npmjs.com/package/@promises/-series)
- **@promises/compose** - [Git](https://github.com/yisraelx/promises/blob/master/modules/compose) - [Npm](https://https://npmjs.com/package/@promises/compose)
- **@promises/core** - [Git](https://github.com/yisraelx/promises/blob/master/modules/core) - [Npm](https://https://npmjs.com/package/@promises/core)
- **@promises/create** - [Git](https://github.com/yisraelx/promises/blob/master/modules/create) - [Npm](https://https://npmjs.com/package/@promises/create)
- **@promises/delay** - [Git](https://github.com/yisraelx/promises/blob/master/modules/delay) - [Npm](https://https://npmjs.com/package/@promises/delay)
- **@promises/error** - [Git](https://github.com/yisraelx/promises/blob/master/modules/error) - [Npm](https://https://npmjs.com/package/@promises/error)
- **@promises/every-parallel** - [Git](https://github.com/yisraelx/promises/blob/master/modules/every-parallel) - [Npm](https://https://npmjs.com/package/@promises/every-parallel)
- **@promises/every-series** - [Git](https://github.com/yisraelx/promises/blob/master/modules/every-series) - [Npm](https://https://npmjs.com/package/@promises/every-series)
- **@promises/exec** - [Git](https://github.com/yisraelx/promises/blob/master/modules/exec) - [Npm](https://https://npmjs.com/package/@promises/exec)
- **@promises/filter-parallel** - [Git](https://github.com/yisraelx/promises/blob/master/modules/filter-parallel) - [Npm](https://https://npmjs.com/package/@promises/filter-parallel)
- **@promises/filter-series** - [Git](https://github.com/yisraelx/promises/blob/master/modules/filter-series) - [Npm](https://https://npmjs.com/package/@promises/filter-series)
- **@promises/for-each-parallel** - [Git](https://github.com/yisraelx/promises/blob/master/modules/for-each-parallel) - [Npm](https://https://npmjs.com/package/@promises/for-each-parallel)
- **@promises/for-each-right-series** - [Git](https://github.com/yisraelx/promises/blob/master/modules/for-each-right-series) - [Npm](https://https://npmjs.com/package/@promises/for-each-right-series)
- **@promises/for-each-series** - [Git](https://github.com/yisraelx/promises/blob/master/modules/for-each-series) - [Npm](https://https://npmjs.com/package/@promises/for-each-series)
- **@promises/from-observable** - [Git](https://github.com/yisraelx/promises/blob/master/modules/from-observable) - [Npm](https://https://npmjs.com/package/@promises/from-observable)
- **@promises/interfaces** - [Git](https://github.com/yisraelx/promises/blob/master/modules/interfaces) - [Npm](https://https://npmjs.com/package/@promises/interfaces)
- **@promises/is-promise** - [Git](https://github.com/yisraelx/promises/blob/master/modules/is-promise) - [Npm](https://https://npmjs.com/package/@promises/is-promise)
- **@promises/keys** - [Git](https://github.com/yisraelx/promises/blob/master/modules/keys) - [Npm](https://https://npmjs.com/package/@promises/keys)
- **@promises/map-parallel** - [Git](https://github.com/yisraelx/promises/blob/master/modules/map-parallel) - [Npm](https://https://npmjs.com/package/@promises/map-parallel)
- **@promises/map-series** - [Git](https://github.com/yisraelx/promises/blob/master/modules/map-series) - [Npm](https://https://npmjs.com/package/@promises/map-series)
- **@promises/parallel** - [Git](https://github.com/yisraelx/promises/blob/master/modules/parallel) - [Npm](https://https://npmjs.com/package/@promises/parallel)
- **@promises/promisify** - [Git](https://github.com/yisraelx/promises/blob/master/modules/promisify) - [Npm](https://https://npmjs.com/package/@promises/promisify)
- **@promises/reduce-right-series** - [Git](https://github.com/yisraelx/promises/blob/master/modules/reduce-right-series) - [Npm](https://https://npmjs.com/package/@promises/reduce-right-series)
- **@promises/reduce-series** - [Git](https://github.com/yisraelx/promises/blob/master/modules/reduce-series) - [Npm](https://https://npmjs.com/package/@promises/reduce-series)
- **@promises/reject-parallel** - [Git](https://github.com/yisraelx/promises/blob/master/modules/reject-parallel) - [Npm](https://https://npmjs.com/package/@promises/reject-parallel)
- **@promises/reject-series** - [Git](https://github.com/yisraelx/promises/blob/master/modules/reject-series) - [Npm](https://https://npmjs.com/package/@promises/reject-series)
- **@promises/reset** - [Git](https://github.com/yisraelx/promises/blob/master/modules/reset) - [Npm](https://https://npmjs.com/package/@promises/reset)
- **@promises/retry** - [Git](https://github.com/yisraelx/promises/blob/master/modules/retry) - [Npm](https://https://npmjs.com/package/@promises/retry)
- **@promises/series** - [Git](https://github.com/yisraelx/promises/blob/master/modules/series) - [Npm](https://https://npmjs.com/package/@promises/series)
- **@promises/some-parallel** - [Git](https://github.com/yisraelx/promises/blob/master/modules/some-parallel) - [Npm](https://https://npmjs.com/package/@promises/some-parallel)
- **@promises/some-series** - [Git](https://github.com/yisraelx/promises/blob/master/modules/some-series) - [Npm](https://https://npmjs.com/package/@promises/some-series)
- **@promises/spread** - [Git](https://github.com/yisraelx/promises/blob/master/modules/spread) - [Npm](https://https://npmjs.com/package/@promises/spread)
- **@promises/timeout** - [Git](https://github.com/yisraelx/promises/blob/master/modules/timeout) - [Npm](https://https://npmjs.com/package/@promises/timeout)
- **@promises/timer** - [Git](https://github.com/yisraelx/promises/blob/master/modules/timer) - [Npm](https://https://npmjs.com/package/@promises/timer)
- **@promises/times-parallel** - [Git](https://github.com/yisraelx/promises/blob/master/modules/times-parallel) - [Npm](https://https://npmjs.com/package/@promises/times-parallel)
- **@promises/times-series** - [Git](https://github.com/yisraelx/promises/blob/master/modules/times-series) - [Npm](https://https://npmjs.com/package/@promises/times-series)
- **@promises/to-callback** - [Git](https://github.com/yisraelx/promises/blob/master/modules/to-callback) - [Npm](https://https://npmjs.com/package/@promises/to-callback)
- **@promises/to-observable** - [Git](https://github.com/yisraelx/promises/blob/master/modules/to-observable) - [Npm](https://https://npmjs.com/package/@promises/to-observable)
- **@promises/wrap** - [Git](https://github.com/yisraelx/promises/blob/master/modules/wrap) - [Npm](https://https://npmjs.com/package/@promises/wrap)
164 changes: 164 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
# Promises utility modules
[![Travis build](https://travis-ci.org/yisraelx/promises.svg?branch=master)](https://travis-ci.org/yisraelx/promises)
[![Codecov](https://codecov.io/gh/yisraelx/promises/branch/master/graph/badge.svg)](https://codecov.io/gh/yisraelx/promises)
[![MIT License](https://img.shields.io/npm/l/promises.svg)](https://github.com/yisraelx/promises/blob/master/LICENSE)
[![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg)](http://commitizen.github.io/cz-cli/)

## Compatibility
These modules are written in typescript and available in ES5 and ES6 standard, the requirements are a global __Promise__ (native or polyfill).
- main - umd format and es5 standard (umd.js, umd.min.js)
- module - commonjs module and es5 standard (es5.js)
- es2015 - commonjs module and es6 standard (index.js)
- browser - umd format and es5 standard (umd.js, umd.min.js)
- bundle - bundle in umd format includes all scope dependencies in es5 standard (bundle.js, bundle.min.js)
- typings - typescript declaration file (index.d.ts)

## Packages structure
##### The code is divided into many small modules and each module is a package in itself ([Packages List](https://github.com/yisraelx/promises/blob/master/PACKAGES.md)).
##### Each package in the scoop has only one function or class and it in the default export of the package.
##### Group package brings together several modules from the scope, and in the export has access to all modules.

#### Marks
* "**-**": __@{scope}/-{name}__ - Group package
* "**_**": **@{scope}/_{name}** - Internal package

#### Import
import __forEachSeries__ _default_ function from '@promises/for-each-series' package, which is package from scoop __@promises__ that contains only one function
```typescript
import forEachSeries from '@promises/for-each-series';
```
import __forEachSeries__ function from '@promises/-all' package, which is group package that contains all functions from scoop __@promises__
```typescript
import { forEachSeries } from '@promises/-all';
```
import __Promises__ class from '~promises/-all' package, which is group package that contains all functions from scoop __@promises__, This will add to the Promises.* and Promises.prototype.* all the functions of the packages in the scope __@promises__
```typescript
import { Promises } from '@promises/-all';
```
Or
```typescript
import '@promises/-all';
import Promises from '@promises/core';
```
Or import some groups of modules from scope __@promises__, This will add the functions of the modules to Promises.* and Promises.prototype.*
```typescript
import '~promises.rxjs';
import '~promises.parallel';
import Promises from '@promises/core';
```

## Install
__Installation of all packages in scoop @promises__
```sh
$ npm install --save @promises/-all
```
__Installation of a single package from scoop @promises__
```sh
$ npm install --save @promises/for-each-series
```

## Use
#### static
```typescript
import mapSeries from '@promises/map-series';
let array: number[] = [1, 2, 3];
let map: Promises<number[]> = mapSeries(array, (value: number, index: number, array: number[]) => {
return value * index;
});
map.then((result: number[]) => {
console.log(result) // => [0, 2, 6]
});
```
#### wrapper
```typescript
import { Promises } from '@promises/-all';
let array: number[] = [1, 2, 3];
let promises: Promises<number[]> = Promises.resolve(array);
let filter: Promises<number[]> = promises.filterParallel((value: number) => value % 2 !== 0);
let map: Promises<number[]> = filter.mapParallel((value: number, index: number) => value + index);
let delay: Promises<number[]> = map.delay(1000);
delay.then((result: number[]) => {
console.log(result) // => [1, 4]
});
```

## Behavior
```typescript
import timeout from '@promises/timeout';

function run(forEach: Function) {
let array: number[] = [3, 7, 1, 5];

console.log('before');
forEach(array, execute(value: number) => {
console.log(`start: ${value}`);
return timeout((resolve) => {
console.log(`end: ${value}`);
resolve();
}, value);
}).then(() => {
console.log('complete');
});
console.log('after');
}
```
#### Parallel
```typescript
import forEachParallel from '@promises/for-each-parallel';

run(forEachParallel);

// => before
// => after
// => start 3
// => start 7
// => start 1
// => start 5
// => end 1
// => end 3
// => end 5
// => end 7
// => complete
```
#### Series
```typescript
import forEachSeries from '@promises/for-each-series';

run(forEachSeries);

// => before
// => after
// => start 3
// => end 3
// => start 7
// => end 7
// => start 1
// => end 1
// => start 5
// => end 5
// => complete
```
#### Wrap
```typescript
import { forEach } from 'lodash';
import wrap from '@promises/wrap';

let forEachWrap = wrap(forEach);

run(forEachWrap);

// => before
// => after
// => start 3
// => start 7
// => start 1
// => start 5
// => complete
// => end 1
// => end 3
// => end 5
// => end 7
```
## License
Copyright © 2017 [Yisrael Eliav](https://github.com/yisraelx),
Licensed under the [MIT license](https://github.com/yisraelx/promises/blob/master/LICENSE).
91 changes: 91 additions & 0 deletions karma.conf.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
import { Config, ConfigOptions } from 'karma';
import { ITslintPreprocessorConfig } from 'karma-tslint/lib/tslint.preprocessor';
import { KarmaTypescriptConfig } from 'karma-typescript/src/api/configuration';

export = (config: Config) => {
config.set({

basePath: '.',

frameworks: ['jasmine', 'karma-typescript'],

files: [
'./node_modules/es6-promise/dist/es6-promise.auto.min.js',
'./node_modules/jasmine-promises/dist/jasmine-promises.js',
'./modules/**/*.ts',
'./test/**/*.ts'
],

preprocessors: {
'./+(modules|test)/**/*.ts': ['tslint', 'karma-typescript']
},

karmaTypescriptConfig: {
tsconfig: './test/tsconfig.json',
reports: {
'text-summary': null,
html: {
'directory': './coverage/html'
},
json: {
'directory': './coverage',
'subdirectory': '.',
'filename': 'coverage.json',
}
},

coverageOptions: {
threshold: {
global: {
statements: 85,
branches: 85,
functions: 85,
lines: 85
}
}
}
} as KarmaTypescriptConfig,

tslintPreprocessor: {
stopOnFailure: true
} as ITslintPreprocessorConfig,

reporters: [
'progress', 'karma-typescript'
],
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: false,
browsers: ['PhantomJS'],
customLaunchers: {
IE8: {
base: 'IE',
browserName: 'IE8',
'x-ua-compatible': 'IE=EmulateIE9'
},
IE9: {
base: 'IE',
browserName: 'IE9',
'x-ua-compatible': 'IE=EmulateIE9'
},
IE10: {
base: 'IE',
browserName: 'IE10',
'x-ua-compatible': 'IE=EmulateIE10'
}
},
singleRun: true,
plugins: [
'karma-chrome-launcher',
'karma-edge-launcher',
'karma-firefox-launcher',
'karma-ie-launcher',
'karma-jasmine',
'karma-phantomjs-launcher',
'karma-tslint',
'karma-typescript'
]

} as ConfigOptions);
};
7 changes: 7 additions & 0 deletions lerna.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"lerna": "2.0.0-rc.5",
"packages": [
"modules/**"
],
"version": "independent"
}
Loading

0 comments on commit 00d9fb7

Please sign in to comment.