Skip to content

Commit

Permalink
0.2.1
Browse files Browse the repository at this point in the history
  • Loading branch information
yanhaijing committed Oct 1, 2023
1 parent 7a94ee8 commit 7ada346
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 21 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# CHANGE LOG

## 0.2.1 / 2023-10-1

- 去掉`@babel/plugin-transform-runtime`,优化生成的代码

## 0.2.0 / 2023-9-23

- paths 支持 type 类型
Expand Down
2 changes: 1 addition & 1 deletion README-zh_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
[![](https://img.shields.io/badge/Powered%20by-jslib%20base-brightgreen.svg)](https://github.com/yanhaijing/jslib-base)
[![license](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/jsmini/anypath/blob/master/LICENSE)
[![CI](https://github.com/jsmini/anypath/actions/workflows/ci.yml/badge.svg?branch=master)](https://github.com/jsmini/anypath/actions/workflows/ci.yml)
[![npm](https://img.shields.io/badge/npm-0.2.0-orange.svg)](https://www.npmjs.com/package/@jsmini/anypath)
[![npm](https://img.shields.io/badge/npm-0.2.1-orange.svg)](https://www.npmjs.com/package/@jsmini/anypath)
[![NPM downloads](http://img.shields.io/npm/dm/@jsmini/anypath.svg?style=flat-square)](http://www.npmtrends.com/@jsmini/anypath)
[![Percentage of issues still open](http://isitmaintained.com/badge/open/jsmini/anypath.svg)](http://isitmaintained.com/project/jsmini/anypath 'Percentage of issues still open')

Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
[![](https://img.shields.io/badge/Powered%20by-jslib%20base-brightgreen.svg)](https://github.com/yanhaijing/jslib-base)
[![license](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/jsmini/anypath/blob/master/LICENSE)
[![CI](https://github.com/jsmini/anypath/actions/workflows/ci.yml/badge.svg?branch=master)](https://github.com/jsmini/anypath/actions/workflows/ci.yml)
[![npm](https://img.shields.io/badge/npm-0.2.0-orange.svg)](https://www.npmjs.com/package/@jsmini/anypath)
[![npm](https://img.shields.io/badge/npm-0.2.1-orange.svg)](https://www.npmjs.com/package/@jsmini/anypath)
[![NPM downloads](http://img.shields.io/npm/dm/@jsmini/anypath.svg?style=flat-square)](http://www.npmtrends.com/@jsmini/anypath)
[![Percentage of issues still open](http://isitmaintained.com/badge/open/jsmini/anypath.svg)](http://isitmaintained.com/project/jsmini/anypath 'Percentage of issues still open')

Expand Down Expand Up @@ -110,7 +110,7 @@ $ npm install
builds your code for production to `build` folder
```bash
$ npm run build
$ npm run build
```
run unit test. notice: borwser enviroment need to test manually. test file is in `test/browser`
Expand Down
20 changes: 10 additions & 10 deletions config/rollup.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,17 @@ function getCompiler(opt) {
],
],
plugins: [
[
'@babel/plugin-transform-runtime',
{
corejs: 3,
versions: '^7.22.15',
helpers: true,
regenerator: false,
},
],
// [
// '@babel/plugin-transform-runtime',
// {
// corejs: 3,
// versions: '^7.22.15',
// helpers: true,
// regenerator: false,
// },
// ],
],
babelHelpers: 'runtime',
babelHelpers: 'bundled',
exclude: 'node_modules/**',
}),
];
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@jsmini/anypath",
"version": "0.2.0",
"version": "0.2.1",
"description": "The best deep value assignment library, supporting Object, Array, and Map.",
"sideEffects": false,
"main": "dist/index.js",
Expand Down
16 changes: 9 additions & 7 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ export function getAnypath(obj: any, paths: AnyPath[]) {
return undefined;
}
let parent = obj;
for (const path of paths) {
for (let i = 0; i < paths.length; i++) {
const path = paths[i];
const t = type(parent);
if (t === 'object' || t === 'array') {
parent = parent[path.key];
Expand Down Expand Up @@ -59,7 +60,8 @@ export function setAnypath(obj: any, paths: AnyPath[], value: any): boolean {
let parent = obj;
// 获取容器元素

for (const path of paths.slice(0, -1)) {
for (let i = 0; i < paths.length - 1; i++) {
const path = paths[i];
const t = type(parent);
if (t === 'object' || t === 'array') {
// undefined | null
Expand Down Expand Up @@ -104,18 +106,18 @@ function parseKeys(keys: string): AnyPath[] {
const paths = String(keys)
.split('.')
.map((item) => {
if (item.includes('[]')) {
if (item.indexOf('[]') !== -1) {
// [] 语法
return {
key: item.replace('[]', ''),
type: 'array',
};
} else if (item.includes(':')) {
} else if (item.indexOf(':') !== -1) {
// : 语法
const [k, v] = item.split(':');
const arr = item.split(':');
return {
key: k,
type: v,
key: arr[0],
type: arr[1],
};
} else {
// object
Expand Down

0 comments on commit 7ada346

Please sign in to comment.