Code Monkey home page Code Monkey logo

urlon's Introduction

URL Object Notation

An Object Notation like JSON but for URLs. Read the full explanation on @vjeux blog: http://blog.vjeux.com/2011/javascript/urlon-url-object-notation.html

Note that format is slightly changed since article was published, but main idea remains the same.

Getting started

NPM

URLON is on NPM.

npm install urlon
var URLON = require('urlon');

UMD build using <script>

<script src="https://unpkg.com/urlon/dist/urlon.umd.js"></script>
<script>
  urlon // urlon.stringify() or urlon.parse()
</script>

Usage

stringify

URLON.stringify({"table":{"achievement":{"column":"instance","ascending":true}}})

// Output:      '$table$achievement$column=instance&ascending:true'

parse

URLON.parse('$table$achievement$column=instance&ascending:true')

// Output:  {"table":{"achievement":{"column":"instance","ascending":true}}}

Projects using URLON

  • url-mapper - @cerebral/router default mapper for URLs

Changelog

See releases

urlon's People

Contributors

guria avatar vjeux avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

urlon's Issues

URLON not working in IE (7&8)

as the title says, it throws an exception (unexpected character) which comes from the fact that IE does not support the array notation for accessing the nth char of a string.
I replaced all str[pos] instances with str.charAt(pos) and it worked like a charm.

an explanation was found here:

Array-like character access (the second way above) is not part of ECMAScript 3. It is a JavaScript and ECMAScript 5 feature.

https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/String

add license

@vjeux
I just found out that we have no License defined for this project.
I'd like to add one but I feel like it is good to consult with you as original author of the code.
My suggestion is to use https://choosealicense.com/licenses/unlicense/ which grants all permissions to a public domain.
Do you agree or do you have any other preference?

Is there any RFC about urlon?

Hi all.

I would like to know if there is any RFC about urlon. So... Is there any RFC about urlon? would it be possible to have an RFC from urlon?


I'm thinking of creating a urlon based implementation but with some technical differences or design.

urlon.stringify() not encoding '/' (slash)

While using this library to update url in my browser I faced an issue while converting it back to JSON.

For example:

urlon.stringify({ foo: 'ba/r' }); // OUTPUT: $foo=ba//r

But in URLs / is a valid character.

Temporarily, I'm using this to solve the problem.

encodeURIComponent(urlon.stringify({ foo: 'ba/r' })); // OUTPUT: %24foo%3Dba%2F%2Fr

It would be great if this issue can be fixed!

preserve type for undefined

undefined values now parse back as string, it potentially could break something:

var obj = { foo: undefined }
assert.deepEqual(parse(stringify(obj)), obj) // fail: { foo: 'undefined' } expected to be { foo: undefined }

I want to fix this as part of 3.0 release since it is could be breaking for someone.

Consider improving the notation syntax

Currently urlon uses _ to define objects.

URLON.parse('_table_achievement_column=instance&ascending:true')

// Output:  {"table":{"achievement":{"column":"instance","ascending":true}}} 

Underscores are not so uncommon in url params and could be either confusing at first or causing trouble with legacy urls. Maybe there is a way of improving this with an alternate notation pattern.

The first thing that popped into my head was:

URLON.parse('table.achievement.column=instance&ascending:true')
URLON.parse('table.achievement={column:instance,ascending:true')}

That's just phantasy though and hasn't been further evaluated in regards to technical limitations etc.

repo maintain plans

test runner doesn't work, since some resources is not available.
we need to rewrite tests using runner from npm.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.