Skip to content

Commit

Permalink
feat: initial
Browse files Browse the repository at this point in the history
  • Loading branch information
afeiship committed Jun 6, 2020
0 parents commit e10e2ea
Show file tree
Hide file tree
Showing 19 changed files with 374 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
14 changes: 14 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
node_modules
bower_components
coverage
npm-debug.log
yarn.lock
Gemfile.lock
yarn-error.log
package-lock.json
.DS_Store
.idea
.vscode

# vscode localhistory
.history
20 changes: 20 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
.idea
.DS_Store
**/npm-debug.log
**/node_modules
test
__tests__
src
build
gulpfile.js

.editorconfig
.prettierrc
Gemfile
jest.config.js
LICENSE.txt
Rakefile
.vscode

# vscode localhistory
.history
2 changes: 2 additions & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
sass_binary_site=https://npm.taobao.org/mirrors/node-sass/
package-lock=false
40 changes: 40 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"trailingComma": "none",
"arrowParens": "always",
"printWidth": 100,
"bracketSpacing": true,
"jsxBracketSameLine": true,
"tabWidth": 2,
"semi": true,
"singleQuote": true,
"overrides": [
{
"files": ["*.json", ".eslintrc", ".tslintrc", ".prettierrc", ".tern-project"],
"options": {
"parser": "json",
"tabWidth": 2
}
},
{
"files": "*.{css,sass,scss,less}",
"options": {
"parser": "postcss",
"tabWidth": 2
}
},
{
"files": "*.ts",
"options": {
"parser": "typescript"
}
},
{
"files": "*.md",
"options": {
"trailingComma": "none",
"tabWidth": 2,
"parser": "json"
}
}
]
}
5 changes: 5 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
source 'https://rubygems.org'

gem 'fileutils'
gem 'sshkit'
gem 'semver'
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.
29 changes: 29 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# next-object-operator
> Object set/get/sets/gets and other operator.
## installation
```bash
npm install -S @feizheng/next-object-operator
```

## apis
| api | params | description |
| ---- | ------------ | --------------------- |
| get | (path) | Get value by path. |
| set | (path,value) | Set value by parh. |
| gets | - | Get the whole object. |
| sets | (object) | Sets multiple values. |

## usage
```js
import NxObjectOperator from '@feizheng/next-object-operator';

const data = {};
const operator = new NxObjectOperator(data);

// operators
operator.set
operator.get
operator.sets
operator.gets
```
4 changes: 4 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

Dir["./node_modules/@feizheng/rake-*/index.rake"].each do |task|
load task
end
40 changes: 40 additions & 0 deletions __tests__/index.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
(function () {
var nx = require('@feizheng/next-js-core2');
var NxObjectOperator = require('../src/next-object-operator');

describe('NxObjectOperator', function () {
test('set can change the value', function () {
var data = {};
var operator = new NxObjectOperator(data);
operator.set('name', 'afei');
expect(data).toEqual({ name: 'afei' })
});

test('get should get the right value', function () {
var data = {};
var operator = new NxObjectOperator(data);
operator.set('name', 'afei');
expect(operator.get('name')).toBe('afei');
});

test('sets can set multiple values', function () {
var data = {};
var operator = new NxObjectOperator(data);
operator.sets({ name: 'afei', age: 100 });
expect(data.name).toBe('afei');
expect(data.age).toBe(100);
});

test('gets should return the whole object', function () {
var data = {
name: 'afei',
age: 100
};
var operator = new NxObjectOperator(data);
expect(operator.gets()).toEqual({
name: 'afei',
age: 100
});
});
});
})();
13 changes: 13 additions & 0 deletions build/clean.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
(function() {
'use strict';

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

//clean
gulp.task('clean', function() {
return $.del('dist');
});
})();
24 changes: 24 additions & 0 deletions build/scripts.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
(function() {
'use strict';

const gulp = require('gulp');
const saveLicense = require('uglify-save-license');
const $ = require('gulp-load-plugins')({
pattern: ['gulp-*', 'gulp.*', 'del', '@feizheng/gulp-*']
});

gulp.task('scripts', function() {
return gulp
.src('src/*.js')
.pipe($.sourcemaps.init())
.pipe($.feizheng.pkgHeader())
.pipe($.sourcemaps.write('.'))
.pipe(gulp.dest('dist'))
.pipe($.size({ title: '[ default size ]:' }))
.pipe($.ignore('*.js.map'))
.pipe($.uglify({ output: { comments: saveLicense } }))
.pipe($.rename({ extname: '.min.js' }))
.pipe(gulp.dest('dist'))
.pipe($.size({ title: '[ minimize size ]:' }));
});
})();
45 changes: 45 additions & 0 deletions dist/next-object-operator.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions dist/next-object-operator.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions dist/next-object-operator.min.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/*!
* name: @feizheng/next-object-operator
* description: Object set/get/sets/gets and other operator.
* homepage: https://github.com/afeiship/next-object-operator
* version: 1.0.0
* date: 2020-06-06T03:14:14.905Z
* license: MIT
*/
!function(){var t=t||this||window||Function("return this")(),n=t.nx||require("@feizheng/next-js-core2"),e=n.declare("nx.ObjectOperator",{methods:{init:function(t){this.data=t},set:function(t,e){n.set(this.data,t,e)},sets:function(t){n.forIn(t,function(t,e){n.set(this.data,t,e)},this)},get:function(t){return n.get(this.data,t)},gets:function(){return this.data}}});"undefined"!=typeof module&&module.exports&&(module.exports=e)}();
13 changes: 13 additions & 0 deletions gulpfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
(function() {
'use strict';

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

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

gulp.task('default', gulp.series(['clean', 'scripts']));
})();
9 changes: 9 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// https://jestjs.io/docs/en/configuration
module.exports = {
verbose: true,
testRegex: [/\.spec.js/],
//preset: "jest-puppeteer",
moduleNameMapper: {
'^@/(.*)$': '<rootDir>/src/$1'
}
};
40 changes: 40 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"name": "@feizheng/next-object-operator",
"version": "1.0.0",
"description": "Object set/get/sets/gets and other operator.",
"homepage": "https://github.com/afeiship/next-object-operator",
"author": {
"name": "afei",
"email": "1290657123@qq.com"
},
"scripts": {
"build": "gulp",
"test": "jest"
},
"main": "dist/next-object-operator.js",
"license": "MIT",
"devDependencies": {
"@feizheng/gulp-pkg-header": "^1.0.4",
"@feizheng/rake-git": "^1.2.1",
"del": "^5.1.0",
"gulp": "^4.0.2",
"gulp-concat": "^2.6.1",
"gulp-debug": "^4.0.0",
"gulp-ignore": "^3.0.0",
"gulp-load-plugins": "^2.0.3",
"gulp-rename": "^2.0.0",
"gulp-size": "^3.0.0",
"gulp-sourcemaps": "^2.6.5",
"gulp-uglify": "^3.0.2",
"jest": "^26.0.1",
"uglify-js": "3.9.4",
"uglify-save-license": "^0.4.1",
"yargs": "^15.3.1"
},
"dependencies": {
"@feizheng/next-js-core2": "^2.5.0"
},
"publishConfig": {
"registry": "https://registry.npmjs.org/"
}
}
34 changes: 34 additions & 0 deletions src/next-object-operator.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
(function () {
var global = global || this || window || Function('return this')();
var nx = global.nx || require('@feizheng/next-js-core2');

var NxObjectOperator = nx.declare('nx.ObjectOperator', {
methods: {
init: function (inData) {
this.data = inData;
},
set: function (inPath, inValue) {
nx.set(this.data, inPath, inValue);
},
sets: function (inObject) {
nx.forIn(
inObject,
function (key, value) {
nx.set(this.data, key, value);
},
this
);
},
get: function (inPath) {
return nx.get(this.data, inPath);
},
gets: function () {
return this.data;
}
}
});

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

0 comments on commit e10e2ea

Please sign in to comment.