Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
k-yle committed Sep 14, 2023
0 parents commit 990dbab
Show file tree
Hide file tree
Showing 14 changed files with 16,402 additions and 0 deletions.
47 changes: 47 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: Build and Test

on: [push]

jobs:
build:
runs-on: ubuntu-latest

strategy:
matrix:
node-version: [18.x, 20.x]

steps:
- name: ⏬ Checkout code
uses: actions/checkout@v4

- name: ⏬ Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}

- name: ⏬ Install
run: |
npm install
- name: ✨ Lint
run: |
npm run lint
- name: 🔨 Build
run: |
npm run build
- name: 🧪 Test
run: |
npm test
env:
FORCE_COLOR: 1

- name: 📦 Publish
if: ${{ github.ref == 'refs/heads/main' && matrix['node-version'] == '20.x' }}
run: |
npm config set //registry.npmjs.org/:_authToken=$NPM_AUTH_TOKEN
npm run trypublish
env:
CI: true
NPM_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }}
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
node_modules
yarn.lock
dist
coverage
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2022-2023 osm-conditional-restrictions Contributors

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.
54 changes: 54 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# OpenStreetMap conditional restriction parser

[![Build Status](https://github.com/k-yle/osm-conditional-restrictions/workflows/Build%20and%20Test/badge.svg)](https://github.com/k-yle/osm-conditional-restrictions/actions)
[![Coverage Status](https://coveralls.io/repos/github/k-yle/osm-conditional-restrictions/badge.svg?branch=main&t=LQmPNl)](https://coveralls.io/github/k-yle/osm-conditional-restrictions?branch=main)
[![npm version](https://badge.fury.io/js/osm-conditional-restrictions.svg)](https://badge.fury.io/js/osm-conditional-restrictions)
[![npm](https://img.shields.io/npm/dt/osm-conditional-restrictions.svg)](https://www.npmjs.com/package/osm-conditional-restrictions)
![npm bundle size](https://img.shields.io/bundlephobia/minzip/osm-conditional-restrictions)

📅🔒 Javascript/Typescript parser for OpenStreetMap [conditional restrictions](https://osm.wiki/Conditional_restrictions).

## Install

```sh
npm install osm-conditional-restrictions
```

## Usage

```js
import { parseConditionalRestrictions } from 'osm-conditional-restrictions';

const tags = {
access: 'no',
'access:conditional': 'yes @ (09:00-17:00 AND weight < 3.5)',
};
const output = parseConditionalRestrictions('access', tags);

// `output` will be an object that looks like this:
({
default: 'no',
exceptions: [
{
value: 'yes',
if: {
type: 'LogicalOperator',
operator: 'OR',
children: [
{ type: 'Condition', string: '09:00-17:00' },
{ type: 'Condition', string: 'weight < 3.5' },
],
},
},
],
});
```

## Scope

This library doesn't try to parse the conditional values, such as `09:00-17:00`.
To parse the [opening hours syntax](https://osm.wiki/Key:opening_hours), check out the [opening_hours](https://npm.im/opening_hours) library.

## Related Work

- [simonpoole/ConditionalRestrictionParser](https://github.com/simonpoole/ConditionalRestrictionParser) - An equivilant library written in Java
Loading

0 comments on commit 990dbab

Please sign in to comment.