Skip to content

Commit

Permalink
issue: inital
Browse files Browse the repository at this point in the history
  • Loading branch information
afeiship committed Oct 4, 2017
0 parents commit 5788d81
Show file tree
Hide file tree
Showing 16 changed files with 260 additions and 0 deletions.
11 changes: 11 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
root = true

[*]
indent_style = space
indent_size = 2
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.md]
trim_trailing_whitespace = false
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
node_modules
bower_components
coverage
.idea
8 changes: 8 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.idea
.DS_Store
**/npm-debug.log
**/node_modules
test
src
build
gulpfile.js
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sass_binary_site=https://npm.taobao.org/mirrors/node-sass/
21 changes: 21 additions & 0 deletions LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2016 afei <1290657123@qq.com>

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.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# next-min-by
> This method is like .min except that it accepts iteratee which is invoked for each element in array to generate the criterion by which the value is ranked.

## resources:

## todos:
- [ ] unit test case
26 changes: 26 additions & 0 deletions bower.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"name": "next-min-by",
"description": "This method is like .min except that it accepts iteratee which is invoked for each element in array to generate the criterion by which the value is ranked.",
"main": "dist/next-min-by.js",
"authors": [
"afei"
],
"license": "MIT",
"keywords": [
"next"
],
"homepage": "https://github.com/afeiship/next-min-by",
"moduleType": [
"amd"
],
"ignore": [
"**/.*",
"node_modules",
"bower_components",
"test",
"tests",
"src",
"gulp",
"gulpfile.js"
]
}
15 changes: 15 additions & 0 deletions build/build.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
(function() {

'use strict';

const gulp = require('gulp');
const config = require('./config');

gulp.task('build', ['clean'], function() {
// console.log('Your task goes here!');
gulp.start(['scripts']);
});



}());
16 changes: 16 additions & 0 deletions build/clean.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
(function() {

'use strict';

const gulp = require('gulp');
const config = require('./config');
const $ = require('gulp-load-plugins')({
pattern: ['gulp-*', 'gulp.*', 'del']
});

//clean
gulp.task('clean', function() {
return $.del('dist');
});

}());
26 changes: 26 additions & 0 deletions build/config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
(function () {

'use strict';

const rootPath = process.cwd();
const gulp = require('gulp');


module.exports = {
path: {
root: rootPath,
src: rootPath + '/src',
dist: rootPath + '/dist',
gulp: rootPath + '/gulp'
},
sassOptions: {
normal: {
outputStyle: 'expanded' /* nested | expanded | compact | compressed */
},
minify: {
outputStyle: 'compressed'
}
}
};

}());
23 changes: 23 additions & 0 deletions build/scripts.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
(function() {

'use strict';

const gulp = require('gulp');
const config = require('./config');
const $ = require('gulp-load-plugins')({
pattern: ['gulp-*', 'gulp.*', 'del']
});

gulp.task('scripts', function () {
return gulp.src('src/*.js')
.pipe(gulp.dest('dist'))
.pipe($.size({title: '[ default size ]:'}))
.pipe($.uglify())
.pipe($.rename({
extname: '.min.js'
}))
.pipe(gulp.dest('dist'))
.pipe($.size({title: '[ minimize size ]:'}));
});

}());
22 changes: 22 additions & 0 deletions build/styles.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
(function () {

'use strict';

const gulp = require('gulp');
const config = require('./config');
const $ = require('gulp-load-plugins')({
pattern: ['gulp-*', 'gulp.*', 'del']
});

gulp.task('styles', function () {
return gulp.src('src/*.scss')
.pipe($.sass({outputStyle: 'expanded'}).on('error', $.sass.logError))
.pipe(gulp.dest('dist'))
.pipe($.sass({outputStyle: 'compressed'}).on('error', $.sass.logError))
.pipe($.rename({
extname: '.min.css'
}))
.pipe(gulp.dest('dist'));
});

}());
15 changes: 15 additions & 0 deletions gulpfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
(function() {

'use strict';

const gulp = require('gulp');
const fs = require('fs');

//import
fs.readdirSync('./build').map(function(file) {
require('./build/' + file);
});

gulp.task('default',['build']);

}());
30 changes: 30 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"name": "next-min-by",
"version": "0.0.0",
"description": "This method is like .min except that it accepts iteratee which is invoked for each element in array to generate the criterion by which the value is ranked.",
"homepage": "https://github.com/afeiship/next-min-by",
"author": {
"name": "afei",
"email": "1290657123@qq.com"
},
"scripts": {
"build": "gulp"
},
"main": "dist/next-min-by.js",
"license": "MIT",
"devDependencies": {
"del": "^2.2.1",
"gulp": "^3.9.1",
"gulp-concat": "^2.6.0",
"gulp-load-plugins": "^1.2.0",
"gulp-rename": "^1.2.2",
"gulp-sass": "^2.3.2",
"gulp-size": "^2.1.0",
"gulp-uglify": "^2.1.2",
"yargs": "^4.7.1",
"mocha": "^3.5.0"
},
"dependencies": {
"next-js-core2": "github:afeiship/next-js-core2"
}
}
18 changes: 18 additions & 0 deletions src/next-min-by.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
(function () {

var global = global || this || self || window;
var nx = global.nx || require('next-js-core2');

nx.minBy = function (inArray, inCallback) {
var items = nx.map(inArray, inCallback);
var minValue = Math.min.apply( null, items );
var minIndex = items.indexOf(minValue);
return inArray[ minIndex ];
};


if (typeof module !== 'undefined' && module.exports) {
module.exports = nx.minBy;
}

}());
16 changes: 16 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
var assert = require('assert');
var nx = require('next-js-core2');
require('../src/next-min-by');

describe('next/minBy', function () {

it('nx.minBy', function () {
var objects = [{ 'n': 1 }, { 'n': 2 }];
var min = nx.minBy(objects, function (_, o) {
return o.n;
});

assert.equal( min.n , 1);
});

});

0 comments on commit 5788d81

Please sign in to comment.