Skip to content

Commit

Permalink
feat: updatea match
Browse files Browse the repository at this point in the history
  • Loading branch information
afeiship committed Jan 13, 2021
0 parents commit 4ebdb54
Show file tree
Hide file tree
Showing 17 changed files with 322 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
12 changes: 12 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
node_modules
bower_components
coverage
npm-debug.log
yarn.lock
package-lock.json
.DS_Store
.idea
.vscode

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

.editorconfig
.prettierrc
Gemfile
jest.config.js
LICENSE.txt
Rakefile
express.js
.vscode
.release-it.json


# vscode localhistory
.history
.release-it.json
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
36 changes: 36 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"trailingComma": "none",
"arrowParens": "always",
"printWidth": 100,
"bracketSpacing": true,
"jsxBracketSameLine": true,
"tabWidth": 2,
"semi": true,
"singleQuote": true,
"overrides": [
{
"files": "*.scss",
"options": {
"trailingComma": "none",
"tabWidth": 2,
"parser": "scss"
}
},
{
"files": "*.json",
"options": {
"trailingComma": "none",
"tabWidth": 2,
"parser": "json"
}
},
{
"files": "*.md",
"options": {
"trailingComma": "none",
"tabWidth": 2,
"parser": "json"
}
}
]
}
17 changes: 17 additions & 0 deletions .release-it.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"git": {
"requireCleanWorkingDir": false
},
"hooks": {
"after:init": [
"npm run test",
"t2k"
],
"after:bump": [
"npm run build"
]
},
"github": {
"release": true
}
}
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.
37 changes: 37 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# next-match
> Math groups with next.
[![version][version-image]][version-url]
[![license][license-image]][license-url]
[![size][size-image]][size-url]
[![download][download-image]][download-url]

## installation
```bash
npm install -S @jswork/next-match
```

## usage
```js
import '@jswork/next-match';

const str = '/api/v1/{id}/{uuid}/{a.b}';

nx.match(str, /{(.*?)}/g, 0); // [ '{id}', '{uuid}', '{a.b}' ]
nx.match(str, /{(.*?)}/g, 1); // ['id', 'uuid', 'a.b']
```

## license
Code released under [the MIT license](https://github.com/afeiship/next-match/blob/master/LICENSE.txt).

[version-image]: https://img.shields.io/npm/v/@jswork/next-match
[version-url]: https://npmjs.org/package/@jswork/next-match

[license-image]: https://img.shields.io/npm/l/@jswork/next-match
[license-url]: https://github.com/afeiship/next-match/blob/master/LICENSE.txt

[size-image]: https://img.shields.io/bundlephobia/minzip/@jswork/next-match
[size-url]: https://github.com/afeiship/next-match/blob/master/dist/next-match.min.js

[download-image]: https://img.shields.io/npm/dm/@jswork/next-match
[download-url]: https://www.npmjs.com/package/@jswork/next-match
11 changes: 11 additions & 0 deletions __tests__/index.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
(function () {
require('../src');

describe('api.basic test', () => {
test('nx.match should match default index 1', function () {
var str = '/api/v1/{id}/{uuid}/{a.b}';
expect(nx.match(str, /{(.*?)}/g, 0)).toEqual(['{id}', '{uuid}', '{a.b}']);
expect(nx.match(str, /{(.*?)}/g, 1)).toEqual(['id', 'uuid', 'a.b']);
});
});
})();
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');
});
})();
21 changes: 21 additions & 0 deletions build/scripts.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
(function() {
'use strict';

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

gulp.task('scripts', function() {
return gulp
.src('src/*.js')
.pipe($.jswork.pkgHeader())
.pipe(gulp.dest('dist'))
.pipe($.size({ title: '[ default size ]:' }))
.pipe($.uglify({ output: { comments: saveLicense } }))
.pipe($.rename({ extname: '.min.js' }))
.pipe(gulp.dest('dist'))
.pipe($.size({ title: '[ minimize size ]:' }));
});
})();
27 changes: 27 additions & 0 deletions dist/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*!
* name: @jswork/next-match
* description: Math groups with next.
* homepage: https://github.com/afeiship/next-match
* version: 1.0.0
* date: 2021-01-13 13:22:59
* license: MIT
*/

(function () {
var global = typeof window !== 'undefined' ? window : this || Function('return this')();
var nx = global.nx || require('@jswork/next');

nx.match = function (inString, inRegExp, inIndex) {
var index = typeof inIndex === 'undefined' ? 1 : inIndex; // default to the first capturing group
var matches = [];
var match;
while ((match = inRegExp.exec(inString))) {
matches.push(match[index]);
}
return matches;
};

if (typeof module !== 'undefined' && module.exports) {
module.exports = nx.match;
}
})();
9 changes: 9 additions & 0 deletions dist/index.min.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/*!
* name: @jswork/next-match
* description: Math groups with next.
* homepage: https://github.com/afeiship/next-match
* version: 1.0.0
* date: 2021-01-13 13:22:59
* license: MIT
*/
!function(){var e=("undefined"!=typeof window?window:this||Function("return this")()).nx||require("@jswork/next");e.match=function(e,n,o){for(var t,r=void 0===o?1:o,u=[];t=n.exec(e);)u.push(t[r]);return u},"undefined"!=typeof module&&module.exports&&(module.exports=e.match)}();
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": "@jswork/next-match",
"version": "1.0.0",
"description": "Math groups with next.",
"homepage": "https://github.com/afeiship/next-match",
"author": {
"name": "afei",
"email": "1290657123@qq.com"
},
"scripts": {
"build": "gulp",
"test": "jest",
"start": "node ./express.js",
"release": "release-it"
},
"main": "dist/index.js",
"license": "MIT",
"devDependencies": {
"@jswork/gulp-pkg-header": "^1.0.3",
"@jswork/next": "^1.0.3",
"del": "^6.0.0",
"gulp": "^4.0.2",
"gulp-debug": "^4.0.0",
"gulp-header": "^2.0.9",
"gulp-ignore": "^3.0.0",
"gulp-load-plugins": "^2.0.6",
"gulp-rename": "^2.0.0",
"gulp-size": "^3.0.0",
"gulp-uglify": "^3.0.2",
"jest": "^26.6.3",
"prettier": "^2.2.1",
"release-it": "^14.2.2",
"uglify-js": "3.12.1",
"uglify-save-license": "^0.4.1"
},
"publishConfig": {
"access": "public",
"registry": "https://registry.npmjs.org"
}
}
18 changes: 18 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
(function () {
var global = typeof window !== 'undefined' ? window : this || Function('return this')();
var nx = global.nx || require('@jswork/next');

nx.match = function (inString, inRegExp, inIndex) {
var index = typeof inIndex === 'undefined' ? 1 : inIndex; // default to the first capturing group
var matches = [];
var match;
while ((match = inRegExp.exec(inString))) {
matches.push(match[index]);
}
return matches;
};

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

0 comments on commit 4ebdb54

Please sign in to comment.