Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
cyrilschumacher committed Oct 14, 2020
2 parents a2afd54 + 6c82a63 commit 7267fd0
Show file tree
Hide file tree
Showing 67 changed files with 3,748 additions and 7,270 deletions.
3 changes: 0 additions & 3 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,8 @@
.prettierrc
.nyc_output
coverage
example
node_modules
src
test
tsconfig.json
tsconfig.*.json
tslint.json
typings
15 changes: 5 additions & 10 deletions .nycrc
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,16 @@
"src/**/*.ts"
],
"exclude": [
"src/**/*.d.ts",
"src/cli/options.ts",
"node_modules",
"lib",
"test",
"typings"
"test"
],
"extension": [
".ts"
],
"require": [
"ts-node/register"
],
"reporter": [
"text-summary",
"html"
"html",
"lcov",
"text",
"text-summary"
]
}
19 changes: 7 additions & 12 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
language: node_js
node_js:
- "node"
- "8"
- "7"
- "6"
- "5"
cache:
yarn: true
directories:
- node_modules
- "lts/*"
cache: npm
install:
- yarn
- npm install
script:
- yarn build
- yarn test:coverage
- yarn coveralls
- npm test
after_script:
- npm run test:coverage
- npm run coveralls
85 changes: 53 additions & 32 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,80 +1,101 @@
# Change Log

All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]
## [2.0.0] - 2020-10-14

### Changed

- Update `export`: the class `JsonPropertyFilter` is replaced by a function `apply(object, string[])`;
- Update filtering mechanism;

## [1.3.1] - 2017-09-30

### Changed
- Update package.json description.

- Update `package.json` description;

### Fixed
- Fix line separator: convert `CRLF` to `LF`.

- Fix line separator: convert `CRLF` to `LF`;

## [1.3.0] - 2017-09-28

### Added
- Add `Date` and `Function` types support.
- Add examples.

- Add `Date` and `Function` types support;

### Changed
- Update: `README.md`.
- Update NPM dependencies.
- Improve unit/integration tests.
- Improve TypeScript documentation.

- Update NPM dependencies;
- Improve TypeScript documentation;

### Fixed
- Fix CLI version.
- Fix CLI.
- Fix Regular expression on including and excluding filters.

- Fix CLI version;
- Fix CLI;
- Fix Regular expression on including and excluding filters;

## [1.2.0] - 2016-06-20

### Added
- Add getters/setters for `JsonPropertyFilter` class to obtain/set the exclude/include filters.
- Add the posibility to define the symbols of include/exclude.
- Add CLI support.

- Add getters/setters for `JsonPropertyFilter` class to obtain/set the exclude/include filters;
- Add the possibility to define the symbols of include/exclude;
- Add CLI support;

### Changed
- All constructor arguments of the `JsonPropertyFilter` class are optionals.
- The `TypeError` object is used to assert separator and filters arguments.

- Update `JsonPropertyFilter` constructor to add optional arguments;
- Update validation on filter arguments;

## [1.1.1] - 2016-06-12

### Fixed
- A array contained in a base array can be ignored when filtering.

- Fix filter for embedded array;

## [1.1.0] - 2016-06-12

### Added
- Add arrays support.

- Add arrays support;

## [1.0.2] - 2016-05-29

### Fixed
- Fix TypeScript definition path.

- Fix TypeScript definition path;

## [1.0.1] - 2016-05-29

### Added
- Add TypeScript definition in "lib" directory.

- Add TypeScript definition in `lib` directory;

## [1.0.0] - 2016-05-29

### Added
- Add more validation on parameters.
- Add exclude filters.

- Add more validation on parameters;
- Add exclude filters;

### Changed
- Update the "include" behavior: if no properties, then the original object is returned.

- Update the "include" behavior: if no properties, then the original object is returned;

### Fixed
- The `apply` method of `JsonPropertyFilter` class can return a wrong filtered object if it contains an array of `string`/`number`/`boolean`.
- The symbol "" causes an undesirable side effect: all properties are added without distinction.

## [0.0.8] - 2016-05-28
### Changed
- Update the filter `**`: it can also be applied to a specific property.
- Fix filter if it contains an array of `string`/`number`/`boolean`;
- Fix filter with an empty symbol;

[Unreleased]: https://github.com/cyrilschumacher/json-property-filter/compare/1.3.1...HEAD
[1.3.0]: https://github.com/cyrilschumacher/json-property-filter/compare/1.3.0...1.3.1
[2.0.0]: https://github.com/cyrilschumacher/json-property-filter/compare/1.3.1...2.0.0
[1.3.1]: https://github.com/cyrilschumacher/json-property-filter/compare/1.3.0...1.3.1
[1.3.0]: https://github.com/cyrilschumacher/json-property-filter/compare/1.2.0...1.3.0
[1.2.0]: https://github.com/cyrilschumacher/json-property-filter/compare/1.1.1...1.2.0
[1.1.1]: https://github.com/cyrilschumacher/json-property-filter/compare/1.1.0...1.1.1
[1.1.0]: https://github.com/cyrilschumacher/json-property-filter/compare/1.0.2...1.1.0
[1.0.2]: https://github.com/cyrilschumacher/json-property-filter/compare/1.0.1...1.0.2
[1.0.1]: https://github.com/cyrilschumacher/json-property-filter/compare/1.0.0...1.0.1
[1.0.0]: https://github.com/cyrilschumacher/json-property-filter/compare/0.0.8...1.0.0
[0.0.8]: https://github.com/cyrilschumacher/json-property-filter/compare/0.0.6...0.0.8
2 changes: 0 additions & 2 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
The MIT License (MIT)

Copyright (c) 2017 Cyril Schumacher.fr

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
Expand Down
56 changes: 21 additions & 35 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,78 +1,64 @@
# json-property-filter

> Filter a JSON object by including/excluding given properties.
> JavaScript library and application to filter a JSON object by including and excluding properties.
[![MIT License][license-image]][license-url]
[![npm version][npmjs-image]][npmjs-url]
[![TypeScript][typescript-image]][typescript-url]
[![Build Status][travis-image]][travis-url]
[![Coverage Status][coveralls-image]][coveralls-url]
[![typescript-standard-style][standard-image]][standard-url]
[![david-dm dependency Status][david-image]][david-url]
[![david-dm devDependency Status][david-dev-dependencies-image]][david-dev-dependencies-url]
[![Known Vulnerabilities][snyk-image]][snyk-url]

**json-property-filter** is a JavaScript library for JSON data filtering by including or excluding properties. This library can be of interest if you need to provide JSON data and the caller wants to get specific properties (and thus avoid a relatively heavy response).
**json-property-filter** is a JavaScript library, developed in TypeScript, providing a function to include and/or exclude JSON properties. In addition to providing a function, an executable is available to filter a JSON file.

This library was developed with the programming language: [TypeScript](http://www.typescriptlang.org/) and is compatible Node 5+.
The library can also be from a Web page: the generated code is ES5 compatible.

## Getting Started

### Usage

To install to using [npm](https://www.npmjs.com/) package manager or [Yarn](https://yarnpkg.com/):
To install to using [npm](https://www.npmjs.com/) package manager:

```bash
$ npm install json-property-filter
$ yarn add json-property-filter
npm install json-property-filter
```

After installation, You can use the library this way:

```javascript
import { JsonPropertyFilter } from "json-property-filter";
```typescript
import * as jsonPropertyFilter from "json-property-filter";

const filter = new JsonPropertyFilter(["**"]);
filter.apply({ key: "value" });
const source = { key: "value" };
const filters = ["**"];
const result = jsonPropertyFilter.apply(source, filters);
```

If you want to have to have a quick overview of all features of this library, take a look at the [example](example), [integration tests](test/integration) or on [RunKit website](https://tonicdev.com/cyrilschumacher/json-property-filter).
If you want to have to have a quick overview of all features of this library, take a look at the [unit tests](test) or on [RunKit website](https://tonicdev.com/cyrilschumacher/json-property-filter).

### Command-Line

You have possibility to run in command-line this library without create a small JavaScript file. This executable provides all the options that are available at the code level. To see all the options, run the following line:
You have possibility to run in command-line this library without create a small TypeScript file. This executable provides all the options that are available at the code level. To see all the options, run the following line:

```bash
json-property-filter --help
```

### Filters
To filter a JSON file and produce a filtered JSON file containing only `message` and `timestamp` properties, the following options are used:

The following filters will allow you to include or exclude your object properties.

#### All properties

For include or exclude all the properties children and their children, you can use the symbol: `**`. Example: `**`, `root.**`, `root.node.**`.

#### Root properties

For include or exclude only properties located in the root, you can use the
symbol: `*`. Example: `root.*`, `root.node.*`.
```bash
json-property-filter --in "source.json" --out "destination.json" --filters "message" --filters "timestamp"
```

#### Specific property
To filter a JSON file and display the result formatted with 4 spaces in the console, the following options are used:

For include or include a specific property, you can set the path to your
property. Example: `root.element`, `root.node.element`.
```bash
json-property-filter --in "source.json" --filters "message" --filters "timestamp" --pretty --pretty-space 4
```

## License

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details

[david-dev-dependencies-image]: https://david-dm.org/cyrilschumacher/json-property-filter/dev-status.svg
[david-dev-dependencies-url]: https://david-dm.org/cyrilschumacher/json-property-filter#info=devDependencies

[david-image]: https://david-dm.org/cyrilschumacher/json-property-filter.svg
[david-url]: https://david-dm.org/cyrilschumacher/json-property-filter
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.

[license-image]: http://img.shields.io/badge/license-MIT-blue.svg?style=flat
[license-url]: LICENSE
Expand Down
14 changes: 0 additions & 14 deletions example/all/index.js

This file was deleted.

10 changes: 0 additions & 10 deletions example/all/source.json

This file was deleted.

14 changes: 0 additions & 14 deletions example/array/index.js

This file was deleted.

16 changes: 0 additions & 16 deletions example/array/source.json

This file was deleted.

14 changes: 0 additions & 14 deletions example/complex/index.js

This file was deleted.

13 changes: 0 additions & 13 deletions example/complex/source.json

This file was deleted.

Loading

0 comments on commit 7267fd0

Please sign in to comment.