1 | **Protege is a versatile NodeJS extension library that aims to make code as simple as possible**
|
2 |
|
3 | ## Installation
|
4 |
|
5 | To install Protege, use [npm](http://github.com/isaacs/npm):
|
6 |
|
7 | $ npm install protege
|
8 |
|
9 | ## Usage
|
10 |
|
11 | ```require('protege')``` - it's that easy
|
12 |
|
13 | ### Global
|
14 | ```
|
15 | .delay(time, fn) - Coffeescript friendly alias for setTimeout
|
16 | ```
|
17 |
|
18 | ### Object
|
19 | ####These apply to all types, some are Object specific though
|
20 | ```
|
21 | .clone() - Duplicates the object into a new reference
|
22 | .clear() - Removes all keys and values from the objects
|
23 | .concat(source) - Adds all properties/values from source to object.
|
24 | (optional) overwrite = true will overwrite existing values with source values
|
25 | .merge(source, overwrite, deep) - Merge source properties/values into object.
|
26 | (optional) overwrite = true will overwrite existing values with source values
|
27 | (optional) deep = true will initiate a deep merge, merging descriptors and non-enumerable properties
|
28 |
|
29 | .extend(source) - Alias for merge
|
30 | .unique(merge) - Returns a unique copy of the object. (optional) merge will merge values for duplicate keys into arrays instead of removing them
|
31 |
|
32 | Object.isEmpty(object) - Returns true if object is empty
|
33 | Object.isObject(object) - Returns true if object is an object
|
34 | Object.isArray(object) - Returns true if object is an array
|
35 | Object.isElement(object) - Returns true if object is a DOM element
|
36 | Object.isBoolean(object) - Returns true if object is a boolean
|
37 | Object.isNumber(object) - Returns true if object is a number
|
38 | Object.isString(object) - Returns true if object is a string
|
39 | Object.isFunction(object) - Returns true if object is a function
|
40 | Object.isXML(object) - Returns true if object is an XML object
|
41 |
|
42 | .keys() - Returns all keys in the object
|
43 | .values() - Returns all values in the object
|
44 |
|
45 | .getKey() - Returns first key in object
|
46 | .getValue() - Returns first value in object
|
47 | .getKeys(value) - Returns all keys for the corresponding value
|
48 | .getValues(key) - Returns all values for the corresponding key
|
49 |
|
50 | .remove(key) - Removes key from object
|
51 |
|
52 | .stringify() - Returns JSON string for object
|
53 | .prettify() - Returns a human readable JSON string for object
|
54 | ```
|
55 |
|
56 | ### Array
|
57 | ####These also apply to String (since String is just an array after all) but some are only really useful for true arrays
|
58 | ```
|
59 | .clone() - Duplicates the array into a new reference.
|
60 |
|
61 | .merge(arr) - Adds array arr to array
|
62 | .unique() - Returns a copy of the array with duplicates removed
|
63 | .flatten() - Returns a one-dimensional copy of the array
|
64 | .compact() - Returns a copy of the array with all undefined and null items removed
|
65 | .intersect(arr) - Returns an array of all items in both arr and the array
|
66 |
|
67 | .size() - Returns size of array
|
68 | .first() - Returns first value or array or undefined
|
69 | .last() - Returns last value or array or undefined
|
70 |
|
71 | .replace(value, newval) - Replaces first instance of value with newval
|
72 | .replaceIndex(index, value) - Replaces item at index with value
|
73 | .replaceAll(value, newval) - Replaces all instances of value with newval
|
74 | .remove(value) - Removes first instance of value from array
|
75 | .removeAll(value) - Removes all instances of value from array.
|
76 | .removeAllIgnoreCase(value) - Removes all instances of value from array ignoring case
|
77 | .removeIndex(idx) - Removes index of idx from array
|
78 | ```
|
79 |
|
80 | ### String
|
81 | ```
|
82 | .upcase() - Alias for toUpperCase(), inspired by Ruby syntax
|
83 | .downcase() - Alias for toLowerCase(), inspired by Ruby syntax
|
84 |
|
85 | .strip() - Alias for trim(), inspired by Ruby syntax
|
86 | .rstrip() - Alias for trimRight(), inspired by Ruby syntax
|
87 | .lstrip() - Alias for trimLeft(), inspired by Ruby syntax
|
88 |
|
89 | .replaceAll(value, newval) - Replaces all instances of value with newval
|
90 |
|
91 | .startsWith(value) - Returns true if string starts with value, inspired by Java syntax
|
92 | .endsWith(value) - Returns true if string ends with value, inspired by Java syntax
|
93 | .startsWithIgnoreCase(value) - Returns true if string starts with value ignoring case, inspired by Java syntax
|
94 | .endsWithIgnoreCase(value) - Returns true if string ends with value ignoring case, inspired by Java syntax
|
95 |
|
96 | .contains(value) - Returns true if the string contains value, inspired by Java syntax
|
97 | .containsIgnoreCase(value) - Returns true if the string contains value ignoring case, inspired by Java syntax
|
98 | .equalsIgnoreCase(value) - Returns true if the string equals value ignoring case, inspired by Java syntax
|
99 | ```
|
100 |
|
101 | ### Function
|
102 | ```
|
103 | .memoize() - Caches result for parameters so any future calls will skip execution and return previous result
|
104 | Example: var cacheFunc = myFunc.memoize(); cacheFunc(15); cacheFunc(13); cacheFunc(15);
|
105 | Only the first two calls will actually be executed.
|
106 | ```
|
107 | ## Examples
|
108 |
|
109 | You can view further examples in the [example folder.](https://github.com/wearefractal/protege/tree/master/examples)
|
110 |
|
111 | ## LICENSE
|
112 |
|
113 | (MIT License)
|
114 |
|
115 | Copyright (c) 2011 Fractal <contact@wearefractal.com>
|
116 |
|
117 | Permission is hereby granted, free of charge, to any person obtaining
|
118 | a copy of this software and associated documentation files (the
|
119 | "Software"), to deal in the Software without restriction, including
|
120 | without limitation the rights to use, copy, modify, merge, publish,
|
121 | distribute, sublicense, and/or sell copies of the Software, and to
|
122 | permit persons to whom the Software is furnished to do so, subject to
|
123 | the following conditions:
|
124 |
|
125 | The above copyright notice and this permission notice shall be
|
126 | included in all copies or substantial portions of the Software.
|
127 |
|
128 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
129 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
130 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
131 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
132 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
133 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
134 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
135 |
|
136 |
|
\ | No newline at end of file |