All Projects → prayerslayer → Js.spec

prayerslayer / Js.spec

Licence: mit
clojure.spec for Javascript

Programming Languages

javascript
184084 projects - #8 most used programming language
clojure
4091 projects

Labels

Projects that are alternatives of or similar to Js.spec

Ghostwheel
Hassle-free inline clojure.spec with semi-automatic generative testing and side effect detection
Stars: ✭ 556 (+149.33%)
Mutual labels:  spec
Kitchen In Travis
Chef cookbook example to run test-kitchen inside Travis CI.
Stars: ✭ 36 (-83.86%)
Mutual labels:  spec
Unwalled.garden
Schemas for a p2p social-media network built on the Dat Web.
Stars: ✭ 126 (-43.5%)
Mutual labels:  spec
Spected
Validation library
Stars: ✭ 717 (+221.52%)
Mutual labels:  spec
Array Api
RFC document, tooling and other content related to the array API standard
Stars: ✭ 26 (-88.34%)
Mutual labels:  spec
Kahlan
✔️ PHP Test Framework for Freedom, Truth, and Justice
Stars: ✭ 1,065 (+377.58%)
Mutual labels:  spec
Openmicroservices.org
NOT MAINTAINED https://medium.com/@iopeak/open-microservices-specification-1abd8262ad0e
Stars: ✭ 383 (+71.75%)
Mutual labels:  spec
Hjson
Hjson, a user interface for JSON
Stars: ✭ 2,330 (+944.84%)
Mutual labels:  spec
Sketch Measure
Make it a fun to create spec for developers and teammates
Stars: ✭ 6,960 (+3021.08%)
Mutual labels:  spec
Pinpointer
Pinpointer is yet another clojure.spec error reporter based on a precise error analysis
Stars: ✭ 92 (-58.74%)
Mutual labels:  spec
Expound
Human-optimized error messages for clojure.spec
Stars: ✭ 806 (+261.43%)
Mutual labels:  spec
Spec
OStatus Specification
Stars: ✭ 18 (-91.93%)
Mutual labels:  spec
Pytest Spec
Library pytest-spec is a pytest plugin to display test execution output like a SPECIFICATION.
Stars: ✭ 65 (-70.85%)
Mutual labels:  spec
Orchestra
Complete instrumentation for clojure.spec
Stars: ✭ 573 (+156.95%)
Mutual labels:  spec
Dockerspec
A small Ruby Gem to run RSpec and Serverspec, Infrataster and Capybara tests against Dockerfiles or Docker images easily.
Stars: ✭ 181 (-18.83%)
Mutual labels:  spec
Matrix Doc
Matrix Documentation (including The Spec)
Stars: ✭ 536 (+140.36%)
Mutual labels:  spec
Spec Examples
Some examples on using clojure.spec!
Stars: ✭ 48 (-78.48%)
Mutual labels:  spec
Inspec
InSpec: Auditing and Testing Framework
Stars: ✭ 2,450 (+998.65%)
Mutual labels:  spec
Proposals
Tracking ECMAScript Proposals
Stars: ✭ 14,444 (+6377.13%)
Mutual labels:  spec
Friendly Public Transport Format
A format for APIs, libraries and datasets containing and working with public transport data.
Stars: ✭ 69 (-69.06%)
Mutual labels:  spec

js.spec

clojure.spec for Javascript

Latest build Coverage Status npm version

logo

There is clojure.spec, a part of Clojure's core library that is intended to help with specification, testing and error messages. I recommend you to read the linked rationale, you will get the gist even without knowledge of Clojure. In any case here's my best attempt of a summary:

In a dynamic language like Javascript or Clojure it is common to represent information with data. For instance, you could encode the score of a soccer match with a list of two integers [0, 1]. (In a statically typed language like Java the idiomatic way would be an instance of a SoccerScore class.) This data is passed around between modules of your code or sent to external systems, yet the knowledge about what this list of integers stands for is not available anywhere. Maybe you described it in the project's documentation, which is likely outdated. Most probably it is implicitly assumed in your code (var goals_scored = score[0] + score[1];). If the semantics change (e.g. list contains also teams), your code breaks.

One way to mitigate this is by static analysis tools (Flow) or typed languages (Typescript), but they only get you so far. For instance they don't work at runtime (duh!) and offer limited expressiveness. (They also need more tooling, but that's another story.) So what you're left with is manual parsing and checking, which is repetitive and half-assed at worst (if (!Array.isArray(score)) ...), and non-standard at best, ie. there is no way for users of your function to know where exactly their provided input failed your specification.

Another issue is that schemas get more popular in the Javascript community (JSON Schema, React.PropTypes...), yet there is no uniform way to define them. Error messages differ from system to system. You can't port your schemas, but need to define them multiple times in different syntax.

js.spec tries to solve those problems.

Usage

For a quick usage example see example.js. Otherwise please refer to the documentation.

Documentation

https://prayerslayer.gitbooks.io/js-spec/content/

Installation

npm install js.spec

This will install the current release candidate, as there is no 1.0 yet.

If you want to include it into a web page directly via script, please use the UMD build like this:

<script src="./js.spec.bundle.js" charset="utf-8"></script>
<script type="text/javascript">
  const {spec, valid} = window['js.spec']
  const foo = spec.map("foo", {
    name: spec.string
  })
  alert(valid(foo, {name: 'hugo'}))
</script>

Implementation Status

The 0.0.x published versions should be seen as developer previews. Code may or may not work. API may or may not witness breaking changes.

  • Specs
    • ✅ Primitives
    • ✅ Map
    • ✅ Collection
    • Combination
      • ✅ And
      • ✅ Or
    • ✅ Tuple
    • ✅ Nilable
    • ✅ Enum
  • ✅ Spec Registry Removed after discussion in #21
  • 🚧 Spec Regexes (cat, alt, *, ?, +)
  • 😰 Generator Functions
  • 😫 Function Specs (Not even sure if it's possible the way it works in clojure.spec)

Why not use Clojurescript?

If you already thought about using CLJS, go ahead. clojure.spec is already available there. However if you meant to pull in CLJS as a dependency: clojure.spec is macro-heavy. Macros exist only at compile-time, so all the "functions" (they are macros) are gone.

License

MIT, see LICENSE

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].